-
Notifications
You must be signed in to change notification settings - Fork 911
/
namespace.bats
executable file
·337 lines (249 loc) · 10.1 KB
/
namespace.bats
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/usr/bin/env bats
load test_helper
@test "namespace.cluster.ls" {
vcsim_env
run govc namespace.cluster.ls
assert_success ""
run govc namespace.cluster.ls -json
assert_success "[]"
run govc cluster.create WCP-cluster
assert_success
run govc namespace.cluster.ls
assert_success /DC0/host/WCP-cluster
run govc namespace.cluster.ls -l
assert_success
assert_matches RUNNING
assert_matches READY
id=$(govc namespace.cluster.ls -json | jq -r .[].cluster)
run govc object.collect -s "ClusterComputeResource:$id" name
assert_success WCP-cluster
}
@test "namespace.cluster.enable" {
vcsim_env
# need to set up some dependencies
govc cluster.create WCP-Cluster
assert_success
govc dvs.create "DVPG-Management Network"
assert_success
govc namespace.cluster.enable \
--service-cidr 10.96.0.0/23 \
--pod-cidrs 10.244.0.0/20 \
--cluster "WCP-Cluster" \
--control-plane-dns 8.8.8.8 \
--worker-dns 8.8.8.8 \
--control-plane-dns-search-domains example.com \
--control-plane-dns-names wcp.example.com \
--control-plane-ntp-servers pool.ntp.org \
--network-provider "NSXT_CONTAINER_PLUGIN" \
--workload-network.egress-cidrs 10.0.0.128/26 \
--workload-network.ingress-cidrs "10.0.0.64/26" \
--workload-network.switch VDS \
--workload-network.edge-cluster Edge-Cluster-1 \
--size TINY \
--mgmt-network.mode STATICRANGE \
--mgmt-network.network "DVPG-Management Network" \
--mgmt-network.gateway 10.0.0.1 \
--mgmt-network.starting-address 10.0.0.45 \
--mgmt-network.subnet-mask 255.255.255.0 \
--ephemeral-storage-policy "vSAN Default Storage Policy" \
--control-plane-storage-policy "vSAN Default Storage Policy" \
--image-storage-policy "vSAN Default Storage Policy"
assert_success
}
@test "namespace.cluster.disable" {
vcsim_env
govc cluster.create WCP-Cluster
assert_success
govc namespace.cluster.disable --cluster WCP-Cluster
assert_success
}
@test "namespace.logs" {
vcsim_env
id=$(govc find -i -maxdepth 0 host/DC0_C0 | awk -F: '{print $2}')
run govc namespace.logs.download -cluster DC0_C0
assert_success
rm "wcp-support-bundle-$id-"*.tar
govc namespace.logs.download -cluster DC0_C0 - | tar -xvOf-
}
@test "namespace.service.ls" {
vcsim_env
run govc namespace.service.ls
assert_success
assert_matches service1
assert_matches service2
run govc namespace.service.ls -l
assert_success
assert_matches ACTIVATED
assert_matches mock-service-1
}
@test "namespace.service.info" {
vcsim_env
run govc namespace.service.info service1
assert_success
assert_matches mock-service-1
assert_matches ACTIVATED
assert_matches "Description of service1"
run govc namespace.service.info -json service2
assert_matches DE-ACTIVATED
}
@test "namespace.create" {
vcsim_env
run govc namespace.create -cluster DC0_C0 test-namespace-1
assert_success
ns=$(govc namespace.info -json test-namespace-1 | jq)
id=$(govc find -i -maxdepth 0 /DC0/host/DC0_C0 | cut -d: -f2)
assert_equal "$id" $(echo $ns | jq -r '."cluster"')
assert_equal "0" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length)
run govc namespace.create -cluster DC0_C0 -library=lib1 -library=lib2 test-namespace-2
assert_success
ns=$(govc namespace.info -json test-namespace-2 | jq)
assert_equal "2" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length)
run govc namespace.create -cluster DC0_C0 -storage MyStoragePolicy test-namespace-2
assert_failure # storage policy does not exist
run govc storage.policy.create -category my_cat -tag my_tag MyStoragePolicy
assert_success
run govc namespace.create -cluster DC0_C0 -storage MyStoragePolicy test-namespace-2
assert_success
}
@test "namespace.update" {
vcsim_env
govc namespace.create -cluster DC0_C0 test-namespace-1
run govc namespace.update -library=lib1 -library=lib2 -vmclass=class1 test-namespace-1
assert_success
ns=$(govc namespace.info -json test-namespace-1 | jq)
assert_equal "2" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length)
assert_matches "lib[0-9]+" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"[0]')
assert_matches "lib[0-9]+" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"[1]')
assert_equal "1" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"' | jq length)
assert_equal "class1" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"[0]')
run govc namespace.update -library=lib3 test-namespace-1
assert_success
ns=$(govc namespace.info -json test-namespace-1 | jq)
assert_equal "1" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length)
assert_equal "lib3" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"[0]')
assert_equal "0" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"' | jq length)
run govc namespace.update -vmclass=class3 test-namespace-1
assert_success
ns=$(govc namespace.info -json test-namespace-1 | jq)
assert_equal "0" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length)
assert_equal "1" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"' | jq length)
assert_equal "class3" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"[0]')
run govc namespace.update -library=lib4 -vmclass=class4 test-namespace-1
assert_success
ns=$(govc namespace.info -json test-namespace-1 | jq)
assert_equal "1" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"' | jq length)
assert_equal "lib4" $(echo $ns | jq -r '."vm_service_spec"."content_libraries"[0]')
assert_equal "1" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"' | jq length)
assert_equal "class4" $(echo $ns | jq -r '."vm_service_spec"."vm_classes"[0]')
run govc namespace.update -library=lib1 -library=lib2 -vmclass=class1 non-existing-namespace
assert_failure
assert_matches "404 Not Found"
}
@test "namespace.info" {
vcsim_env
govc namespace.create -cluster DC0_C0 test-namespace-1
ns=$(govc namespace.info -json test-namespace-1 | jq)
id=$(govc find -i -maxdepth 0 /DC0/host/DC0_C0 | cut -d: -f2)
assert_equal "$id" $(echo $ns | jq -r '."cluster"')
run govc namespace.info test-namespace-1
assert_success
run govc namespace.info non-existing-namespace
assert_failure
assert_matches "404 Not Found"
}
@test "namespace.ls" {
vcsim_env
run govc namespace.ls
assert_success ""
ls=$(govc namespace.ls -json)
assert_equal "0" $(echo $ls | jq length)
govc namespace.create -cluster DC0_C0 test-namespace-1
ls=$(govc namespace.ls -json)
assert_equal "1" $(echo $ls | jq length)
assert_equal "test-namespace-1" $(echo $ls | jq -r '.[0]."namespace"')
run govc namespace.ls
assert_success test-namespace-1
govc namespace.create -cluster DC0_C0 test-namespace-2
ls=$(govc namespace.ls -json)
assert_equal "2" $(echo $ls | jq length)
id=$(govc find -i -maxdepth 0 /DC0/host/DC0_C0 | cut -d: -f2)
assert_equal "$id" $(echo $ls | jq -r '.[0]."cluster"')
assert_matches "test-namespace-[0-9]+" $(echo $ls | jq -r '.[0]."namespace"')
assert_equal "$id" $(echo $ls | jq -r '.[1]."cluster"')
assert_matches "test-namespace-[0-9]+" $(echo $ls | jq -r '.[1]."namespace"')
}
@test "namespace.rm" {
vcsim_env
run govc namespace.rm non-existing-namespace
assert_failure
assert_matches "404 Not Found"
run govc namespace.create -cluster DC0_C0 test-namespace-1
assert_success
run govc namespace.rm test-namespace-1
assert_success
}
@test "namespace.vmclass.create" {
vcsim_env
run govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-1
assert_success
c=$(govc namespace.vmclass.info -json test-class-1 | jq)
assert_equal "16" $(echo $c | jq -r '."cpu_count"')
assert_equal "16000" $(echo $c | jq -r '."memory_mb"')
}
@test "namespace.vmclass.update" {
vcsim_env
govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-1
govc namespace.vmclass.update -cpus=24 -memory=24000 test-class-1
c=$(govc namespace.vmclass.info -json test-class-1 | jq)
assert_equal "24" $(echo $c | jq -r '."cpu_count"')
assert_equal "24000" $(echo $c | jq -r '."memory_mb"')
}
@test "namespace.vmclass.info" {
vcsim_env
run govc namespace.vmclass.info
assert_failure
run govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-1
assert_success
run govc namespace.vmclass.info test-class-1
assert_success
c=$(govc namespace.vmclass.info -json test-class-1 | jq)
assert_equal "16" $(echo $c | jq -r '."cpu_count"')
assert_equal "16000" $(echo $c | jq -r '."memory_mb"')
run govc namespace.vmclass.info non-existing-class
assert_failure
assert_matches "404 Not Found"
}
@test "namespace.vmclass.ls" {
vcsim_env
run govc namespace.vmclass.ls
assert_success ""
ls=$(govc namespace.vmclass.ls -json)
assert_equal "0" $(echo $ls | jq length)
govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-1
ls=$(govc namespace.vmclass.ls -json)
assert_equal "1" $(echo $ls | jq length)
govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-2
ls=$(govc namespace.vmclass.ls -json)
assert_equal "2" $(echo $ls | jq length)
}
@test "namespace.vmclass.rm" {
vcsim_env
run govc namespace.vmclass.rm non-existing-class
assert_failure
assert_matches "404 Not Found"
govc namespace.vmclass.create -cpus=16 -memory=16000 test-class-1
run govc namespace.vmclass.rm test-class-1
assert_success
}
@test "namespace.registervm" {
vcsim_env
vm=DC0_C0_RP0_VM0
run govc namespace.create -cluster DC0_C0 test-namespace-1
assert_success
run govc namespace.registervm -vm $vm test-namespace-1
assert_failure # missing resource.yaml
run govc vm.change -vm $vm -e vmservice.virtualmachine.resource.yaml=b64
assert_success
run govc namespace.registervm -vm $vm test-namespace-1
assert_success
}