forked from vmware/go-vcloud-director
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminorg_test.go
263 lines (227 loc) · 11.4 KB
/
adminorg_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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// +build org functional ALL
/*
* Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
*/
package govcd
import (
"fmt"
. "gopkg.in/check.v1"
)
// Creates a Catalog and then verify that finds it
func (vcd *TestVCD) Test_FindAdminCatalogRecords(check *C) {
if vcd.skipAdminTests {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
}
adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
check.Assert(err, IsNil)
check.Assert(adminOrg, NotNil)
catalogName := "catalogForQuery"
adminCatalog, err := adminOrg.CreateCatalog(catalogName, "catalogForQueryDescription")
check.Assert(err, IsNil)
AddToCleanupList(catalogName, "catalog", vcd.config.VCD.Org, check.TestName())
check.Assert(adminCatalog.AdminCatalog.Name, Equals, catalogName)
// just imitate wait
err = adminOrg.Refresh()
check.Assert(err, IsNil)
findRecords, err := adminOrg.FindAdminCatalogRecords(catalogName)
check.Assert(err, IsNil)
check.Assert(findRecords, NotNil)
check.Assert(len(findRecords), Equals, 1)
check.Assert(findRecords[0].Name, Equals, catalogName)
check.Assert(findRecords[0].OrgName, Equals, adminOrg.AdminOrg.Name)
}
// Tests AdminOrg lease settings for vApp and vApp template
func (vcd *TestVCD) TestAdminOrg_SetLease(check *C) {
type leaseParams struct {
deploymentLeaseSeconds int
vappStorageLease int
vappTemplateStorageLease int
powerOffOnRuntimeLeaseExpiration bool
vappDeleteOnStorageLeaseExpiration bool
vappTemplateDeleteOnStorageLeaseExpiration bool
}
if vcd.skipAdminTests {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
}
adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
check.Assert(err, IsNil)
check.Assert(adminOrg, NotNil)
// Save vApp and vApp template lease parameters
var saveParams = leaseParams{
deploymentLeaseSeconds: *adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.DeploymentLeaseSeconds,
vappStorageLease: *adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.StorageLeaseSeconds,
vappTemplateStorageLease: *adminOrg.AdminOrg.OrgSettings.OrgVAppTemplateSettings.StorageLeaseSeconds,
powerOffOnRuntimeLeaseExpiration: *adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.PowerOffOnRuntimeLeaseExpiration,
vappDeleteOnStorageLeaseExpiration: *adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.DeleteOnStorageLeaseExpiration,
vappTemplateDeleteOnStorageLeaseExpiration: *adminOrg.AdminOrg.OrgSettings.OrgVAppTemplateSettings.DeleteOnStorageLeaseExpiration,
}
var leaseData = []leaseParams{
{
deploymentLeaseSeconds: 0, // never expires
vappStorageLease: 0, // never expires
vappTemplateStorageLease: 0, // never expires
powerOffOnRuntimeLeaseExpiration: true,
vappDeleteOnStorageLeaseExpiration: true,
vappTemplateDeleteOnStorageLeaseExpiration: true,
},
{
deploymentLeaseSeconds: 0, // never expires
vappStorageLease: 0, // never expires
vappTemplateStorageLease: 0, // never expires
powerOffOnRuntimeLeaseExpiration: false,
vappDeleteOnStorageLeaseExpiration: false,
vappTemplateDeleteOnStorageLeaseExpiration: false,
},
{
deploymentLeaseSeconds: 3600, // 1 hour
vappStorageLease: 3600 * 24, // 1 day
vappTemplateStorageLease: 3600 * 24 * 7, // 1 week
powerOffOnRuntimeLeaseExpiration: true,
vappDeleteOnStorageLeaseExpiration: true,
vappTemplateDeleteOnStorageLeaseExpiration: true,
},
{
deploymentLeaseSeconds: 3600, // 1 hour
vappStorageLease: 3600 * 24, // 1 day
vappTemplateStorageLease: 3600 * 24 * 7, // 1 week
powerOffOnRuntimeLeaseExpiration: false,
vappDeleteOnStorageLeaseExpiration: false,
vappTemplateDeleteOnStorageLeaseExpiration: false,
},
{
deploymentLeaseSeconds: 3600 * 24 * 30, // 1 month
vappStorageLease: 3600 * 24 * 90, // 1 quarter
vappTemplateStorageLease: 3600 * 24 * 365, // 1 year
powerOffOnRuntimeLeaseExpiration: true,
vappDeleteOnStorageLeaseExpiration: true,
vappTemplateDeleteOnStorageLeaseExpiration: true,
},
{
deploymentLeaseSeconds: 3600 * 24 * 30, // 1 month
vappStorageLease: 3600 * 24 * 90, // 1 quarter
vappTemplateStorageLease: 3600 * 24 * 365, // 1 year
powerOffOnRuntimeLeaseExpiration: false,
vappDeleteOnStorageLeaseExpiration: false,
vappTemplateDeleteOnStorageLeaseExpiration: false,
},
}
for _, info := range leaseData {
fmt.Printf("update lease params %v\n", info)
// Change the lease parameters for both vapp and vApp template
adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.StorageLeaseSeconds = &info.vappStorageLease
adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.DeploymentLeaseSeconds = &info.deploymentLeaseSeconds
adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.PowerOffOnRuntimeLeaseExpiration = &info.powerOffOnRuntimeLeaseExpiration
adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.DeleteOnStorageLeaseExpiration = &info.vappDeleteOnStorageLeaseExpiration
adminOrg.AdminOrg.OrgSettings.OrgVAppTemplateSettings.StorageLeaseSeconds = &info.vappTemplateStorageLease
adminOrg.AdminOrg.OrgSettings.OrgVAppTemplateSettings.DeleteOnStorageLeaseExpiration = &info.vappTemplateDeleteOnStorageLeaseExpiration
task, err := adminOrg.Update()
check.Assert(err, IsNil)
check.Assert(task, NotNil)
err = task.WaitTaskCompletion()
check.Assert(err, IsNil)
// Check the results
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.DeploymentLeaseSeconds, Equals, info.deploymentLeaseSeconds)
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.StorageLeaseSeconds, Equals, info.vappStorageLease)
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.PowerOffOnRuntimeLeaseExpiration, Equals, info.powerOffOnRuntimeLeaseExpiration)
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.DeleteOnStorageLeaseExpiration, Equals, info.vappDeleteOnStorageLeaseExpiration)
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppTemplateSettings.DeleteOnStorageLeaseExpiration, Equals, info.vappTemplateDeleteOnStorageLeaseExpiration)
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppTemplateSettings.StorageLeaseSeconds, Equals, info.vappTemplateStorageLease)
}
// Restore the initial parameters
adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.StorageLeaseSeconds = &saveParams.vappStorageLease
adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.DeploymentLeaseSeconds = &saveParams.deploymentLeaseSeconds
adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.PowerOffOnRuntimeLeaseExpiration = &saveParams.powerOffOnRuntimeLeaseExpiration
adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.DeleteOnStorageLeaseExpiration = &saveParams.vappDeleteOnStorageLeaseExpiration
adminOrg.AdminOrg.OrgSettings.OrgVAppTemplateSettings.StorageLeaseSeconds = &saveParams.vappTemplateStorageLease
adminOrg.AdminOrg.OrgSettings.OrgVAppTemplateSettings.DeleteOnStorageLeaseExpiration = &saveParams.vappTemplateDeleteOnStorageLeaseExpiration
fmt.Printf("restore lease params %v\n", saveParams)
task, err := adminOrg.Update()
check.Assert(err, IsNil)
check.Assert(task, NotNil)
err = task.WaitTaskCompletion()
check.Assert(err, IsNil)
// Check that the initial parameters were restored
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.DeploymentLeaseSeconds, Equals, saveParams.deploymentLeaseSeconds)
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.StorageLeaseSeconds, Equals, saveParams.vappStorageLease)
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.PowerOffOnRuntimeLeaseExpiration, Equals, saveParams.powerOffOnRuntimeLeaseExpiration)
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppLeaseSettings.DeleteOnStorageLeaseExpiration, Equals, saveParams.vappDeleteOnStorageLeaseExpiration)
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppTemplateSettings.DeleteOnStorageLeaseExpiration, Equals, saveParams.vappTemplateDeleteOnStorageLeaseExpiration)
check.Assert(*adminOrg.AdminOrg.OrgSettings.OrgVAppTemplateSettings.StorageLeaseSeconds, Equals, saveParams.vappTemplateStorageLease)
}
func (vcd *TestVCD) TestOrg_AdminOrg_QueryCatalogList(check *C) {
if vcd.config.VCD.Org == "" {
check.Skip("no org name provided. test skipped")
}
if vcd.config.VCD.Catalog.Name == "" {
check.Skip("no catalog name provided. test skipped")
}
adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
check.Assert(err, IsNil)
check.Assert(adminOrg, NotNil)
org, err := vcd.client.GetOrgByName(vcd.config.VCD.Org)
check.Assert(err, IsNil)
check.Assert(org, NotNil)
// gets the catalog list as an adminOrg
catalogsInAdminOrg, err := adminOrg.QueryCatalogList()
check.Assert(err, IsNil)
// gets the catalog list as an Org
catalogsInOrg, err := org.QueryCatalogList()
check.Assert(err, IsNil)
foundInOrg := false
// Searches the org catalogs list for a known catalog
for _, catOrg := range catalogsInOrg {
if catOrg.Name == vcd.config.VCD.Catalog.Name {
foundInOrg = true
}
}
check.Assert(foundInOrg, Equals, true)
foundInAdminOrg := false
// Searches the admin org catalogs list for a known catalog
for _, catOrg := range catalogsInAdminOrg {
if catOrg.Name == vcd.config.VCD.Catalog.Name {
foundInAdminOrg = true
}
}
check.Assert(foundInAdminOrg, Equals, true)
// both lists should have the same number of items
check.Assert(len(catalogsInAdminOrg), Equals, len(catalogsInOrg))
// Check that every item in one list is also in the other list
for _, catA := range catalogsInAdminOrg {
foundInBoth := false
for _, catO := range catalogsInOrg {
if catA.Name == catO.Name {
foundInBoth = true
}
}
check.Assert(foundInBoth, Equals, true)
}
}
// Test_GetAllVDCs checks that adminOrg.GetAllVDCs returns at least one VDC
func (vcd *TestVCD) Test_AdminOrgGetAllVDCs(check *C) {
if vcd.skipAdminTests {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
}
adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
check.Assert(err, IsNil)
check.Assert(adminOrg, NotNil)
vdcs, err := adminOrg.GetAllVDCs(true)
check.Assert(err, IsNil)
check.Assert(len(vdcs) > 0, Equals, true)
// If NSX-T VDC is configured we expect to see at least 2 VDCs (NSX-V and NSX-T)
if vcd.config.VCD.Nsxt.Vdc != "" {
check.Assert(len(vdcs) >= 2, Equals, true)
}
}
// Test_GetAllStorageProfileReferences checks that adminOrg.GetAllStorageProfileReferences returns at least one storage
// profile reference
func (vcd *TestVCD) Test_GetAllStorageProfileReferences(check *C) {
if vcd.skipAdminTests {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
}
adminOrg, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
check.Assert(err, IsNil)
check.Assert(adminOrg, NotNil)
storageProfileReferences, err := adminOrg.GetAllStorageProfileReferences(true)
check.Assert(err, IsNil)
check.Assert(len(storageProfileReferences) > 0, Equals, true)
}