github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/ip_space_org_assignment_test.go (about) 1 //go:build network || nsxt || functional || openapi || ALL 2 3 package govcd 4 5 import ( 6 "fmt" 7 8 "github.com/vmware/go-vcloud-director/v2/types/v56" 9 . "gopkg.in/check.v1" 10 ) 11 12 func (vcd *TestVCD) Test_IpSpaceOrgAssignment(check *C) { 13 if vcd.skipAdminTests { 14 check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) 15 } 16 skipNoNsxtConfiguration(vcd, check) 17 skipOpenApiEndpointTest(vcd, check, types.OpenApiPathVersion1_0_0+types.OpenApiEndpointIpSpaceOrgAssignments) 18 19 ipSpace := createIpSpace(vcd, check) 20 extNet := createExternalNetwork(vcd, check) 21 22 // IP Space uplink (not directly referenced anywhere, but is required to make IP allocations) 23 ipSpaceUplink := createIpSpaceUplink(vcd, check, extNet.ExternalNetwork.ID, ipSpace.IpSpace.ID) 24 25 // Check if any Org assignments are found before Edge Gateway creation - there should be none as 26 // Org assignments are implicitly created during Edge Gateway creation 27 allOrgAssignments, err := ipSpace.GetAllOrgAssignments(nil) 28 check.Assert(err, IsNil) 29 check.Assert(len(allOrgAssignments), Equals, 0) 30 31 // Create NSX-T Edge Gateway 32 edgeGw := createNsxtEdgeGateway(vcd, check, extNet.ExternalNetwork.ID) 33 34 // After the Edge Gateway is created - one can find an implicitly created IP Space Org Assignment 35 orgAssignmentByOrgName, err := ipSpace.GetOrgAssignmentByOrgName(vcd.org.Org.Name) 36 check.Assert(err, IsNil) 37 check.Assert(orgAssignmentByOrgName, NotNil) 38 39 orgAssignmentByOrgId, err := ipSpace.GetOrgAssignmentByOrgId(vcd.org.Org.ID) 40 check.Assert(err, IsNil) 41 check.Assert(orgAssignmentByOrgId, NotNil) 42 43 // Get Org Assignment by ID 44 orgAssignmentById, err := ipSpace.GetOrgAssignmentById(orgAssignmentByOrgId.IpSpaceOrgAssignment.ID) 45 check.Assert(err, IsNil) 46 check.Assert(orgAssignmentById.IpSpaceOrgAssignment, DeepEquals, orgAssignmentByOrgId.IpSpaceOrgAssignment) 47 48 // Get All org Assignments and check that there is exactly one - matching other lookup methods 49 allOrgAssignments, err = ipSpace.GetAllOrgAssignments(nil) 50 check.Assert(err, IsNil) 51 check.Assert(len(allOrgAssignments), Equals, 1) 52 check.Assert(allOrgAssignments[0].IpSpaceOrgAssignment, DeepEquals, orgAssignmentByOrgId.IpSpaceOrgAssignment) 53 check.Assert(allOrgAssignments[0].IpSpaceOrgAssignment, DeepEquals, orgAssignmentByOrgName.IpSpaceOrgAssignment) 54 55 // Update 56 orgAssignmentById.IpSpaceOrgAssignment.CustomQuotas = &types.IpSpaceOrgAssignmentQuotas{ 57 FloatingIPQuota: addrOf(10), 58 IPPrefixQuotas: []types.IpSpaceOrgAssignmentIPPrefixQuotas{ 59 { 60 PrefixLength: addrOf(31), 61 Quota: addrOf(11), 62 }, 63 { 64 PrefixLength: addrOf(30), 65 Quota: addrOf(12), 66 }, 67 }, 68 } 69 70 updatedOrgAssignmentCustomQuota, err := orgAssignmentById.Update(orgAssignmentById.IpSpaceOrgAssignment) 71 check.Assert(err, IsNil) 72 check.Assert(updatedOrgAssignmentCustomQuota.IpSpaceOrgAssignment.CustomQuotas.FloatingIPQuota, DeepEquals, orgAssignmentById.IpSpaceOrgAssignment.CustomQuotas.FloatingIPQuota) 73 check.Assert(len(updatedOrgAssignmentCustomQuota.IpSpaceOrgAssignment.CustomQuotas.IPPrefixQuotas), DeepEquals, len(orgAssignmentById.IpSpaceOrgAssignment.CustomQuotas.IPPrefixQuotas)) 74 75 // Cleanup 76 err = edgeGw.Delete() 77 check.Assert(err, IsNil) 78 79 err = ipSpaceUplink.Delete() 80 check.Assert(err, IsNil) 81 82 err = extNet.Delete() 83 check.Assert(err, IsNil) 84 85 err = ipSpace.Delete() 86 check.Assert(err, IsNil) 87 }