Skip to content

Commit 71d02fa

Browse files
committed
Add VPC for project e2e test
1 parent e7b8259 commit 71d02fa

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

test/e2e/common.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,31 @@ func CheckNetworkExists(client *cloudstack.CloudStackClient, networkName string)
394394
}
395395

396396
func CheckVPCExists(client *cloudstack.CloudStackClient, vpcName string) (bool, error) {
397-
_, count, err := client.VPC.GetVPCByName(vpcName)
397+
return CheckVPCExistsInProject(client, vpcName, "")
398+
}
399+
400+
func CheckVPCExistsInProject(client *cloudstack.CloudStackClient, vpcName string, project string) (bool, error) {
401+
p := client.VPC.NewListVPCsParams()
402+
p.SetName(vpcName)
403+
404+
if project != "" {
405+
projectID, _, err := client.Project.GetProjectID(project)
406+
if err != nil {
407+
Fail("Failed to get project: " + err.Error())
408+
}
409+
p.SetProjectid(projectID)
410+
}
411+
412+
listResp, err := client.VPC.ListVPCs(p)
398413
if err != nil {
399414
if strings.Contains(err.Error(), "No match found for") {
400415
return false, nil
401416
}
402417
return false, err
403-
} else if count > 1 {
404-
return false, fmt.Errorf("Expected 0-1 VPC with name %s, but got %d.", vpcName, count)
418+
} else if listResp.Count > 1 {
419+
return false, fmt.Errorf("Expected 0-1 VPC with name %s, but got %d.", vpcName, listResp.Count)
405420
}
406-
return count == 1, nil
421+
return listResp.Count == 1, nil
407422
}
408423

409424
func CreateCloudStackClient(ctx context.Context, kubeConfigPath string) *cloudstack.CloudStackClient {

test/e2e/data/infrastructure-cloudstack/v1beta3/cluster-template-project/cloudstack-cluster.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ spec:
1212
name : ${CLOUDSTACK_ZONE_NAME}
1313
network:
1414
name: ${CLOUDSTACK_NETWORK_NAME}
15+
gateway: ${CLOUDSTACK_GATEWAY}
16+
netmask: ${CLOUDSTACK_NETMASK}
17+
vpc:
18+
name: ${CLOUDSTACK_VPC_NAME}
19+
cidr: ${CLOUDSTACK_VPC_CIDR}
1520
project: ${CLOUDSTACK_PROJECT_NAME}
1621
controlPlaneEndpoint:
1722
host: ""

test/e2e/project.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func ProjectSpec(ctx context.Context, inputGetter func() CommonSpecInput) {
4141
cancelWatches context.CancelFunc
4242
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
4343
affinityIds []string
44+
vpcName = "vpc-for-e2e-1"
4445
)
4546

4647
BeforeEach(func() {
@@ -81,8 +82,8 @@ func ProjectSpec(ctx context.Context, inputGetter func() CommonSpecInput) {
8182
Namespace: namespace.Name,
8283
ClusterName: fmt.Sprintf("%s-%s", specName, util.RandomString(6)),
8384
KubernetesVersion: input.E2EConfig.GetVariable(KubernetesVersion),
84-
ControlPlaneMachineCount: pointer.Int64Ptr(1),
85-
WorkerMachineCount: pointer.Int64Ptr(1),
85+
ControlPlaneMachineCount: pointer.Int64(1),
86+
WorkerMachineCount: pointer.Int64(2),
8687
},
8788
WaitForClusterIntervals: input.E2EConfig.GetIntervals(specName, "wait-cluster"),
8889
WaitForControlPlaneIntervals: input.E2EConfig.GetIntervals(specName, "wait-control-plane"),
@@ -91,6 +92,9 @@ func ProjectSpec(ctx context.Context, inputGetter func() CommonSpecInput) {
9192

9293
csClient := CreateCloudStackClient(ctx, input.BootstrapClusterProxy.GetKubeconfigPath())
9394
affinityIds = CheckAffinityGroupInProject(csClient, clusterResources.Cluster.Name, "pro", projectName)
95+
exists, err := CheckVPCExistsInProject(csClient, vpcName, projectName)
96+
Expect(err).To(BeNil())
97+
Expect(exists).To(BeTrue())
9498
})
9599

96100
AfterEach(func() {

0 commit comments

Comments
 (0)