|
| 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_GenericIpSpacePublic(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.OpenApiEndpointIpSpaces) |
| 18 | + |
| 19 | + ipSpaceConfig := &types.IpSpace{ |
| 20 | + Name: check.TestName(), |
| 21 | + IPSpaceInternalScope: []string{"22.0.0.0/24"}, |
| 22 | + IPSpaceExternalScope: "200.0.0.1/24", |
| 23 | + Type: types.IpSpacePublic, |
| 24 | + RouteAdvertisementEnabled: false, |
| 25 | + IPSpacePrefixes: []types.IPSpacePrefixes{ |
| 26 | + { |
| 27 | + DefaultQuotaForPrefixLength: -1, |
| 28 | + IPPrefixSequence: []types.IPPrefixSequence{ |
| 29 | + { |
| 30 | + StartingPrefixIPAddress: "22.0.0.200", |
| 31 | + PrefixLength: 31, |
| 32 | + TotalPrefixCount: 3, |
| 33 | + }, |
| 34 | + }, |
| 35 | + }, |
| 36 | + { |
| 37 | + DefaultQuotaForPrefixLength: 2, |
| 38 | + IPPrefixSequence: []types.IPPrefixSequence{ |
| 39 | + { |
| 40 | + StartingPrefixIPAddress: "22.0.0.100", |
| 41 | + PrefixLength: 30, |
| 42 | + TotalPrefixCount: 3, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + IPSpaceRanges: types.IPSpaceRanges{ |
| 48 | + DefaultFloatingIPQuota: 3, |
| 49 | + IPRanges: []types.IpSpaceRangeValues{ |
| 50 | + { |
| 51 | + StartIPAddress: "22.0.0.10", |
| 52 | + EndIPAddress: "22.0.0.30", |
| 53 | + }, |
| 54 | + { |
| 55 | + StartIPAddress: "22.0.0.32", |
| 56 | + EndIPAddress: "22.0.0.34", |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + createdIpSpace, err := vcd.client.GenCreateIpSpace(ipSpaceConfig) |
| 63 | + check.Assert(err, IsNil) |
| 64 | + check.Assert(createdIpSpace, NotNil) |
| 65 | + |
| 66 | + openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointIpSpaces + createdIpSpace.IpSpace.ID |
| 67 | + AddToCleanupListOpenApi(createdIpSpace.IpSpace.Name, check.TestName(), openApiEndpoint) |
| 68 | + |
| 69 | + // Get by ID |
| 70 | + byId, err := vcd.client.GenGetIpSpaceById(createdIpSpace.IpSpace.ID) |
| 71 | + check.Assert(err, IsNil) |
| 72 | + check.Assert(byId.IpSpace, DeepEquals, createdIpSpace.IpSpace) |
| 73 | + |
| 74 | + // Get by Name |
| 75 | + byName, err := vcd.client.GenGetIpSpaceByName(createdIpSpace.IpSpace.Name) |
| 76 | + check.Assert(err, IsNil) |
| 77 | + check.Assert(byName.IpSpace, DeepEquals, createdIpSpace.IpSpace) |
| 78 | + |
| 79 | + // Get all and make sure it is found |
| 80 | + allIpSpaces, err := vcd.client.GenGetAllIpSpaceSummaries(nil) |
| 81 | + check.Assert(err, IsNil) |
| 82 | + check.Assert(len(allIpSpaces) > 0, Equals, true) |
| 83 | + var found bool |
| 84 | + for i := range allIpSpaces { |
| 85 | + if allIpSpaces[i].IpSpace.ID == byId.IpSpace.ID { |
| 86 | + found = true |
| 87 | + break |
| 88 | + } |
| 89 | + } |
| 90 | + check.Assert(found, Equals, true) |
| 91 | + |
| 92 | + // If an Org is assigned - attempt to lookup by name and Org ID |
| 93 | + if byId.IpSpace.OrgRef != nil && byId.IpSpace.OrgRef.ID != "" { |
| 94 | + byNameAndOrgId, err := vcd.client.GenGetIpSpaceByNameAndOrgId(byId.IpSpace.Name, byId.IpSpace.OrgRef.ID) |
| 95 | + check.Assert(err, IsNil) |
| 96 | + check.Assert(byNameAndOrgId, NotNil) |
| 97 | + check.Assert(byNameAndOrgId.IpSpace, DeepEquals, createdIpSpace.IpSpace) |
| 98 | + |
| 99 | + } |
| 100 | + |
| 101 | + // Check an update |
| 102 | + |
| 103 | + ipSpaceConfig.ID = createdIpSpace.IpSpace.ID |
| 104 | + ipSpaceConfig.RouteAdvertisementEnabled = true |
| 105 | + ipSpaceConfig.IPSpaceInternalScope = append(ipSpaceConfig.IPSpaceInternalScope, "32.0.0.0/24") |
| 106 | + |
| 107 | + updatedIpSpace, err := createdIpSpace.Update(ipSpaceConfig) |
| 108 | + check.Assert(err, IsNil) |
| 109 | + check.Assert(updatedIpSpace, NotNil) |
| 110 | + check.Assert(len(ipSpaceConfig.IPSpaceInternalScope), Equals, len(updatedIpSpace.IpSpace.IPSpaceInternalScope)) |
| 111 | + |
| 112 | + if vcd.client.Client.APIVCDMaxVersionIs(">= 38.0") { |
| 113 | + fmt.Println("# Testing NAT and Firewall rule autocreation flags for VCD 10.5.0+") |
| 114 | + ipSpaceConfig.Name = check.TestName() + "-GatewayServiceConfig" |
| 115 | + ipSpaceConfig.DefaultGatewayServiceConfig = &types.IpSpaceDefaultGatewayServiceConfig{ |
| 116 | + EnableDefaultFirewallRuleCreation: true, |
| 117 | + EnableDefaultNoSnatRuleCreation: true, |
| 118 | + EnableDefaultSnatRuleCreation: true, |
| 119 | + } |
| 120 | + |
| 121 | + updatedIpSpace, err = updatedIpSpace.Update(ipSpaceConfig) |
| 122 | + check.Assert(err, IsNil) |
| 123 | + check.Assert(updatedIpSpace.IpSpace.DefaultGatewayServiceConfig, DeepEquals, ipSpaceConfig.DefaultGatewayServiceConfig) |
| 124 | + } |
| 125 | + |
| 126 | + err = createdIpSpace.Delete() |
| 127 | + check.Assert(err, IsNil) |
| 128 | + |
| 129 | + // Check that the entity is not found |
| 130 | + notFoundById, err := vcd.client.GenGetIpSpaceById(byId.IpSpace.ID) |
| 131 | + check.Assert(ContainsNotFound(err), Equals, true) |
| 132 | + check.Assert(notFoundById, IsNil) |
| 133 | +} |
0 commit comments