Skip to content

Commit 2cc528b

Browse files
author
sivakami
committed
fix customer vnet and subnet create steps.
1 parent 1e96c7a commit 2cc528b

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

.pipelines/swiftv2-long-running/scripts/create_vnets.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ verify_subnet() {
4646

4747
# -------------------------------
4848
create_vnet_subets() {
49-
local vnet="$2";
50-
local vnet_cidr="$3"
51-
local node_subnet_cidr="$4";
52-
local extra_subnets="$5";
53-
local extra_cidrs="$6"
49+
local vnet="$1"
50+
local vnet_cidr="$2"
51+
local node_subnet_cidr="$3"
52+
local extra_subnets="$4"
53+
local extra_cidrs="$5"
5454

5555
echo "==> Creating VNet: $vnet with CIDR: $vnet_cidr"
5656
az network vnet create -g "$RG" -l "$LOCATION" --name "$vnet" --address-prefixes "$vnet_cidr" -o none

test/integration/swiftv2/helpers/az_helpers.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,41 @@ import (
66
"strings"
77
)
88

9-
func runAzCommand(cmd string, args ...string) string {
9+
func runAzCommand(cmd string, args ...string) (string, error) {
1010
out, err := exec.Command(cmd, args...).CombinedOutput()
1111
if err != nil {
12-
panic(fmt.Sprintf("Failed to run %s %v: %s", cmd, args, string(out)))
12+
return "", fmt.Errorf("failed to run %s %v: %w\nOutput: %s", cmd, args, err, string(out))
1313
}
14-
return strings.TrimSpace(string(out))
14+
return strings.TrimSpace(string(out)), nil
1515
}
1616

17-
func GetVnetGUID(rg, vnet string) string {
17+
func GetVnetGUID(rg, vnet string) (string, error) {
1818
return runAzCommand("az", "network", "vnet", "show", "--resource-group", rg, "--name", vnet, "--query", "resourceGuid", "-o", "tsv")
1919
}
2020

21-
func GetSubnetARMID(rg, vnet, subnet string) string {
21+
func GetSubnetARMID(rg, vnet, subnet string) (string, error) {
2222
return runAzCommand("az", "network", "vnet", "subnet", "show", "--resource-group", rg, "--vnet-name", vnet, "--name", subnet, "--query", "id", "-o", "tsv")
2323
}
2424

25-
func GetSubnetGUID(rg, vnet, subnet string) string {
26-
subnetID := GetSubnetARMID(rg, vnet, subnet)
25+
func GetSubnetGUID(rg, vnet, subnet string) (string, error) {
26+
subnetID, err := GetSubnetARMID(rg, vnet, subnet)
27+
if err != nil {
28+
return "", err
29+
}
2730
return runAzCommand("az", "resource", "show", "--ids", subnetID, "--api-version", "2023-09-01", "--query", "properties.serviceAssociationLinks[0].properties.subnetId", "-o", "tsv")
2831
}
2932

30-
func GetSubnetToken(rg, vnet, subnet string) string {
33+
func GetSubnetToken(rg, vnet, subnet string) (string, error) {
3134
// Optionally implement if you use subnet token override
32-
return ""
35+
return "", nil
3336
}
3437

3538
// GetClusterNodes returns a slice of node names from a cluster using the given kubeconfig
36-
func GetClusterNodes(kubeconfig string) []string {
39+
func GetClusterNodes(kubeconfig string) ([]string, error) {
3740
cmd := exec.Command("kubectl", "--kubeconfig", kubeconfig, "get", "nodes", "-o", "name")
3841
out, err := cmd.CombinedOutput()
3942
if err != nil {
40-
panic(fmt.Sprintf("Failed to get nodes using kubeconfig %s: %s\n%s", kubeconfig, err, string(out)))
43+
return nil, fmt.Errorf("failed to get nodes using kubeconfig %s: %w\nOutput: %s", kubeconfig, err, string(out))
4144
}
4245

4346
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
@@ -49,7 +52,7 @@ func GetClusterNodes(kubeconfig string) []string {
4952
nodes = append(nodes, strings.TrimPrefix(line, "node/"))
5053
}
5154
}
52-
return nodes
55+
return nodes, nil
5356
}
5457

5558
// EnsureNamespaceExists checks if a namespace exists and creates it if it doesn't

test/integration/swiftv2/longRunningCluster/datapath_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ var _ = ginkgo.Describe("Datapath Tests", func() {
3838
subnetName := "s1"
3939

4040
// Get subnet information once (doesn't change between iterations)
41-
vnetGUID := helpers.GetVnetGUID(rg, vnetName)
42-
subnetGUID := helpers.GetSubnetGUID(rg, vnetName, subnetName)
43-
subnetARMID := helpers.GetSubnetARMID(rg, vnetName, subnetName)
44-
subnetToken := helpers.GetSubnetToken(rg, vnetName, subnetName)
41+
vnetGUID, err := helpers.GetVnetGUID(rg, vnetName)
42+
gomega.Expect(err).To(gomega.BeNil())
43+
subnetGUID, err := helpers.GetSubnetGUID(rg, vnetName, subnetName)
44+
gomega.Expect(err).To(gomega.BeNil())
45+
subnetARMID, err := helpers.GetSubnetARMID(rg, vnetName, subnetName)
46+
gomega.Expect(err).To(gomega.BeNil())
47+
subnetToken, err := helpers.GetSubnetToken(rg, vnetName, subnetName)
48+
gomega.Expect(err).To(gomega.BeNil())
4549

4650
// Run indefinitely until test is cancelled
4751
iteration := 0
@@ -77,7 +81,8 @@ var _ = ginkgo.Describe("Datapath Tests", func() {
7781

7882
// Step 3: Create pods on first two nodes
7983
ginkgo.By("Getting cluster nodes")
80-
nodes := helpers.GetClusterNodes(kubeconfig2)
84+
nodes, err := helpers.GetClusterNodes(kubeconfig2)
85+
gomega.Expect(err).To(gomega.BeNil())
8186
gomega.Expect(len(nodes)).To(gomega.BeNumerically(">=", 2), "Need at least 2 nodes")
8287

8388
podNames := []string{}

0 commit comments

Comments
 (0)