@@ -632,6 +632,194 @@ var _ = Describe("Octavia controller", func() {
632632 })
633633 })
634634
635+ When ("The management network is created with AZ support" , func () {
636+ var apiFixtures APIFixtures
637+
638+ BeforeEach (func () {
639+ apiFixtures = createAndSimulateKeystone (octaviaName )
640+
641+ createAndSimulateOctaviaSecrets (octaviaName )
642+ createAndSimulateTransportURL (transportURLName , transportURLSecretName )
643+
644+ createAndSimulateDB (spec )
645+
646+ createAndSimulateOctaviaAPI (octaviaName )
647+
648+ DeferCleanup (k8sClient .Delete , ctx , CreateNAD (types.NamespacedName {
649+ Name : spec ["octaviaNetworkAttachment" ].(string ),
650+ Namespace : namespace ,
651+ }))
652+
653+ DeferCleanup (k8sClient .Delete , ctx , CreateNode (types.NamespacedName {
654+ Namespace : namespace ,
655+ Name : "node1" ,
656+ }))
657+
658+ spec ["lbMgmtNetwork" ].(map [string ]interface {})["availabilityZoneCIDRs" ] = map [string ]string {
659+ "az1" : "172.34.0.0/16" ,
660+ "az2" : "172.44.0.0/16" ,
661+ }
662+ spec ["lbMgmtNetwork" ].(map [string ]interface {})["createDefaultLbMgmtNetwork" ] = false
663+ DeferCleanup (th .DeleteInstance , CreateOctavia (octaviaName , spec ))
664+
665+ th .SimulateJobSuccess (types.NamespacedName {Namespace : namespace , Name : octaviaName .Name + "-db-sync" })
666+ })
667+
668+ It ("should create appropriate resources in Neutron" , func () {
669+ th .ExpectCondition (
670+ octaviaName ,
671+ ConditionGetterFunc (OctaviaConditionGetter ),
672+ octaviav1 .OctaviaManagementNetworkReadyCondition ,
673+ corev1 .ConditionTrue ,
674+ )
675+
676+ instance := GetOctavia (octaviaName )
677+ tenant := GetProject (instance .Spec .TenantName )
678+ adminTenant := GetProject (octavia .AdminTenant )
679+
680+ nadConfig := GetNADConfig (types.NamespacedName {
681+ Name : instance .Spec .OctaviaNetworkAttachment ,
682+ Namespace : namespace })
683+
684+ // Networks
685+ netNameAZ1 := fmt .Sprintf (octavia .LbMgmtNetNameAZ , "az1" )
686+ netNameAZ2 := fmt .Sprintf (octavia .LbMgmtNetNameAZ , "az2" )
687+ expectedNetworks := map [string ]networks.Network {
688+ netNameAZ1 : {
689+ Description : fmt .Sprintf (octavia .LbMgmtNetDescriptionAZ , "az1" ),
690+ TenantID : tenant .ID ,
691+ AvailabilityZoneHints : []string {"az1" },
692+ },
693+ netNameAZ2 : {
694+ Description : fmt .Sprintf (octavia .LbMgmtNetDescriptionAZ , "az2" ),
695+ TenantID : tenant .ID ,
696+ AvailabilityZoneHints : []string {"az2" },
697+ },
698+ octavia .LbProvNetName : {
699+ Description : octavia .LbProvNetDescription ,
700+ TenantID : adminTenant .ID ,
701+ AvailabilityZoneHints : instance .Spec .LbMgmtNetworks .AvailabilityZones ,
702+ },
703+ }
704+
705+ resultNetworks := map [string ]networks.Network {}
706+ for _ , network := range apiFixtures .Neutron .Networks {
707+ resultNetworks [network .Name ] = network
708+ }
709+ Expect (resultNetworks ).To (HaveLen (3 ))
710+ for name , expectedNetwork := range expectedNetworks {
711+ network := resultNetworks [name ]
712+ Expect (network ).ToNot (Equal (networks.Network {}), "Network %s doesn't appear to exist" , name )
713+ Expect (network .Description ).To (Equal (expectedNetwork .Description ))
714+ Expect (network .TenantID ).To (Equal (expectedNetwork .TenantID ))
715+ Expect (network .AvailabilityZoneHints ).To (Equal (expectedNetwork .AvailabilityZoneHints ))
716+ }
717+
718+ lbMgmtPortAddress := map [string ]string {}
719+ lbMgmtPortID := map [string ]string {}
720+ for _ , az := range []string {"az1" , "az2" } {
721+ for _ , port := range apiFixtures .Neutron .Ports {
722+ if port .Name == fmt .Sprintf (octavia .LbMgmtRouterPortNameAZ , az ) {
723+ lbMgmtPortAddress [az ] = port .FixedIPs [0 ].IPAddress
724+ lbMgmtPortID [az ] = port .ID
725+ break
726+ }
727+ }
728+ }
729+ // Subnets
730+ subnetNameAZ1 := fmt .Sprintf (octavia .LbMgmtSubnetNameAZ , "az1" )
731+ subnetNameAZ2 := fmt .Sprintf (octavia .LbMgmtSubnetNameAZ , "az2" )
732+ expectedSubnets := map [string ]subnets.Subnet {
733+ subnetNameAZ1 : {
734+ Description : fmt .Sprintf (octavia .LbMgmtSubnetDescriptionAZ , "az1" ),
735+ TenantID : tenant .ID ,
736+ NetworkID : resultNetworks [netNameAZ1 ].ID ,
737+ CIDR : instance .Spec .LbMgmtNetworks .AvailabilityZoneCIDRs ["az1" ],
738+ HostRoutes : []subnets.HostRoute {{
739+ DestinationCIDR : nadConfig .IPAM .CIDR .String (),
740+ NextHop : lbMgmtPortAddress ["az1" ],
741+ }},
742+ },
743+ subnetNameAZ2 : {
744+ Description : fmt .Sprintf (octavia .LbMgmtSubnetDescriptionAZ , "az2" ),
745+ TenantID : tenant .ID ,
746+ NetworkID : resultNetworks [netNameAZ2 ].ID ,
747+ CIDR : instance .Spec .LbMgmtNetworks .AvailabilityZoneCIDRs ["az2" ],
748+ HostRoutes : []subnets.HostRoute {{
749+ DestinationCIDR : nadConfig .IPAM .CIDR .String (),
750+ NextHop : lbMgmtPortAddress ["az2" ],
751+ }},
752+ },
753+ octavia .LbProvSubnetName : {
754+ Description : octavia .LbProvSubnetDescription ,
755+ TenantID : adminTenant .ID ,
756+ NetworkID : resultNetworks [octavia .LbProvNetName ].ID ,
757+ CIDR : nadConfig .IPAM .CIDR .String (),
758+ },
759+ }
760+
761+ resultSubnets := map [string ]subnets.Subnet {}
762+ for _ , subnet := range apiFixtures .Neutron .Subnets {
763+ resultSubnets [subnet .Name ] = subnet
764+ }
765+ Expect (resultSubnets ).To (HaveLen (3 ))
766+ for name , expectedSubnet := range expectedSubnets {
767+ subnet := resultSubnets [name ]
768+ Expect (subnet ).ToNot (Equal (subnets.Subnet {}), "Subnet %s doesn't appear to exist" , name )
769+ Expect (subnet .Description ).To (Equal (expectedSubnet .Description ))
770+ Expect (subnet .TenantID ).To (Equal (expectedSubnet .TenantID ))
771+ Expect (subnet .NetworkID ).To (Equal (expectedSubnet .NetworkID ))
772+ Expect (subnet .CIDR ).To (Equal (expectedSubnet .CIDR ))
773+ Expect (subnet .HostRoutes ).To (Equal (expectedSubnet .HostRoutes ))
774+ }
775+
776+ // Routers
777+ expectedRouters := map [string ]routers.Router {
778+ octavia .LbRouterName : {
779+ GatewayInfo : routers.GatewayInfo {
780+ NetworkID : resultNetworks [octavia .LbProvNetName ].ID ,
781+ ExternalFixedIPs : []routers.ExternalFixedIP {
782+ {
783+ SubnetID : resultSubnets [octavia .LbProvSubnetName ].ID ,
784+ },
785+ },
786+ },
787+ AvailabilityZoneHints : instance .Spec .LbMgmtNetworks .AvailabilityZones ,
788+ },
789+ }
790+
791+ resultRouters := map [string ]routers.Router {}
792+ for _ , router := range apiFixtures .Neutron .Routers {
793+ resultRouters [router .Name ] = router
794+ }
795+ Expect (resultRouters ).To (HaveLen (1 ))
796+ for name , expectedRouter := range expectedRouters {
797+ router := resultRouters [name ]
798+ Expect (router ).ToNot (Equal (routers.Router {}), "Router %s doesn't appear to exist" , name )
799+ Expect (router .GatewayInfo .NetworkID ).To (Equal (expectedRouter .GatewayInfo .NetworkID ))
800+ Expect (router .GatewayInfo .ExternalFixedIPs [0 ].SubnetID ).To (Equal (expectedRouter .GatewayInfo .ExternalFixedIPs [0 ].SubnetID ))
801+ Expect (router .AvailabilityZoneHints ).To (Equal (expectedRouter .AvailabilityZoneHints ))
802+ }
803+
804+ expectedInterfaces := map [string ]routers.InterfaceInfo {
805+ fmt .Sprintf ("%s:%s" , resultRouters [octavia .LbRouterName ].ID , resultSubnets [subnetNameAZ1 ].ID ): {
806+ SubnetID : resultSubnets [subnetNameAZ1 ].ID ,
807+ PortID : lbMgmtPortID ["az1" ],
808+ },
809+ fmt .Sprintf ("%s:%s" , resultRouters [octavia .LbRouterName ].ID , resultSubnets [subnetNameAZ2 ].ID ): {
810+ SubnetID : resultSubnets [subnetNameAZ2 ].ID ,
811+ PortID : lbMgmtPortID ["az2" ],
812+ },
813+ }
814+ for id , expectedInterfaces := range expectedInterfaces {
815+ iface := apiFixtures .Neutron .InterfaceInfos [id ]
816+ Expect (iface ).ToNot (Equal (routers.InterfaceInfo {}), "Interface %s doesn't appear to exist" , id )
817+ Expect (iface .SubnetID ).To (Equal (expectedInterfaces .SubnetID ))
818+ Expect (iface .PortID ).To (Equal (expectedInterfaces .PortID ))
819+ }
820+ })
821+ })
822+
635823 // Predictable IPs
636824
637825 // Amphora Controller Daemonsets
0 commit comments