github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/nsxt_alb_virtual_service_test.go (about) 1 //go:build nsxt || alb || functional || ALL 2 3 package govcd 4 5 import ( 6 "fmt" 7 "time" 8 9 "github.com/vmware/go-vcloud-director/v2/types/v56" 10 11 . "gopkg.in/check.v1" 12 ) 13 14 func (vcd *TestVCD) Test_AlbVirtualService(check *C) { 15 if vcd.skipAdminTests { 16 check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) 17 } 18 skipNoNsxtAlbConfiguration(vcd, check) 19 skipOpenApiEndpointTest(vcd, check, types.OpenApiPathVersion1_0_0+types.OpenApiEndpointAlbEdgeGateway) 20 21 // Setup prerequisite components 22 controller, cloud, seGroup, edge, seGroupAssignment, albPool := setupAlbVirtualServicePrerequisites(check, vcd) 23 24 // Setup Org user and connection 25 adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org) 26 check.Assert(err, IsNil) 27 orgUserVcdClient, orgUser, err := newOrgUserConnection(adminOrg, "alb-virtual-service-testing", "CHANGE-ME", vcd.config.Provider.Url, true) 28 check.Assert(err, IsNil) 29 30 printVerbose("# Running tests as Sysadmin user\n") 31 // Run tests with System user 32 testMinimalVirtualServiceConfigHTTP(check, edge, albPool, seGroup, vcd, vcd.client) 33 testVirtualServiceConfigWithCertHTTPS(check, edge, albPool, seGroup, vcd, vcd.client) 34 testMinimalVirtualServiceConfigL4(check, edge, albPool, seGroup, vcd, vcd.client) 35 testMinimalVirtualServiceConfigL4TLS(check, edge, albPool, seGroup, vcd, vcd.client) 36 if vcd.client.Client.APIVCDMaxVersionIs(">= 37.0") { 37 printVerbose("# Running 10.4.0+ IPv6 Virtual Service test as Sysadmin user\n") 38 testVirtualServiceConfigHTTPIPv6(check, edge, albPool, seGroup, vcd, vcd.client) 39 } 40 41 printVerbose("# Running tests as Org user\n") 42 // Run tests with Org admin user 43 testMinimalVirtualServiceConfigHTTP(check, edge, albPool, seGroup, vcd, orgUserVcdClient) 44 testVirtualServiceConfigWithCertHTTPS(check, edge, albPool, seGroup, vcd, orgUserVcdClient) 45 testMinimalVirtualServiceConfigL4(check, edge, albPool, seGroup, vcd, orgUserVcdClient) 46 testMinimalVirtualServiceConfigL4TLS(check, edge, albPool, seGroup, vcd, orgUserVcdClient) 47 if vcd.client.Client.APIVCDMaxVersionIs(">= 37.0") { 48 printVerbose("# Running 10.4.0+ IPv6 Virtual Service test as Org user\n") 49 testVirtualServiceConfigHTTPIPv6(check, edge, albPool, seGroup, vcd, orgUserVcdClient) 50 } 51 52 // Test 10.4.1 Transparent mode on VCD >= 10.4.1 53 if vcd.client.Client.APIVCDMaxVersionIs(">= 37.1") { 54 printVerbose("# Running 10.4.1+ tests as Sysadmin user\n") 55 56 printVerbose("## Creating ALB Pool with Member Group (VCD 10.4.1+) as Sysadmin\n") 57 ipSet, poolWithMemberGroup := setupAlbPoolFirewallGroupMembers(check, vcd, edge) 58 59 testMinimalVirtualServiceConfigHTTPTransparent(check, edge, poolWithMemberGroup, seGroup, vcd, vcd.client, true) 60 testMinimalVirtualServiceConfigHTTPTransparent(check, edge, poolWithMemberGroup, seGroup, vcd, vcd.client, false) 61 62 printVerbose("# Running 10.4.1+ tests as Org user\n") 63 64 printVerbose("## Creating ALB Pool with Member Group (VCD 10.4.1+) as Org user\n") 65 testMinimalVirtualServiceConfigHTTPTransparent(check, edge, poolWithMemberGroup, seGroup, vcd, orgUserVcdClient, true) 66 testMinimalVirtualServiceConfigHTTPTransparent(check, edge, poolWithMemberGroup, seGroup, vcd, orgUserVcdClient, false) 67 68 // cleanup ipset and pool membership 69 err = poolWithMemberGroup.Delete() 70 check.Assert(err, IsNil) 71 72 err = retryOnError(ipSet.Delete, 5, 1*time.Second) 73 check.Assert(err, IsNil) 74 } 75 76 // teardown prerequisites 77 tearDownAlbVirtualServicePrerequisites(check, albPool, seGroupAssignment, edge, seGroup, cloud, controller) 78 79 // cleanup Org user 80 err = orgUser.Delete(true) 81 check.Assert(err, IsNil) 82 } 83 84 func testMinimalVirtualServiceConfigHTTP(check *C, edge *NsxtEdgeGateway, pool *NsxtAlbPool, seGroup *NsxtAlbServiceEngineGroup, vcd *TestVCD, client *VCDClient) { 85 virtualServiceConfig := &types.NsxtAlbVirtualService{ 86 Name: check.TestName(), 87 Enabled: addrOf(true), 88 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 89 SystemDefined: true, 90 Type: "HTTP", 91 }, 92 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 93 LoadBalancerPoolRef: types.OpenApiReference{ID: pool.NsxtAlbPool.ID}, 94 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 95 ServicePorts: []types.NsxtAlbVirtualServicePort{ 96 { 97 PortStart: addrOf(80), 98 }, 99 }, 100 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 101 } 102 103 virtualServiceConfigUpdated := &types.NsxtAlbVirtualService{ 104 Name: check.TestName(), 105 Description: "Updated", 106 Enabled: addrOf(true), 107 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 108 SystemDefined: true, 109 Type: "HTTP", 110 }, 111 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 112 LoadBalancerPoolRef: types.OpenApiReference{ID: pool.NsxtAlbPool.ID}, 113 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 114 ServicePorts: []types.NsxtAlbVirtualServicePort{ 115 { 116 PortStart: addrOf(443), 117 PortEnd: addrOf(449), 118 SslEnabled: addrOf(false), 119 }, 120 { 121 PortStart: addrOf(2000), 122 PortEnd: addrOf(2010), 123 SslEnabled: addrOf(false), 124 }, 125 }, 126 // Use Primary IP of Edge Gateway as virtual service IP 127 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 128 //HealthStatus: "", 129 //HealthMessage: "", 130 //DetailedHealthMessage: "", 131 } 132 133 testAlbVirtualServiceConfig(check, vcd, "MinimalHTTP", virtualServiceConfig, virtualServiceConfigUpdated, client) 134 } 135 136 func testVirtualServiceConfigHTTPIPv6(check *C, edge *NsxtEdgeGateway, pool *NsxtAlbPool, seGroup *NsxtAlbServiceEngineGroup, vcd *TestVCD, client *VCDClient) { 137 // Enable SLAAC Profile - this is a property of Edge Gateway - it will be removed with Edge 138 // Gateway itself upon cleanup 139 _, err := edge.UpdateSlaacProfile(&types.NsxtEdgeGatewaySlaacProfile{Enabled: true, Mode: "SLAAC"}) 140 check.Assert(err, IsNil) 141 defer func() { 142 _, err := edge.UpdateSlaacProfile(&types.NsxtEdgeGatewaySlaacProfile{Enabled: false, Mode: "DISABLED"}) 143 check.Assert(err, IsNil) 144 }() 145 146 virtualServiceConfig := &types.NsxtAlbVirtualService{ 147 Name: check.TestName(), 148 Enabled: addrOf(true), 149 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 150 SystemDefined: true, 151 Type: "HTTP", 152 }, 153 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 154 LoadBalancerPoolRef: types.OpenApiReference{ID: pool.NsxtAlbPool.ID}, 155 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 156 ServicePorts: []types.NsxtAlbVirtualServicePort{ 157 { 158 PortStart: addrOf(80), 159 }, 160 }, 161 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 162 IPv6VirtualIpAddress: "2002:0:0:1234:abcd:ffff:c0a8:103", 163 } 164 165 virtualServiceConfigUpdated := &types.NsxtAlbVirtualService{ 166 Name: check.TestName(), 167 Description: "Updated", 168 Enabled: addrOf(true), 169 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 170 SystemDefined: true, 171 Type: "HTTP", 172 }, 173 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 174 LoadBalancerPoolRef: types.OpenApiReference{ID: pool.NsxtAlbPool.ID}, 175 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 176 ServicePorts: []types.NsxtAlbVirtualServicePort{ 177 { 178 PortStart: addrOf(443), 179 PortEnd: addrOf(449), 180 SslEnabled: addrOf(false), 181 }, 182 { 183 PortStart: addrOf(2000), 184 PortEnd: addrOf(2010), 185 SslEnabled: addrOf(false), 186 }, 187 }, 188 // Use Primary IP of Edge Gateway as virtual service IP 189 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 190 IPv6VirtualIpAddress: "2002:0:0:1234:abcd:ffff:c0a8:103", 191 //HealthStatus: "", 192 //HealthMessage: "", 193 //DetailedHealthMessage: "", 194 } 195 196 testAlbVirtualServiceConfig(check, vcd, "IPv6", virtualServiceConfig, virtualServiceConfigUpdated, client) 197 } 198 199 func testMinimalVirtualServiceConfigHTTPTransparent(check *C, edge *NsxtEdgeGateway, poolWithMemberGroup *NsxtAlbPool, seGroup *NsxtAlbServiceEngineGroup, vcd *TestVCD, client *VCDClient, trueOnCreate bool) { 200 createTransparentMode := trueOnCreate 201 updateTransparentMode := !createTransparentMode 202 203 virtualServiceConfig := &types.NsxtAlbVirtualService{ 204 Name: check.TestName(), 205 Enabled: addrOf(true), 206 TransparentModeEnabled: &createTransparentMode, 207 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 208 SystemDefined: true, 209 Type: "HTTP", 210 }, 211 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 212 LoadBalancerPoolRef: types.OpenApiReference{ID: poolWithMemberGroup.NsxtAlbPool.ID}, 213 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 214 ServicePorts: []types.NsxtAlbVirtualServicePort{ 215 { 216 PortStart: addrOf(80), 217 }, 218 }, 219 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 220 } 221 222 virtualServiceConfigUpdated := &types.NsxtAlbVirtualService{ 223 Name: check.TestName(), 224 Description: "Updated", 225 Enabled: addrOf(true), 226 TransparentModeEnabled: &updateTransparentMode, 227 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 228 SystemDefined: true, 229 Type: "HTTP", 230 }, 231 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 232 LoadBalancerPoolRef: types.OpenApiReference{ID: poolWithMemberGroup.NsxtAlbPool.ID}, 233 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 234 ServicePorts: []types.NsxtAlbVirtualServicePort{ 235 { 236 PortStart: addrOf(443), 237 PortEnd: addrOf(449), 238 SslEnabled: addrOf(false), 239 }, 240 { 241 PortStart: addrOf(2000), 242 PortEnd: addrOf(2010), 243 SslEnabled: addrOf(false), 244 }, 245 }, 246 // Use Primary IP of Edge Gateway as virtual service IP 247 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 248 //HealthStatus: "", 249 //HealthMessage: "", 250 //DetailedHealthMessage: "", 251 } 252 253 testAlbVirtualServiceConfig(check, vcd, fmt.Sprintf("MinimalHTTPWithTransparentModeOnCreate%t", createTransparentMode), virtualServiceConfig, virtualServiceConfigUpdated, client) 254 } 255 256 func testMinimalVirtualServiceConfigL4(check *C, edge *NsxtEdgeGateway, pool *NsxtAlbPool, seGroup *NsxtAlbServiceEngineGroup, vcd *TestVCD, client *VCDClient) { 257 virtualServiceConfig := &types.NsxtAlbVirtualService{ 258 Name: check.TestName(), 259 Enabled: addrOf(true), 260 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 261 SystemDefined: true, 262 Type: "L4", 263 }, 264 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 265 LoadBalancerPoolRef: types.OpenApiReference{ID: pool.NsxtAlbPool.ID}, 266 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 267 ServicePorts: []types.NsxtAlbVirtualServicePort{ 268 { 269 PortStart: addrOf(80), 270 }, 271 }, 272 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 273 } 274 275 virtualServiceConfigUpdated := &types.NsxtAlbVirtualService{ 276 Name: check.TestName(), 277 Description: "Updated", 278 Enabled: addrOf(true), 279 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 280 SystemDefined: true, 281 Type: "L4", 282 }, 283 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 284 LoadBalancerPoolRef: types.OpenApiReference{ID: pool.NsxtAlbPool.ID}, 285 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 286 ServicePorts: []types.NsxtAlbVirtualServicePort{ 287 { 288 PortStart: addrOf(443), 289 TcpUdpProfile: &types.NsxtAlbVirtualServicePortTcpUdpProfile{ 290 SystemDefined: true, 291 Type: "TCP_PROXY", 292 }, 293 }, 294 { 295 PortStart: addrOf(8443), 296 PortEnd: addrOf(8445), 297 TcpUdpProfile: &types.NsxtAlbVirtualServicePortTcpUdpProfile{ 298 SystemDefined: true, 299 Type: "TCP_FAST_PATH", 300 }, 301 }, 302 { 303 PortStart: addrOf(9000), 304 TcpUdpProfile: &types.NsxtAlbVirtualServicePortTcpUdpProfile{ 305 SystemDefined: true, 306 Type: "UDP_FAST_PATH", 307 }, 308 }, 309 { 310 PortStart: addrOf(10000), 311 }, 312 }, 313 // Use Primary IP of Edge Gateway as virtual service IP 314 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 315 } 316 317 testAlbVirtualServiceConfig(check, vcd, "L4", virtualServiceConfig, virtualServiceConfigUpdated, client) 318 } 319 320 func testMinimalVirtualServiceConfigL4TLS(check *C, edge *NsxtEdgeGateway, pool *NsxtAlbPool, seGroup *NsxtAlbServiceEngineGroup, vcd *TestVCD, client *VCDClient) { 321 adminOrg, err := vcd.client.GetAdminOrgByName(vcd.org.Org.Name) 322 check.Assert(err, IsNil) 323 check.Assert(adminOrg, NotNil) 324 325 certificateConfigWithPrivateKey := &types.CertificateLibraryItem{ 326 Alias: check.TestName(), 327 Certificate: certificate, 328 PrivateKey: privateKey, 329 PrivateKeyPassphrase: "test", 330 } 331 openApiEndpoint, err := getEndpointByVersion(&vcd.client.Client) 332 check.Assert(err, IsNil) 333 createdCertificate, err := adminOrg.AddCertificateToLibrary(certificateConfigWithPrivateKey) 334 check.Assert(err, IsNil) 335 PrependToCleanupListOpenApi(createdCertificate.CertificateLibrary.Alias, check.TestName(), openApiEndpoint+createdCertificate.CertificateLibrary.Id) 336 337 virtualServiceConfig := &types.NsxtAlbVirtualService{ 338 Name: check.TestName(), 339 Enabled: addrOf(true), 340 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 341 SystemDefined: true, 342 Type: "L4_TLS", 343 }, 344 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 345 LoadBalancerPoolRef: types.OpenApiReference{ID: pool.NsxtAlbPool.ID}, 346 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 347 CertificateRef: &types.OpenApiReference{ID: createdCertificate.CertificateLibrary.Id}, 348 ServicePorts: []types.NsxtAlbVirtualServicePort{ 349 { 350 PortStart: addrOf(80), 351 SslEnabled: addrOf(true), 352 }, 353 }, 354 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 355 } 356 357 virtualServiceConfigUpdated := &types.NsxtAlbVirtualService{ 358 Name: check.TestName(), 359 Description: "Updated", 360 Enabled: addrOf(true), 361 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 362 SystemDefined: true, 363 Type: "L4_TLS", 364 }, 365 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 366 LoadBalancerPoolRef: types.OpenApiReference{ID: pool.NsxtAlbPool.ID}, 367 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 368 CertificateRef: &types.OpenApiReference{ID: createdCertificate.CertificateLibrary.Id}, 369 ServicePorts: []types.NsxtAlbVirtualServicePort{ 370 { 371 PortStart: addrOf(443), 372 SslEnabled: addrOf(true), 373 TcpUdpProfile: &types.NsxtAlbVirtualServicePortTcpUdpProfile{ 374 SystemDefined: true, 375 Type: "TCP_PROXY", // The only possible type with L4_TLS 376 }, 377 }, 378 }, 379 // Use Primary IP of Edge Gateway as virtual service IP 380 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 381 } 382 383 testAlbVirtualServiceConfig(check, vcd, "L4-TLS", virtualServiceConfig, virtualServiceConfigUpdated, client) 384 385 err = createdCertificate.Delete() 386 check.Assert(err, IsNil) 387 } 388 389 func testVirtualServiceConfigWithCertHTTPS(check *C, edge *NsxtEdgeGateway, pool *NsxtAlbPool, seGroup *NsxtAlbServiceEngineGroup, vcd *TestVCD, client *VCDClient) { 390 adminOrg, err := vcd.client.GetAdminOrgByName(vcd.org.Org.Name) 391 check.Assert(err, IsNil) 392 check.Assert(adminOrg, NotNil) 393 394 certificateConfigWithPrivateKey := &types.CertificateLibraryItem{ 395 Alias: check.TestName(), 396 Certificate: certificate, 397 PrivateKey: privateKey, 398 PrivateKeyPassphrase: "test", 399 } 400 401 openApiEndpoint, err := getEndpointByVersion(&vcd.client.Client) 402 check.Assert(err, IsNil) 403 createdCertificate, err := adminOrg.AddCertificateToLibrary(certificateConfigWithPrivateKey) 404 check.Assert(err, IsNil) 405 PrependToCleanupListOpenApi(createdCertificate.CertificateLibrary.Alias, check.TestName(), openApiEndpoint+createdCertificate.CertificateLibrary.Id) 406 407 virtualServiceConfig := &types.NsxtAlbVirtualService{ 408 Name: check.TestName(), 409 Enabled: addrOf(true), 410 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 411 SystemDefined: true, 412 Type: "HTTPS", 413 }, 414 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 415 LoadBalancerPoolRef: types.OpenApiReference{ID: pool.NsxtAlbPool.ID}, 416 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 417 CertificateRef: &types.OpenApiReference{ID: createdCertificate.CertificateLibrary.Id}, 418 ServicePorts: []types.NsxtAlbVirtualServicePort{{PortStart: addrOf(80), SslEnabled: addrOf(true)}}, 419 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 420 } 421 422 virtualServiceConfigUpdated := &types.NsxtAlbVirtualService{ 423 Name: check.TestName(), 424 Description: "Updated", 425 Enabled: addrOf(true), 426 ApplicationProfile: types.NsxtAlbVirtualServiceApplicationProfile{ 427 SystemDefined: true, 428 Type: "HTTPS", 429 }, 430 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 431 LoadBalancerPoolRef: types.OpenApiReference{ID: pool.NsxtAlbPool.ID}, 432 ServiceEngineGroupRef: types.OpenApiReference{ID: seGroup.NsxtAlbServiceEngineGroup.ID}, 433 CertificateRef: &types.OpenApiReference{ID: createdCertificate.CertificateLibrary.Id}, 434 ServicePorts: []types.NsxtAlbVirtualServicePort{ 435 { 436 PortStart: addrOf(80), 437 }, 438 { 439 PortStart: addrOf(443), 440 SslEnabled: addrOf(true), 441 }, 442 }, 443 // Use Primary IP of Edge Gateway as virtual service IP 444 VirtualIpAddress: edge.EdgeGateway.EdgeGatewayUplinks[0].Subnets.Values[0].PrimaryIP, 445 } 446 447 testAlbVirtualServiceConfig(check, vcd, "WithCertHTTPS", virtualServiceConfig, virtualServiceConfigUpdated, client) 448 449 err = createdCertificate.Delete() 450 check.Assert(err, IsNil) 451 } 452 453 func testAlbVirtualServiceConfig(check *C, vcd *TestVCD, name string, setupConfig *types.NsxtAlbVirtualService, updateConfig *types.NsxtAlbVirtualService, client *VCDClient) { 454 fmt.Printf("# Running ALB Virtual Service test with config %s ('System' user: %t) ", name, client.Client.IsSysAdmin) 455 456 edge, err := vcd.nsxtVdc.GetNsxtEdgeGatewayByName(vcd.config.VCD.Nsxt.EdgeGateway) 457 check.Assert(err, IsNil) 458 459 createdVirtualService, err := client.CreateNsxtAlbVirtualService(setupConfig) 460 check.Assert(err, IsNil) 461 462 // Verify mandatory fields 463 check.Assert(createdVirtualService.NsxtAlbVirtualService.ID, NotNil) 464 check.Assert(createdVirtualService.NsxtAlbVirtualService.Name, NotNil) 465 check.Assert(createdVirtualService.NsxtAlbVirtualService.GatewayRef.ID, NotNil) 466 467 openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbVirtualServices + createdVirtualService.NsxtAlbVirtualService.ID 468 PrependToCleanupListOpenApi(createdVirtualService.NsxtAlbVirtualService.Name, check.TestName(), openApiEndpoint) 469 470 // Get By ID 471 virtualServiceById, err := client.GetAlbVirtualServiceById(createdVirtualService.NsxtAlbVirtualService.ID) 472 check.Assert(err, IsNil) 473 check.Assert(virtualServiceById.NsxtAlbVirtualService.ID, Equals, createdVirtualService.NsxtAlbVirtualService.ID) 474 475 // Get By Name 476 virtualServiceByName, err := client.GetAlbVirtualServiceByName(edge.EdgeGateway.ID, createdVirtualService.NsxtAlbVirtualService.Name) 477 check.Assert(err, IsNil) 478 check.Assert(virtualServiceByName.NsxtAlbVirtualService.ID, Equals, createdVirtualService.NsxtAlbVirtualService.ID) 479 480 //Get All Virtual Service summaries 481 allVirtualServiceSummaries, err := client.GetAllAlbVirtualServiceSummaries(edge.EdgeGateway.ID, nil) 482 check.Assert(err, IsNil) 483 check.Assert(len(allVirtualServiceSummaries) > 0, Equals, true) 484 485 // Get All Pools 486 allVirtualServices, err := client.GetAllAlbVirtualServices(edge.EdgeGateway.ID, nil) 487 check.Assert(err, IsNil) 488 check.Assert(len(allVirtualServices) > 0, Equals, true) 489 490 check.Assert(len(allVirtualServiceSummaries), Equals, len(allVirtualServices)) 491 492 // Attempt an update if config is provided 493 if updateConfig != nil { 494 updateConfig.ID = createdVirtualService.NsxtAlbVirtualService.ID 495 updatedPool, err := createdVirtualService.Update(updateConfig) 496 check.Assert(err, IsNil) 497 check.Assert(createdVirtualService.NsxtAlbVirtualService.ID, Equals, updatedPool.NsxtAlbVirtualService.ID) 498 check.Assert(updatedPool.NsxtAlbVirtualService.Name, NotNil) 499 check.Assert(updatedPool.NsxtAlbVirtualService.GatewayRef.ID, NotNil) 500 } 501 502 err = createdVirtualService.Delete() 503 check.Assert(err, IsNil) 504 fmt.Printf("Done.\n") 505 } 506 507 func setupAlbVirtualServicePrerequisites(check *C, vcd *TestVCD) (*NsxtAlbController, *NsxtAlbCloud, *NsxtAlbServiceEngineGroup, *NsxtEdgeGateway, *NsxtAlbServiceEngineGroupAssignment, *NsxtAlbPool) { 508 controller, cloud, seGroup, edge, assignedSeGroup := setupAlbPoolPrerequisites(check, vcd) 509 510 poolConfig := &types.NsxtAlbPool{ 511 Name: check.TestName(), 512 Enabled: addrOf(true), 513 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 514 } 515 516 albPool, err := vcd.client.CreateNsxtAlbPool(poolConfig) 517 check.Assert(err, IsNil) 518 519 openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbPools + albPool.NsxtAlbPool.ID 520 PrependToCleanupListOpenApi(albPool.NsxtAlbPool.Name, check.TestName(), openApiEndpoint) 521 522 return controller, cloud, seGroup, edge, assignedSeGroup, albPool 523 } 524 525 func setupAlbPoolFirewallGroupMembers(check *C, vcd *TestVCD, edge *NsxtEdgeGateway) (*NsxtFirewallGroup, *NsxtAlbPool) { 526 // creates ip set 527 ipSetConfig := &types.NsxtFirewallGroup{ 528 Name: check.TestName(), 529 OwnerRef: &types.OpenApiReference{ID: edge.EdgeGateway.ID}, 530 Description: "Test IP Set", 531 Type: "IP_SET", 532 IpAddresses: []string{"1.1.1.1"}, 533 } 534 535 ipSet, err := vcd.nsxtVdc.CreateNsxtFirewallGroup(ipSetConfig) 536 check.Assert(err, IsNil) 537 538 // add ip set to cleanup list 539 openApiEndpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointFirewallGroups + ipSet.NsxtFirewallGroup.ID 540 PrependToCleanupListOpenApi(ipSet.NsxtFirewallGroup.Name, check.TestName(), openApiEndpoint) 541 542 poolConfig := &types.NsxtAlbPool{ 543 Name: check.TestName() + "-member-group", 544 Enabled: addrOf(true), 545 GatewayRef: types.OpenApiReference{ID: edge.EdgeGateway.ID}, 546 MemberGroupRef: &types.OpenApiReference{ 547 ID: ipSet.NsxtFirewallGroup.ID, 548 }, 549 } 550 551 albPool, err := vcd.client.CreateNsxtAlbPool(poolConfig) 552 check.Assert(err, IsNil) 553 554 openApiEndpoint = types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointAlbPools + albPool.NsxtAlbPool.ID 555 PrependToCleanupListOpenApi(albPool.NsxtAlbPool.Name, check.TestName(), openApiEndpoint) 556 557 return ipSet, albPool 558 } 559 560 func tearDownAlbVirtualServicePrerequisites(check *C, albPool *NsxtAlbPool, assignment *NsxtAlbServiceEngineGroupAssignment, edge *NsxtEdgeGateway, seGroup *NsxtAlbServiceEngineGroup, cloud *NsxtAlbCloud, controller *NsxtAlbController) { 561 err := albPool.Delete() 562 check.Assert(err, IsNil) 563 err = assignment.Delete() 564 check.Assert(err, IsNil) 565 err = edge.DisableAlb() 566 check.Assert(err, IsNil) 567 err = seGroup.Delete() 568 check.Assert(err, IsNil) 569 err = cloud.Delete() 570 check.Assert(err, IsNil) 571 err = controller.Delete() 572 check.Assert(err, IsNil) 573 }