-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
140150: roachprod: add ip address expander func r=srosenberg,herkolategan a=DarrylWong This change adds ip to the list of supported roachprod expander funcs. e.g. `{ip:1-3}` now expands to the private ip addresses of nodes 1 to 3. `:public` can be appended, e.g. `{ip:1-3:public}` to specify the public ip addresses. Additionally, this change also logs expanded commands for roachtests if they differ from the original command. This should ease debugging as we can know what command was actually run on the node. Release note: none Epic: none Fixes: none ---- Additional context is that this PR is motivated by my playing around with iptables on a roachprod cluster. Found running `roachprod ip` repeatedly and copy pasting tedious. Co-authored-by: DarrylWong <[email protected]>
- Loading branch information
Showing
9 changed files
with
369 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package install | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"github.com/cockroachdb/cockroach/pkg/roachprod/cloud" | ||
"github.com/cockroachdb/cockroach/pkg/roachprod/logger" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/datapathutils" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func newTestCluster(t *testing.T) *SyncedCluster { | ||
testClusterFile := datapathutils.TestDataPath(t, "test_cluster.txt") | ||
data, err := os.ReadFile(testClusterFile) | ||
if err != nil { | ||
t.Fatalf("could not read test cluster file: %s", err) | ||
} | ||
metadata := &cloud.Cluster{} | ||
if err := json.Unmarshal(data, metadata); err != nil { | ||
t.Fatalf("could not unmarshal test cluster file: %s", err) | ||
} | ||
c, err := NewSyncedCluster(metadata, "all", MakeClusterSettings()) | ||
if err != nil { | ||
t.Fatalf("could not create synced cluster: %s", err) | ||
} | ||
return c | ||
} | ||
|
||
func TestIPExpander(t *testing.T) { | ||
ctx := context.Background() | ||
l := &logger.Logger{} | ||
|
||
c := newTestCluster(t) | ||
e := &expander{ | ||
node: c.Nodes[0], | ||
} | ||
cfg := ExpanderConfig{} | ||
|
||
for _, tc := range []struct { | ||
name string | ||
command string | ||
expected string | ||
}{ | ||
{ | ||
name: "same node", | ||
command: "{ip:1}", | ||
expected: "10.142.1.1", | ||
}, | ||
{ | ||
name: "different node", | ||
command: "{ip:2}", | ||
expected: "10.142.1.2", | ||
}, | ||
{ | ||
name: "range of nodes", | ||
command: "{ip:1-3}", | ||
expected: "10.142.1.1 10.142.1.2 10.142.1.3", | ||
}, | ||
{ | ||
name: "non consecutive nodes", | ||
command: "{ip:2,4}", | ||
expected: "10.142.1.2 10.142.1.4", | ||
}, | ||
{ | ||
name: "public ip", | ||
command: "{ip:1-4:public}", | ||
expected: "35.196.120.1 35.227.25.2 34.75.95.3 34.139.54.4", | ||
}, | ||
{ | ||
name: "private ip", | ||
command: "{ip:1-4:private}", | ||
expected: "10.142.1.1 10.142.1.2 10.142.1.3 10.142.1.4", | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
res, err := e.expand(ctx, l, c, cfg, tc.command) | ||
require.NoError(t, err) | ||
require.Equal(t, tc.expected, res) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.