Skip to content

Commit 559b662

Browse files
committed
Improvements, new tests
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
1 parent b31d977 commit 559b662

6 files changed

+210
-16
lines changed

.changes/v2.22.0/610-improvements.md

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
* New method `NsxtEdgeGateway.ReorderUplinks()` that will ensure that NSX-T Tier0 Gateway backed
2-
uplink is at position 0 in the slice of uplinks. All NSX-T Edge Gateway retrieval functions will
3-
call it implicitly [GH-610]
41
* New method `NsxtEdgeGateway.GetAllocatedIpCountByUplinkType` complementing existing
52
`NsxtEdgeGateway.GetAllocatedIpCount`. It will return allocated IP counts by uplink types [GH-610]

govcd/api_vcd_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ type TestConfig struct {
189189
ExternalNetwork string `yaml:"externalNetwork"`
190190
EdgeGateway string `yaml:"edgeGateway"`
191191
NsxtImportSegment string `yaml:"nsxtImportSegment"`
192+
NsxtImportSegment2 string `yaml:"nsxtImportSegment2"`
192193
VdcGroup string `yaml:"vdcGroup"`
193194
VdcGroupEdgeGateway string `yaml:"vdcGroupEdgeGateway"`
194195
NsxtEdgeCluster string `yaml:"nsxtEdgeCluster"`

govcd/external_network_v2_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ func (vcd *TestVCD) testCreateExternalNetworkV2Nsxt(check *C, backingName, backi
8686
// getBackingIdByNameAndType looks up Backing ID by name and type
8787
func getBackingIdByNameAndType(check *C, backingName string, backingType string, vcd *TestVCD, nsxtManagerId string) string {
8888
var backingId string
89-
switch backingType {
90-
case types.ExternalNetworkBackingTypeNsxtTier0Router: // Lookup T0 router ID
89+
switch {
90+
case backingType == types.ExternalNetworkBackingTypeNsxtTier0Router || backingType == types.ExternalNetworkBackingTypeNsxtVrfTier0Router: // Lookup T0 or T0 VRF
9191
tier0RouterVrf, err := vcd.client.GetImportableNsxtTier0RouterByName(backingName, nsxtManagerId)
9292
check.Assert(err, IsNil)
9393
backingId = tier0RouterVrf.NsxtTier0Router.ID
94-
case types.ExternalNetworkBackingTypeNsxtSegment: // Lookup segment ID
94+
case backingType == types.ExternalNetworkBackingTypeNsxtSegment: // Lookup segment ID
9595
bareNsxtManagerId, err := getBareEntityUuid(nsxtManagerId)
9696
check.Assert(err, IsNil)
9797
filter := map[string]string{"nsxTManager": bareNsxtManagerId}

govcd/nsxt_edgegateway.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (egw *NsxtEdgeGateway) Refresh() error {
198198
}
199199
egw.EdgeGateway = refreshedEdge.EdgeGateway
200200

201-
err = egw.ReorderUplinks()
201+
err = egw.reorderUplinks()
202202
if err != nil {
203203
return fmt.Errorf("error reordering Edge Gateway Uplinks after refresh operation: %s", err)
204204
}
@@ -237,7 +237,7 @@ func (egw *NsxtEdgeGateway) Update(edgeGatewayConfig *types.OpenAPIEdgeGateway)
237237
return nil, fmt.Errorf("error updating Edge Gateway: %s", err)
238238
}
239239

240-
err = egw.ReorderUplinks()
240+
err = egw.reorderUplinks()
241241
if err != nil {
242242
return nil, fmt.Errorf("error reordering Edge Gateway Uplinks after update operation: %s", err)
243243
}
@@ -291,15 +291,15 @@ func (egw *NsxtEdgeGateway) MoveToVdcOrVdcGroup(vdcOrVdcGroupId string) (*NsxtEd
291291
return egw.Update(edgeGatewayConfig)
292292
}
293293

294-
// ReorderUplinks will ensure that uplink at slice index 0 is the one backed by NSX-T Tier0 External network.
294+
// reorderUplinks will ensure that uplink at slice index 0 is the one backed by NSX-T Tier0 External network.
295295
// NSX-T Edge Gateway can have many uplinks of different types (they are differentiated by 'backingType' field):
296296
// * MANDATORY - exactly 1 uplink to Tier0 Gateway (External network backed by NSX-T T0 Gateway) [backingType==NSXT_TIER0]
297297
// * OPTIONAL - one or more External Network Uplinks (backed by NSX-T Segment backed External networks) [backingType==IMPORTED_T_LOGICAL_SWITCH]
298298
// It is expected that the Tier0 gateway uplink is always at index 0, but we have seen where VCD API
299299
// shuffles response values therefore it is important to ensure that uplink with
300300
// backingType==NSXT_TIER0 the element 0 in types.EdgeGatewayUplinks to avoid breaking functionality
301301
// in upstream code.
302-
func (egw *NsxtEdgeGateway) ReorderUplinks() error {
302+
func (egw *NsxtEdgeGateway) reorderUplinks() error {
303303
if egw == nil || egw.EdgeGateway == nil {
304304
return fmt.Errorf("edge gateway cannot be nil ")
305305
}
@@ -347,7 +347,7 @@ func getNsxtEdgeGatewayById(client *Client, id string, queryParameters url.Value
347347
ErrorEntityNotFound, egw.EdgeGateway.GatewayBacking.GatewayType)
348348
}
349349

350-
err = egw.ReorderUplinks()
350+
err = egw.reorderUplinks()
351351
if err != nil {
352352
return nil, fmt.Errorf("error reordering Edge Gateway Uplink after API retrieval")
353353
}
@@ -404,7 +404,7 @@ func getAllNsxtEdgeGateways(client *Client, queryParameters url.Values) ([]*Nsxt
404404

405405
// Reorder uplink in all Edge Gateways
406406
for edgeIndex := range onlyNsxtEdges {
407-
err := onlyNsxtEdges[edgeIndex].ReorderUplinks()
407+
err := onlyNsxtEdges[edgeIndex].reorderUplinks()
408408
if err != nil {
409409
return nil, fmt.Errorf("error reordering NSX-T Edge Gateway Uplinks for gateway '%s' ('%s'): %s",
410410
onlyNsxtEdges[edgeIndex].EdgeGateway.Name, onlyNsxtEdges[edgeIndex].EdgeGateway.ID, err)
@@ -543,8 +543,10 @@ func (egw *NsxtEdgeGateway) GetAllocatedIpCount(refresh bool) (int, error) {
543543
}
544544

545545
func (egw *NsxtEdgeGateway) GetAllocatedIpCountByUplinkType(refresh bool, uplinkType string) (int, error) {
546-
if uplinkType != "NSXT_TIER0" && uplinkType != "IMPORTED_T_LOGICAL_SWITCH" {
547-
return 0, fmt.Errorf("invalid 'uplinkType', expected 'NSXT_TIER0' or 'IMPORTED_T_LOGICAL_SWITCH', got: %s", uplinkType)
546+
if uplinkType != "NSXT_TIER0" &&
547+
uplinkType != "IMPORTED_T_LOGICAL_SWITCH" &&
548+
uplinkType != "NSXT_VRF_TIER0" {
549+
return 0, fmt.Errorf("invalid 'uplinkType', expected 'NSXT_TIER0', 'IMPORTED_T_LOGICAL_SWITCH' or 'NSXT_VRF_TIER0', got: %s", uplinkType)
548550
}
549551

550552
if refresh {

govcd/nsxt_edgegateway_test.go

+193
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,196 @@ func (vcd *TestVCD) Test_NsxtEdgeSlaacProfile(check *C) {
643643
check.Assert(err, IsNil)
644644
check.Assert(updatedSlaacProfile, NotNil)
645645
}
646+
647+
// Test_NsxtEdgeCreateWithT0AndExternalNetworks checks that IP Allocation counts and External
648+
// Network attachment works well with NSX-T T0 Gateway backed external network
649+
func (vcd *TestVCD) Test_NsxtEdgeCreateWithT0AndExternalNetworks(check *C) {
650+
test_NsxtEdgeCreateWithExternalNetworks(vcd, check, vcd.config.VCD.Nsxt.Tier0router, types.ExternalNetworkBackingTypeNsxtTier0Router)
651+
}
652+
653+
// Test_NsxtEdgeCreateWithT0VrfAndExternalNetworks checks that IP Allocation counts and External
654+
// Network attachment works well with NSX-T T0 VRF Gateway backed external network
655+
func (vcd *TestVCD) Test_NsxtEdgeCreateWithT0VrfAndExternalNetworks(check *C) {
656+
test_NsxtEdgeCreateWithExternalNetworks(vcd, check, vcd.config.VCD.Nsxt.Tier0routerVrf, types.ExternalNetworkBackingTypeNsxtVrfTier0Router)
657+
}
658+
659+
func test_NsxtEdgeCreateWithExternalNetworks(vcd *TestVCD, check *C, backingRouter, backingRouterType string) {
660+
if vcd.client.Client.APIVCDMaxVersionIs("< 37.1") {
661+
check.Skip("Segment Backed External Network uplinks are supported in VCD 10.4.1+")
662+
}
663+
skipNoNsxtConfiguration(vcd, check)
664+
skipOpenApiEndpointTest(vcd, check, types.OpenApiPathVersion1_0_0+types.OpenApiEndpointEdgeGateways)
665+
vcd.skipIfNotSysAdmin(check)
666+
667+
adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
668+
check.Assert(err, IsNil)
669+
check.Assert(adminOrg, NotNil)
670+
671+
nsxtVdc, err := adminOrg.GetVDCByName(vcd.config.VCD.Nsxt.Vdc, false)
672+
if ContainsNotFound(err) {
673+
check.Skip(fmt.Sprintf("No NSX-T VDC (%s) found - skipping test", vcd.config.VCD.Nsxt.Vdc))
674+
}
675+
check.Assert(err, IsNil)
676+
check.Assert(nsxtVdc, NotNil)
677+
678+
// Setup 2 NSX-T Segment backed External Networks and 1 T0 or T0 VRF backed networks
679+
nsxtManager, err := vcd.client.QueryNsxtManagerByName(vcd.config.VCD.Nsxt.Manager)
680+
check.Assert(err, IsNil)
681+
nsxtManagerId, err := BuildUrnWithUuid("urn:vcloud:nsxtmanager:", extractUuid(nsxtManager[0].HREF))
682+
check.Assert(err, IsNil)
683+
684+
// T0 backed external network
685+
backingExtNet := getBackingIdByNameAndType(check, backingRouter, backingRouterType, vcd, nsxtManagerId)
686+
nsxtExternalNetworkCfg := t0vrfBackedExternalNetworkConfig(vcd, check.TestName()+"-t0", "89.1.1", backingRouterType, backingExtNet, nsxtManagerId)
687+
nsxtExternalNetwork, err := CreateExternalNetworkV2(vcd.client, nsxtExternalNetworkCfg)
688+
check.Assert(err, IsNil)
689+
check.Assert(nsxtExternalNetwork, NotNil)
690+
openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointExternalNetworks + nsxtExternalNetwork.ExternalNetwork.ID
691+
AddToCleanupListOpenApi(nsxtExternalNetwork.ExternalNetwork.Name, check.TestName(), openApiEndpoint)
692+
693+
// First NSX-T Segment backed network
694+
backingId1 := getBackingIdByNameAndType(check, vcd.config.VCD.Nsxt.NsxtImportSegment, types.ExternalNetworkBackingTypeNsxtSegment, vcd, nsxtManagerId)
695+
segmentBackedNet1Cfg := t0vrfBackedExternalNetworkConfig(vcd, check.TestName()+"-1", "1.1.1", types.ExternalNetworkBackingTypeNsxtSegment, backingId1, nsxtManagerId)
696+
segmentBackedNet1, err := CreateExternalNetworkV2(vcd.client, segmentBackedNet1Cfg)
697+
check.Assert(err, IsNil)
698+
check.Assert(segmentBackedNet1, NotNil)
699+
openApiEndpoint = types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointExternalNetworks + segmentBackedNet1.ExternalNetwork.ID
700+
AddToCleanupListOpenApi(segmentBackedNet1.ExternalNetwork.Name, check.TestName(), openApiEndpoint)
701+
702+
// Second NSX-T Segment backed network
703+
backingId2 := getBackingIdByNameAndType(check, vcd.config.VCD.Nsxt.NsxtImportSegment2, types.ExternalNetworkBackingTypeNsxtSegment, vcd, nsxtManagerId)
704+
segmentBackedNet2Cfg := t0vrfBackedExternalNetworkConfig(vcd, check.TestName()+"-2", "4.4.4", types.ExternalNetworkBackingTypeNsxtSegment, backingId2, nsxtManagerId)
705+
segmentBackedNet2, err := CreateExternalNetworkV2(vcd.client, segmentBackedNet2Cfg)
706+
check.Assert(err, IsNil)
707+
check.Assert(segmentBackedNet2, NotNil)
708+
openApiEndpoint = types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointExternalNetworks + segmentBackedNet2.ExternalNetwork.ID
709+
AddToCleanupListOpenApi(segmentBackedNet1.ExternalNetwork.Name, check.TestName(), openApiEndpoint)
710+
// Setup 2 NSX-T Segment backed External Networks and 1 T0 or T0 VRF backed networks
711+
712+
egwDefinition := &types.OpenAPIEdgeGateway{
713+
Name: "nsx-t-edge",
714+
Description: "nsx-t-edge-description",
715+
OrgVdc: &types.OpenApiReference{
716+
ID: nsxtVdc.Vdc.ID,
717+
},
718+
EdgeGatewayUplinks: []types.EdgeGatewayUplinks{
719+
{
720+
UplinkID: nsxtExternalNetwork.ExternalNetwork.ID,
721+
Subnets: types.OpenAPIEdgeGatewaySubnets{Values: []types.OpenAPIEdgeGatewaySubnetValue{{
722+
Gateway: "5.1.1.1",
723+
PrefixLength: 24,
724+
Enabled: true,
725+
}}},
726+
Connected: true,
727+
Dedicated: false,
728+
},
729+
{
730+
UplinkID: segmentBackedNet1.ExternalNetwork.ID,
731+
Subnets: types.OpenAPIEdgeGatewaySubnets{Values: []types.OpenAPIEdgeGatewaySubnetValue{{
732+
Gateway: "1.1.1.1",
733+
PrefixLength: 24,
734+
Enabled: true,
735+
AutoAllocateIPRanges: true,
736+
PrimaryIP: "1.1.1.5",
737+
TotalIPCount: addrOf(4),
738+
}}},
739+
Connected: true,
740+
Dedicated: false,
741+
},
742+
{
743+
UplinkID: segmentBackedNet2.ExternalNetwork.ID,
744+
Subnets: types.OpenAPIEdgeGatewaySubnets{Values: []types.OpenAPIEdgeGatewaySubnetValue{{
745+
Gateway: "4.4.4.1",
746+
PrefixLength: 24,
747+
Enabled: true,
748+
AutoAllocateIPRanges: true,
749+
TotalIPCount: addrOf(7),
750+
}}},
751+
Connected: true,
752+
Dedicated: false,
753+
},
754+
},
755+
}
756+
757+
createdEdge, err := adminOrg.CreateNsxtEdgeGateway(egwDefinition)
758+
check.Assert(err, IsNil)
759+
check.Assert(createdEdge.EdgeGateway.Name, Equals, egwDefinition.Name)
760+
openApiEndpoint = types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGateways + createdEdge.EdgeGateway.ID
761+
PrependToCleanupListOpenApi(createdEdge.EdgeGateway.Name, check.TestName(), openApiEndpoint)
762+
// check.Assert(*createdEdge.EdgeGateway.EdgeGatewayUplinks[0].BackingType, Equals, types.ExternalNetworkBackingTypeNsxtTier0Router)
763+
764+
// Retrieve edge gateway
765+
retrievedEdge, err := adminOrg.GetNsxtEdgeGatewayById(createdEdge.EdgeGateway.ID)
766+
check.Assert(err, IsNil)
767+
check.Assert(retrievedEdge, NotNil)
768+
// check.Assert(*retrievedEdge.EdgeGateway.EdgeGatewayUplinks[0].BackingType, Equals, types.ExternalNetworkBackingTypeNsxtTier0Router)
769+
770+
// Check IP allocation in NSX-T Segment backed networks
771+
totalAllocatedIpCountSegmentBacked, err := retrievedEdge.GetAllocatedIpCountByUplinkType(false, types.ExternalNetworkBackingTypeNsxtSegment)
772+
check.Assert(err, IsNil)
773+
check.Assert(totalAllocatedIpCountSegmentBacked, Equals, (4 + 7))
774+
775+
// Check IP allocation in NSX-T T0 backed networks
776+
totalAllocatedIpCountT0backed, err := retrievedEdge.GetAllocatedIpCountByUplinkType(false, backingRouterType)
777+
check.Assert(err, IsNil)
778+
check.Assert(totalAllocatedIpCountT0backed, Equals, 1)
779+
780+
// Check IP allocation for all subnets
781+
totalAllocatedIpCount, err := retrievedEdge.GetAllocatedIpCount(false)
782+
check.Assert(err, IsNil)
783+
check.Assert(totalAllocatedIpCount, Equals, (1 + 4 + 7))
784+
785+
createdEdge.EdgeGateway.Name = check.TestName() + "-renamed-edge"
786+
updatedEdge, err := createdEdge.Update(createdEdge.EdgeGateway)
787+
check.Assert(err, IsNil)
788+
check.Assert(updatedEdge.EdgeGateway.Name, Equals, createdEdge.EdgeGateway.Name)
789+
790+
// Check IP allocation in NSX-T Segment backed networks
791+
totalAllocatedIpCountSegmentBacked, err = updatedEdge.GetAllocatedIpCountByUplinkType(false, types.ExternalNetworkBackingTypeNsxtSegment)
792+
check.Assert(err, IsNil)
793+
check.Assert(totalAllocatedIpCountSegmentBacked, Equals, (4 + 7))
794+
795+
// Check IP allocation in NSX-T T0 backed networks
796+
totalAllocatedIpCountT0backed, err = updatedEdge.GetAllocatedIpCountByUplinkType(false, backingRouterType)
797+
check.Assert(err, IsNil)
798+
check.Assert(totalAllocatedIpCountT0backed, Equals, 1)
799+
800+
// Check IP allocation for all subnets
801+
totalAllocatedIpCount, err = updatedEdge.GetAllocatedIpCount(false)
802+
check.Assert(err, IsNil)
803+
check.Assert(totalAllocatedIpCount, Equals, (1 + 4 + 7))
804+
805+
// Cleanup
806+
err = updatedEdge.Delete()
807+
check.Assert(err, IsNil)
808+
}
809+
810+
func t0vrfBackedExternalNetworkConfig(vcd *TestVCD, name, ipPrefix string, backingType, backingId, NetworkProviderId string) *types.ExternalNetworkV2 {
811+
net := &types.ExternalNetworkV2{
812+
Name: name,
813+
Subnets: types.ExternalNetworkV2Subnets{Values: []types.ExternalNetworkV2Subnet{
814+
{
815+
Gateway: ipPrefix + ".1",
816+
PrefixLength: 24,
817+
IPRanges: types.ExternalNetworkV2IPRanges{Values: []types.ExternalNetworkV2IPRange{
818+
{
819+
StartAddress: ipPrefix + ".3",
820+
EndAddress: ipPrefix + ".50",
821+
},
822+
}},
823+
Enabled: true,
824+
},
825+
}},
826+
NetworkBackings: types.ExternalNetworkV2Backings{Values: []types.ExternalNetworkV2Backing{
827+
{
828+
BackingID: backingId,
829+
NetworkProvider: types.NetworkProvider{
830+
ID: NetworkProviderId,
831+
},
832+
BackingTypeValue: backingType,
833+
},
834+
}},
835+
}
836+
837+
return net
838+
}

types/v56/nsxt_types.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ type EdgeGatewayUplinks struct {
7373
Dedicated bool `json:"dedicated,omitempty"`
7474

7575
// BackingType of uplink. This can be:
76-
// * NSXT_TIER0 - The default and mandatory External Network backed by NSX-T Tier0 Gateway
77-
// * IMPORTED_T_LOGICAL_SWITCH - External Network uplinks (External Networks backed by NSX-T Segment)
76+
// * types.ExternalNetworkBackingTypeNsxtTier0Router (NSXT_TIER0) - The default and mandatory External Network backed by NSX-T Tier0 Gateway
77+
// * types.ExternalNetworkBackingTypeNsxtVrfTier0Router (NSXT_VRF_TIER0) -
78+
// * types.ExternalNetworkBackingTypeNsxtSegment (IMPORTED_T_LOGICAL_SWITCH) - External Network uplinks (External Networks backed by NSX-T Segment)
7879
BackingType *string `json:"backingType,omitempty"`
7980

8081
// UsingIpSpace is a boolean flag showing if the uplink uses IP Space

0 commit comments

Comments
 (0)