forked from vmware/go-vcloud-director
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminvdc_nsxt_test.go
137 lines (112 loc) · 4.15 KB
/
adminvdc_nsxt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// +build org functional nsxt ALL
/*
* Copyright 2020 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
*/
package govcd
// This file tests out NSX-T related Org VDC capabilities
import (
"fmt"
"github.com/vmware/go-vcloud-director/v2/types/v56"
. "gopkg.in/check.v1"
)
func (vcd *TestVCD) Test_CreateNsxtOrgVdc(check *C) {
if vcd.skipAdminTests {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
}
skipNoNsxtConfiguration(vcd, check)
adminOrg, err := vcd.client.GetAdminOrgByName(vcd.org.Org.Name)
check.Assert(err, IsNil)
check.Assert(adminOrg, NotNil)
pVdcs, err := QueryProviderVdcByName(vcd.client, vcd.config.VCD.NsxtProviderVdc.Name)
check.Assert(err, IsNil)
if len(pVdcs) == 0 {
check.Skip(fmt.Sprintf("No NSX-T Provider VDC found with name '%s'", vcd.config.VCD.NsxtProviderVdc.Name))
}
providerVdcHref := pVdcs[0].HREF
pvdcStorageProfile, err := vcd.client.QueryProviderVdcStorageProfileByName(vcd.config.VCD.NsxtProviderVdc.StorageProfile, providerVdcHref)
check.Assert(err, IsNil)
providerVdcStorageProfileHref := pvdcStorageProfile.HREF
networkPools, err := QueryNetworkPoolByName(vcd.client, vcd.config.VCD.NsxtProviderVdc.NetworkPool)
check.Assert(err, IsNil)
if len(networkPools) == 0 {
check.Skip(fmt.Sprintf("No network pool found with name '%s'", vcd.config.VCD.NsxtProviderVdc.NetworkPool))
}
networkPoolHref := networkPools[0].HREF
allocationModels := []string{"AllocationVApp", "AllocationPool", "ReservationPool", "Flex"}
trueValue := true
for i, allocationModel := range allocationModels {
vdcConfiguration := &types.VdcConfiguration{
Name: fmt.Sprintf("%s%d", "TestNsxtVdc", i),
Xmlns: types.XMLNamespaceVCloud,
AllocationModel: allocationModel,
ComputeCapacity: []*types.ComputeCapacity{
&types.ComputeCapacity{
CPU: &types.CapacityWithUsage{
Units: "MHz",
Allocated: 1024,
Limit: 1024,
},
Memory: &types.CapacityWithUsage{
Allocated: 1024,
Limit: 1024,
},
},
},
VdcStorageProfile: []*types.VdcStorageProfileConfiguration{&types.VdcStorageProfileConfiguration{
Enabled: true,
Units: "MB",
Limit: 1024,
Default: true,
ProviderVdcStorageProfile: &types.Reference{
HREF: providerVdcStorageProfileHref,
},
},
},
NetworkPoolReference: &types.Reference{
HREF: networkPoolHref,
},
ProviderVdcReference: &types.Reference{
HREF: providerVdcHref,
},
IsEnabled: true,
IsThinProvision: true,
UsesFastProvisioning: true,
}
if allocationModel == "Flex" {
vdcConfiguration.IsElastic = &trueValue
vdcConfiguration.IncludeMemoryOverhead = &trueValue
}
vdc, _ := adminOrg.GetVDCByName(vdcConfiguration.Name, false)
if vdc != nil {
err = vdc.DeleteWait(true, true)
check.Assert(err, IsNil)
}
// expected to fail due to missing value
task, err := adminOrg.CreateOrgVdcAsync(vdcConfiguration)
check.Assert(err, Not(IsNil))
check.Assert(task, Equals, Task{})
// checks function validation
check.Assert(err.Error(), Equals, "VdcConfiguration missing required field: ComputeCapacity[0].Memory.Units")
vdcConfiguration.ComputeCapacity[0].Memory.Units = "MB"
vdc, err = adminOrg.CreateOrgVdc(vdcConfiguration)
check.Assert(vdc, NotNil)
check.Assert(err, IsNil)
AddToCleanupList(vdcConfiguration.Name, "vdc", vcd.org.Org.Name, check.TestName())
adminVdc, err := adminOrg.GetAdminVDCByName(vdcConfiguration.Name, true)
check.Assert(err, IsNil)
check.Assert(vdc, NotNil)
check.Assert(vdc.Vdc.Name, Equals, vdcConfiguration.Name)
check.Assert(vdc.Vdc.IsEnabled, Equals, vdcConfiguration.IsEnabled)
check.Assert(vdc.Vdc.AllocationModel, Equals, vdcConfiguration.AllocationModel)
// Test update
adminVdc.AdminVdc.Description = "updated-description" + check.TestName()
updatedAdminVdc, err := adminVdc.Update()
check.Assert(err, IsNil)
check.Assert(updatedAdminVdc.AdminVdc, Equals, adminVdc.AdminVdc)
err = vdc.DeleteWait(true, true)
check.Assert(err, IsNil)
vdc, err = adminOrg.GetVDCByName(vdcConfiguration.Name, true)
check.Assert(err, NotNil)
check.Assert(vdc, IsNil)
}
}