Skip to content

Commit

Permalink
test with a noproxy that doesn't include every private IP
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Sep 5, 2024
1 parent fd4ed73 commit 2fa69ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
26 changes: 20 additions & 6 deletions e2e/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Dir struct {
// names and the cluster id.
type Output struct {
Nodes []string
IPs []string
network string
id string
T *testing.T
Expand Down Expand Up @@ -216,7 +217,7 @@ func NewTestCluster(in *Input) *Output {
}
CreateProfile(in)
CreateNetworks(in)
out.Nodes = CreateNodes(in)
out.Nodes, out.IPs = CreateNodes(in)
for _, node := range out.Nodes {
CopyFilesToNode(in, node)
CopyDirsToNode(in, node)
Expand Down Expand Up @@ -573,18 +574,20 @@ func CopyFileFromNode(node, source, dest string) error {

// CreateNodes creats the nodes for the cluster. The amount of nodes is
// specified in the input.
func CreateNodes(in *Input) []string {
func CreateNodes(in *Input) ([]string, []string) {
nodes := []string{}
IPs := []string{}
for i := 0; i < in.Nodes; i++ {
node := CreateNode(in, i)
node, ip := CreateNode(in, i)
if !in.WithProxy {
NodeHasInternet(in, node)
} else {
NodeHasNoInternet(in, node)
}
nodes = append(nodes, node)
IPs = append(IPs, ip)
}
return nodes
return nodes, IPs
}

// NodeHasInternet checks if the node has internet access. It does this by
Expand Down Expand Up @@ -687,7 +690,7 @@ func NodeHasNoInternet(in *Input, node string) {
// CreateNode creates a single node. The i here is used to create a unique
// name for the node. Node is named as "node-<cluster id>-<i>". The node
// name is returned.
func CreateNode(in *Input, i int) string {
func CreateNode(in *Input, i int) (string, string) {
client, err := lxd.ConnectLXDUnix(lxdSocket, nil)
if err != nil {
in.T.Fatalf("Failed to connect to LXD: %v", err)
Expand Down Expand Up @@ -736,7 +739,18 @@ func CreateNode(in *Input, i int) string {
in.T.Fatalf("Failed to get node state %s: %v", name, err)
}
}
return name
ip := ""
for key, netState := range state.Network {
for _, addr := range netState.Addresses {
fmt.Printf("key: %s Family: %s IP: %s\n", key, addr.Family, addr.Address)
if addr.Family == "inet" {
ip = addr.Address
break
}
}
}

return name, ip
}

// CreateNetworks create two networks, one of type bridge and inside of it another one of
Expand Down
4 changes: 2 additions & 2 deletions e2e/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestProxiedEnvironment(t *testing.T) {
line := []string{"single-node-install.sh", "ui"}
line = append(line, "--http-proxy", cluster.HTTPProxy)
line = append(line, "--https-proxy", cluster.HTTPProxy)
line = append(line, "--no-proxy", cluster.NOProxy)
line = append(line, "--no-proxy", strings.Join(tc.IPs, ","))
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
t.Fatalf("fail to install embedded-cluster on node %s: %v", tc.Nodes[0], err)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestProxiedCustomCIDR(t *testing.T) {
line := []string{"single-node-install.sh", "ui"}
line = append(line, "--http-proxy", cluster.HTTPProxy)
line = append(line, "--https-proxy", cluster.HTTPProxy)
line = append(line, "--no-proxy", cluster.NOProxy)
line = append(line, "--no-proxy", strings.Join(tc.IPs, ","))
line = append(line, "--pod-cidr", "10.128.0.0/20")
line = append(line, "--service-cidr", "10.129.0.0/20")
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions e2e/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestSingleNodeDisasterRecoveryWithProxy(t *testing.T) {
line := []string{"single-node-install.sh", "ui"}
line = append(line, "--http-proxy", cluster.HTTPProxy)
line = append(line, "--https-proxy", cluster.HTTPProxy)
line = append(line, "--no-proxy", cluster.NOProxy)
line = append(line, "--no-proxy", strings.Join(tc.IPs, ","))
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
t.Fatalf("fail to install embedded-cluster on node %s: %v", tc.Nodes[0], err)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestSingleNodeDisasterRecoveryWithProxy(t *testing.T) {
line = append([]string{"restore-installation.exp"}, testArgs...)
line = append(line, "--http-proxy", cluster.HTTPProxy)
line = append(line, "--https-proxy", cluster.HTTPProxy)
line = append(line, "--no-proxy", cluster.NOProxy)
line = append(line, "--no-proxy", strings.Join(tc.IPs, ","))
if _, _, err := RunCommandOnNode(t, tc, 0, line, withProxyEnv()); err != nil {
t.Fatalf("fail to restore the installation: %v", err)
}
Expand Down

0 comments on commit 2fa69ea

Please sign in to comment.