@@ -21,10 +21,7 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkIsolated(check *C) {
21
21
orgVdcNetworkConfig := & types.OpenApiOrgVdcNetwork {
22
22
Name : check .TestName (),
23
23
Description : check .TestName () + "-description" ,
24
-
25
- // On v35.0 orgVdc is not supported anymore. Using ownerRef instead.
26
- OwnerRef : & types.OpenApiReference {ID : vcd .nsxtVdc .Vdc .ID },
27
-
24
+ OwnerRef : & types.OpenApiReference {ID : vcd .nsxtVdc .Vdc .ID },
28
25
NetworkType : types .OrgVdcNetworkTypeIsolated ,
29
26
Subnets : types.OrgVdcNetworkSubnets {
30
27
Values : []types.OrgVdcNetworkSubnetValues {
@@ -54,8 +51,8 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkIsolated(check *C) {
54
51
},
55
52
}
56
53
57
- runOpenApiOrgVdcNetworkTest (check , vcd , vcd .nsxtVdc , orgVdcNetworkConfig , types .OrgVdcNetworkTypeIsolated , nil )
58
- runOpenApiOrgVdcNetworkWithVdcGroupTest (check , vcd , orgVdcNetworkConfig , types .OrgVdcNetworkTypeIsolated , nil )
54
+ runOpenApiOrgVdcNetworkTest (check , vcd , vcd .nsxtVdc , orgVdcNetworkConfig , types .OrgVdcNetworkTypeIsolated , [] dhcpConfigFunc { nsxtDhcpConfigNetworkMode } )
55
+ runOpenApiOrgVdcNetworkWithVdcGroupTest (check , vcd , orgVdcNetworkConfig , types .OrgVdcNetworkTypeIsolated , [] dhcpConfigFunc { nsxtDhcpConfigNetworkMode } )
59
56
}
60
57
61
58
func (vcd * TestVCD ) Test_NsxtOrgVdcNetworkRouted (check * C ) {
@@ -68,10 +65,7 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkRouted(check *C) {
68
65
orgVdcNetworkConfig := & types.OpenApiOrgVdcNetwork {
69
66
Name : check .TestName (),
70
67
Description : check .TestName () + "-description" ,
71
-
72
- // On v35.0 orgVdc is not supported anymore. Using ownerRef instead.
73
- OwnerRef : & types.OpenApiReference {ID : vcd .nsxtVdc .Vdc .ID },
74
-
68
+ OwnerRef : & types.OpenApiReference {ID : vcd .nsxtVdc .Vdc .ID },
75
69
NetworkType : types .OrgVdcNetworkTypeRouted ,
76
70
77
71
// Connection is used for "routed" network
@@ -115,8 +109,8 @@ func (vcd *TestVCD) Test_NsxtOrgVdcNetworkRouted(check *C) {
115
109
},
116
110
}
117
111
118
- runOpenApiOrgVdcNetworkTest (check , vcd , vcd .nsxtVdc , orgVdcNetworkConfig , types .OrgVdcNetworkTypeRouted , nsxtRoutedDhcpConfig )
119
- runOpenApiOrgVdcNetworkWithVdcGroupTest (check , vcd , orgVdcNetworkConfig , types .OrgVdcNetworkTypeRouted , nsxtRoutedDhcpConfig )
112
+ runOpenApiOrgVdcNetworkTest (check , vcd , vcd .nsxtVdc , orgVdcNetworkConfig , types .OrgVdcNetworkTypeRouted , [] dhcpConfigFunc { nsxtRoutedDhcpConfigEdgeMode , nsxtDhcpConfigNetworkMode } )
113
+ runOpenApiOrgVdcNetworkWithVdcGroupTest (check , vcd , orgVdcNetworkConfig , types .OrgVdcNetworkTypeRouted , [] dhcpConfigFunc { nsxtRoutedDhcpConfigEdgeMode , nsxtDhcpConfigNetworkMode } )
120
114
}
121
115
122
116
func (vcd * TestVCD ) Test_NsxtOrgVdcNetworkImported (check * C ) {
@@ -330,7 +324,7 @@ func (vcd *TestVCD) Test_NsxvOrgVdcNetworkDirect(check *C) {
330
324
runOpenApiOrgVdcNetworkTest (check , vcd , vcd .vdc , orgVdcNetworkConfig , types .OrgVdcNetworkTypeDirect , nil )
331
325
}
332
326
333
- func runOpenApiOrgVdcNetworkTest (check * C , vcd * TestVCD , vdc * Vdc , orgVdcNetworkConfig * types.OpenApiOrgVdcNetwork , expectNetworkType string , dhcpFunc dhcpConfigFunc ) {
327
+ func runOpenApiOrgVdcNetworkTest (check * C , vcd * TestVCD , vdc * Vdc , orgVdcNetworkConfig * types.OpenApiOrgVdcNetwork , expectNetworkType string , dhcpFunc [] dhcpConfigFunc ) {
334
328
orgVdcNet , err := vdc .CreateOpenApiOrgVdcNetwork (orgVdcNetworkConfig )
335
329
check .Assert (err , IsNil )
336
330
@@ -370,8 +364,8 @@ func runOpenApiOrgVdcNetworkTest(check *C, vcd *TestVCD, vdc *Vdc, orgVdcNetwork
370
364
check .Assert (updatedOrgVdcNet .OpenApiOrgVdcNetwork .Description , Equals , orgVdcNet .OpenApiOrgVdcNetwork .Description )
371
365
372
366
// Configure DHCP if specified
373
- if dhcpFunc != nil {
374
- dhcpFunc (check , vcd , vdc , updatedOrgVdcNet .OpenApiOrgVdcNetwork .ID )
367
+ for i := range dhcpFunc {
368
+ dhcpFunc [ i ] (check , vcd , vdc , updatedOrgVdcNet .OpenApiOrgVdcNetwork .ID )
375
369
}
376
370
// Delete
377
371
err = orgVdcNet .Delete ()
@@ -387,7 +381,7 @@ func runOpenApiOrgVdcNetworkTest(check *C, vcd *TestVCD, vdc *Vdc, orgVdcNetwork
387
381
388
382
type dhcpConfigFunc func (check * C , vcd * TestVCD , vdc * Vdc , orgNetId string )
389
383
390
- func nsxtRoutedDhcpConfig (check * C , vcd * TestVCD , vdc * Vdc , orgNetId string ) {
384
+ func nsxtRoutedDhcpConfigEdgeMode (check * C , vcd * TestVCD , vdc * Vdc , orgNetId string ) {
391
385
dhcpDefinition := & types.OpenApiOrgVdcNetworkDhcp {
392
386
Enabled : takeBoolPointer (true ),
393
387
DhcpPools : []types.OpenApiOrgVdcNetworkDhcpPools {
@@ -435,10 +429,81 @@ func nsxtRoutedDhcpConfig(check *C, vcd *TestVCD, vdc *Vdc, orgNetId string) {
435
429
check .Assert (err , IsNil )
436
430
check .Assert (len (deletedDhcp .OpenApiOrgVdcNetworkDhcp .DhcpPools ), Equals , 0 )
437
431
check .Assert (len (deletedDhcp .OpenApiOrgVdcNetworkDhcp .DnsServers ), Equals , 0 )
432
+ }
433
+
434
+ // nsxtDhcpConfigNetworkMode checks DHCP functionality in NETWORK mode.
435
+ // It requires that Edge Cluster is set at VDC level therefore this function does it for the
436
+ // duration of this test and restores it back
437
+ func nsxtDhcpConfigNetworkMode (check * C , vcd * TestVCD , vdc * Vdc , orgNetId string ) {
438
+ // Only supported in 10.3.1+
439
+ if vdc .client .APIVCDMaxVersionIs ("< 36.1" ) {
440
+ return
441
+ }
442
+
443
+ // DHCP in NETWORK mode requires Edge Cluster to be set for VDC and cleaned up afterwards
444
+ edgeCluster , err := vdc .GetNsxtEdgeClusterByName (vcd .config .VCD .Nsxt .NsxtEdgeCluster )
445
+ check .Assert (err , IsNil )
446
+ vdcNetworkProfile := & types.VdcNetworkProfile {
447
+ ServicesEdgeCluster : & types.VdcNetworkProfileServicesEdgeCluster {
448
+ BackingID : edgeCluster .NsxtEdgeCluster .ID ,
449
+ },
450
+ }
451
+ _ , err = vdc .UpdateVdcNetworkProfile (vdcNetworkProfile )
452
+ check .Assert (err , IsNil )
453
+ defer func () {
454
+ err := vdc .DeleteVdcNetworkProfile ()
455
+ if err != nil {
456
+ check .Errorf ("error cleaning up VDC Network Profile: %s" , err )
457
+ }
458
+ }()
438
459
460
+ dhcpDefinition := & types.OpenApiOrgVdcNetworkDhcp {
461
+ Enabled : takeBoolPointer (true ),
462
+ Mode : "NETWORK" ,
463
+ IPAddress : "2.1.1.252" ,
464
+ DhcpPools : []types.OpenApiOrgVdcNetworkDhcpPools {
465
+ {
466
+ Enabled : takeBoolPointer (true ),
467
+ IPRange : types.OpenApiOrgVdcNetworkDhcpIpRange {
468
+ StartAddress : "2.1.1.200" ,
469
+ EndAddress : "2.1.1.201" ,
470
+ },
471
+ },
472
+ },
473
+ DnsServers : []string {
474
+ "8.8.8.8" ,
475
+ "8.8.4.4" ,
476
+ },
477
+ }
478
+
479
+ updatedDhcp , err := vdc .UpdateOpenApiOrgVdcNetworkDhcp (orgNetId , dhcpDefinition )
480
+ check .Assert (err , IsNil )
481
+
482
+ check .Assert (dhcpDefinition , DeepEquals , updatedDhcp .OpenApiOrgVdcNetworkDhcp )
483
+
484
+ err = vdc .DeleteOpenApiOrgVdcNetworkDhcp (orgNetId )
485
+ check .Assert (err , IsNil )
486
+
487
+ orgVdcNetwork , err := vcd .org .GetOpenApiOrgVdcNetworkById (orgNetId )
488
+ check .Assert (err , IsNil )
489
+ check .Assert (orgVdcNetwork , NotNil )
490
+
491
+ updatedDhcp2 , err := orgVdcNetwork .UpdateDhcp (dhcpDefinition )
492
+ check .Assert (err , IsNil )
493
+ check .Assert (updatedDhcp2 , NotNil )
494
+
495
+ check .Assert (dhcpDefinition , DeepEquals , updatedDhcp2 .OpenApiOrgVdcNetworkDhcp )
496
+
497
+ err = orgVdcNetwork .DeletNetworkDhcp ()
498
+ check .Assert (err , IsNil )
499
+
500
+ deletedDhcp , err := orgVdcNetwork .GetOpenApiOrgVdcNetworkDhcp ()
501
+ check .Assert (err , IsNil )
502
+ check .Assert (len (deletedDhcp .OpenApiOrgVdcNetworkDhcp .DhcpPools ), Equals , 0 )
503
+ check .Assert (len (deletedDhcp .OpenApiOrgVdcNetworkDhcp .DnsServers ), Equals , 0 )
439
504
}
440
505
441
- func runOpenApiOrgVdcNetworkWithVdcGroupTest (check * C , vcd * TestVCD , orgVdcNetworkConfig * types.OpenApiOrgVdcNetwork , expectNetworkType string , dhcpFunc dhcpConfigFunc ) {
506
+ func runOpenApiOrgVdcNetworkWithVdcGroupTest (check * C , vcd * TestVCD , orgVdcNetworkConfig * types.OpenApiOrgVdcNetwork , expectNetworkType string , dhcpFunc [] dhcpConfigFunc ) {
442
507
adminOrg , err := vcd .client .GetAdminOrgByName (vcd .config .VCD .Org )
443
508
check .Assert (err , IsNil )
444
509
@@ -525,8 +590,8 @@ func runOpenApiOrgVdcNetworkWithVdcGroupTest(check *C, vcd *TestVCD, orgVdcNetwo
525
590
check .Assert (updatedOrgVdcNet .OpenApiOrgVdcNetwork .Description , Equals , orgVdcNet .OpenApiOrgVdcNetwork .Description )
526
591
527
592
// Configure DHCP if specified
528
- if dhcpFunc != nil {
529
- dhcpFunc (check , vcd , vdc , updatedOrgVdcNet .OpenApiOrgVdcNetwork .ID )
593
+ for i := range dhcpFunc {
594
+ dhcpFunc [ i ] (check , vcd , vdc , updatedOrgVdcNet .OpenApiOrgVdcNetwork .ID )
530
595
}
531
596
// Delete
532
597
err = orgVdcNet .Delete ()
0 commit comments