Skip to content

Commit b4c2013

Browse files
Fix network creation
1 parent fcc2c7d commit b4c2013

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

test/e2e/common.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -575,32 +575,36 @@ func IsClusterReady(ctx context.Context, mgmtClient client.Client, cluster *clus
575575
return c.Status.ControlPlaneReady && c.Status.InfrastructureReady
576576
}
577577

578-
func EnsureSecondaryNetworkExistsFromPrimary(client *cloudstack.CloudStackClient, input CommonSpecInput) (*cloudstack.Network, error) {
579-
primaryNetName := input.E2EConfig.GetVariable("CLOUDSTACK_NETWORK_NAME")
578+
func EnsureSecondaryNetworkExists(client *cloudstack.CloudStackClient, input CommonSpecInput) (*cloudstack.Network, error) {
580579
secondaryNetName := input.E2EConfig.GetVariable("CLOUDSTACK_NEW_NETWORK_NAME")
581580

582-
// Fetch primary network using helper
583-
primaryNet, _, err := client.Network.GetNetworkByName(primaryNetName)
584-
if err != nil {
585-
return nil, fmt.Errorf("failed to get primary network %q: %w", primaryNetName, err)
586-
}
587-
581+
By("Fetching secondary network details")
588582
// Try fetching secondary network
589583
secondaryNet, _, err := client.Network.GetNetworkByName(secondaryNetName)
590584
if err == nil && secondaryNet != nil {
591585
By(fmt.Sprintf("Network %q already exists", secondaryNetName))
592586
return secondaryNet, nil
593587
}
594588

589+
By("Listing Zone")
590+
zoneName := input.E2EConfig.GetVariable("CLOUDSTACK_ZONE_NAME")
591+
pz := client.Zone.NewListZonesParams()
592+
pz.SetName(zoneName)
593+
listZonesResponse, err := client.Zone.ListZones(pz)
594+
Expect(err).To(BeNil(), "error listing zones")
595+
Expect(listZonesResponse.Count).To(Equal(1), "no zones, or more than one zone resolve to zone name %s", zoneName)
596+
zoneId := listZonesResponse.Zones[0].Id
597+
598+
By("Listing network offerings")
599+
networkOffering, _, err := client.NetworkOffering.GetNetworkOfferingByName(DefaultNetworkOffering)
600+
595601
// Create new network using zone and offering from primary
602+
By("Create secondary network")
596603
createParams := client.Network.NewCreateNetworkParams(
597-
primaryNet.Networkofferingid,
598-
primaryNet.Zoneid,
599604
secondaryNetName,
605+
networkOffering.Id,
606+
zoneId,
600607
)
601-
createParams.SetDisplaytext(secondaryNetName)
602-
createParams.SetAccount(primaryNet.Account)
603-
createParams.SetDomainid(primaryNet.Domainid)
604608

605609
newNetResp, err := client.Network.CreateNetwork(createParams)
606610
if err != nil {
@@ -612,7 +616,8 @@ func EnsureSecondaryNetworkExistsFromPrimary(client *cloudstack.CloudStackClient
612616
return nil, fmt.Errorf("failed to fetch created network %q by ID: %w", newNetResp.Id, err)
613617
}
614618

615-
By(fmt.Sprintf("Created secondary network %q in zone %q", secondaryNetName, primaryNet.Zonename))
619+
By("Created secondary network")
620+
By(fmt.Sprintf("Created secondary network %q", secondaryNetName))
616621
return newNet, nil
617622
}
618623

test/e2e/multiple_networks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func MultipleNetworksSpec(ctx context.Context, inputGetter func() CommonSpecInpu
8585

8686
// Get details from ACS and ensure secondary network exists
8787
csClient := CreateCloudStackClient(ctx, input.BootstrapClusterProxy.GetKubeconfigPath())
88-
EnsureSecondaryNetworkExistsFromPrimary(csClient, input)
88+
EnsureSecondaryNetworkExists(csClient, input)
8989

9090
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
9191
ClusterProxy: input.BootstrapClusterProxy,

0 commit comments

Comments
 (0)