@@ -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
0 commit comments