forked from vmware/govmomi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.bats
executable file
·424 lines (300 loc) · 12.2 KB
/
cluster.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#!/usr/bin/env bats
load test_helper
@test "cluster.group" {
vcsim_env -cluster 2 -host 4 -vm 8
run govc cluster.group.ls -cluster DC0_C0
assert_success "" # no groups
run govc cluster.group.ls -cluster DC0_C0 -name my_vm_group
assert_failure # group does not exist
run govc cluster.group.create -cluster DC0_C0 -name my_vm_group -vm DC0_C0_H{0,1}
assert_failure # -vm or -host required
run govc cluster.group.create -cluster DC0_C0 -name my_vm_group -vm DC0_C0_H{0,1}
assert_failure # -vm with HostSystem type args
run govc cluster.group.create -cluster DC0_C0 -name my_vm_group -vm DC0_C0_RP0_VM{0,1}
assert_success
run govc cluster.group.ls -cluster DC0_C0
assert_success "my_vm_group"
run govc cluster.group.create -cluster DC0_C0 -name my_vm_group -vm DC0_C0_RP0_VM{0,1}
assert_failure # group exists
run govc cluster.group.ls -cluster DC0_C0 -name my_vm_group
assert_success "$(printf "%s\n" DC0_C0_RP0_VM{0,1})"
run govc cluster.group.change -cluster DC0_C0 -name my_vm_group DC0_C0_RP0_VM{0,1,2}
assert_success
run govc cluster.group.ls -cluster DC0_C0 -name my_vm_group
assert_success "$(printf "%s\n" DC0_C0_RP0_VM{0,1,2})"
run govc cluster.group.create -cluster DC0_C0 -name my_host_group -host DC0_C0_RP0_VM{0,1}
assert_failure # -host with VirtualMachine type args
run govc cluster.group.create -cluster DC0_C0 -name my_host_group -host DC0_C0_H{0,1}
assert_success
run govc cluster.group.ls -cluster DC0_C0 -name my_host_group
assert_success
run govc cluster.group.ls -cluster DC0_C0 -l
assert_success
[ ${#lines[@]} -eq 2 ]
run bash -c 'govc cluster.group.ls -cluster DC0_C0 -l | grep ClusterVmGroup'
assert_success
[ ${#lines[@]} -eq 1 ]
run bash -c 'govc cluster.group.ls -cluster DC0_C0 -l | grep ClusterHostGroup'
assert_success
[ ${#lines[@]} -eq 1 ]
run govc cluster.group.remove -cluster DC0_C0 -name my_vm_group
assert_success
run govc cluster.group.remove -cluster DC0_C0 -name my_vm_group
assert_failure # group does not exist
run govc cluster.group.ls -cluster DC0_C0
assert_success "my_host_group"
run govc cluster.group.ls -cluster DC0_C0 -l
assert_success
[ ${#lines[@]} -eq 1 ]
}
@test "cluster.rule" {
vcsim_env -cluster 2 -host 4 -vm 8
run govc cluster.rule.ls -cluster DC0_C0
assert_success "" # no rules
run govc object.collect -json /DC0/host/DC0_C0 configurationEx.rule
assert_success
run govc cluster.rule.ls -cluster DC0_C0 -name pod1
assert_failure # rule does not exist
run govc cluster.rule.create -cluster DC0_C0 -name pod1 -affinity DC0_C0_RP0_VM0
assert_failure # requires >= 2 VMs
run govc cluster.rule.create -cluster DC0_C0 -name pod1 -affinity DC0_C0_RP0_VM{0,1,2,3}
assert_success
run govc cluster.rule.ls -cluster DC0_C0
assert_success "pod1"
run govc cluster.rule.ls -cluster DC0_C0 -l=true
assert_success "pod1 (ClusterAffinityRuleSpec)"
run govc cluster.rule.ls -cluster DC0_C0 -name pod1
assert_success "$(printf "%s\n" DC0_C0_RP0_VM{0,1,2,3})"
run govc cluster.rule.ls -cluster DC0_C0 -name pod1 -l=true
assert_success "$(printf "%s (VM)\n" DC0_C0_RP0_VM{0,1,2,3})"
run govc cluster.rule.info -cluster DC0_C0
assert_success "$(cat <<_EOF_
Rule: pod1
Type: ClusterAffinityRuleSpec
VM: DC0_C0_RP0_VM0
VM: DC0_C0_RP0_VM1
VM: DC0_C0_RP0_VM2
VM: DC0_C0_RP0_VM3
_EOF_
)"
run govc cluster.rule.change -cluster DC0_C0 -name pod1 DC0_C0_RP0_VM{2,3,4}
assert_success
run govc cluster.rule.ls -cluster DC0_C0 -name pod1
assert_success "$(printf "%s\n" DC0_C0_RP0_VM{2,3,4})"
run govc object.collect -json /DC0/host/DC0_C0 configurationEx.rule
assert_success
run govc cluster.group.create -cluster DC0_C0 -name my_vms -vm DC0_C0_RP0_VM{0,1,2,3}
assert_success
run govc cluster.group.create -cluster DC0_C0 -name even_hosts -host DC0_C0_H{0,2}
assert_success
run govc cluster.group.create -cluster DC0_C0 -name odd_hosts -host DC0_C0_H{1,3}
assert_success
run govc cluster.rule.create -cluster DC0_C0 -name pod2 -enable -mandatory -vm-host -vm-group my_vms -host-affine-group even_hosts -host-anti-affine-group odd_hosts
assert_success
run govc cluster.rule.remove -cluster DC0_C0 -name pod1
assert_success
run govc cluster.rule.ls -cluster DC0_C0 -l
assert_success "pod2 (ClusterVmHostRuleInfo)"
run govc cluster.rule.ls -cluster DC0_C0 -name pod2
assert_success "$(printf "%s\n" {my_vms,even_hosts,odd_hosts})"
run govc cluster.rule.ls -cluster DC0_C0 -name pod2 -l
assert_success "$(printf "%s\n" {'my_vms (vmGroupName)','even_hosts (affineHostGroupName)','odd_hosts (antiAffineHostGroupName)'})"
run govc cluster.rule.remove -cluster DC0_C0 -name pod1 -depends
assert_failure # rule does not exist
run govc cluster.rule.create -cluster DC0_C0 -name my_deps -depends
assert_failure # requires 2 groups
run govc cluster.group.create -cluster DC0_C0 -name my_app -vm DC0_C0_RP0_VM{4,5}
assert_success
run govc cluster.group.create -cluster DC0_C0 -name my_db -vm DC0_C0_RP0_VM{6,7}
assert_success
run govc cluster.rule.create -cluster DC0_C0 -name my_deps -depends my_app my_db
assert_success
run govc cluster.rule.ls -cluster DC0_C0 -l
assert_success "$(printf "%s\n" {'pod2 (ClusterVmHostRuleInfo)','my_deps (ClusterDependencyRuleInfo)'})"
run govc cluster.rule.ls -cluster DC0_C0 -name my_deps
assert_success "$(printf "%s\n" {'my_app','my_db'})"
run govc cluster.rule.ls -cluster DC0_C0 -name my_deps -l
assert_success "$(printf "%s\n" {'my_app (VmGroup)','my_db (DependsOnVmGroup)'})"
run govc cluster.rule.info -cluster DC0_C0
assert_success "$(cat <<_EOF_
Rule: pod2
Type: ClusterVmHostRuleInfo
vmGroupName: my_vms
affineHostGroupName even_hosts
antiAffineHostGroupName odd_hosts
Rule: my_deps
Type: ClusterDependencyRuleInfo
VmGroup my_app
DependsOnVmGroup my_db
_EOF_
)"
}
@test "cluster.vm" {
vcsim_env -host 4 -vm 8
run govc cluster.override.info
assert_success "" # no overrides == empty output
run govc cluster.override.change
assert_failure # -vm required
run govc cluster.override.change -vm DC0_C0_RP0_VM0
assert_failure # no changes specified
# DRS override
query=".overrides[] | select(.name == \"DC0_C0_RP0_VM0\") | .drs.enabled"
run govc cluster.override.change -vm DC0_C0_RP0_VM0 -drs-enabled=false
assert_success
[ "$(govc cluster.override.info -json | jq "$query")" == "false" ]
run govc cluster.override.change -vm DC0_C0_RP0_VM0 -drs-enabled=true
assert_success
[ "$(govc cluster.override.info -json | jq "$query")" == "true" ]
run govc cluster.override.change -vm DC0_C0_RP0_VM0 -drs-mode=manual
assert_success
# DAS override
query=".overrides[] | select(.name == \"DC0_C0_RP0_VM0\") | .das.dasSettings.restartPriority"
[ "$(govc cluster.override.info -json | jq -r "$query")" != "high" ]
run govc cluster.override.change -vm DC0_C0_RP0_VM0 -ha-restart-priority high
assert_success
[ "$(govc cluster.override.info -json | jq -r "$query")" == "high" ]
# Orchestration override
query=".overrides[] | select(.name == \"DC0_C0_RP0_VM0\") | .orchestration.vmReadiness.postReadyDelay"
run govc cluster.override.change -vm DC0_C0_RP0_VM0 -ha-additional-delay 60
assert_success
[ "$(govc cluster.override.info -json | jq -r "$query")" == "60" ]
query=".overrides[] | select(.name == \"DC0_C0_RP0_VM0\") | .orchestration.vmReadiness.readyCondition"
run govc cluster.override.change -vm DC0_C0_RP0_VM0 -ha-ready-condition poweredOn
assert_success
[ "$(govc cluster.override.info -json | jq -r "$query")" == "poweredOn" ]
# remove overrides
run govc cluster.override.remove -vm DC0_C0_RP0_VM0
assert_success
run govc cluster.override.info
assert_success "" # no overrides == empty output
}
@test "cluster.add" {
vcsim_env
unset GOVC_HOST
ip=$(govc object.collect -o -json host/DC0_C0/DC0_C0_H0 | jq -r .config.network.vnic[].spec.ip.ipAddress)
assert_equal 127.0.0.1 "$ip"
govc cluster.add -cluster DC0_C0 -hostname 10.0.0.42 -username user -password pass
assert_success
ip=$(govc object.collect -o -json host/DC0_C0/10.0.0.42 | jq -r .config.network.vnic[].spec.ip.ipAddress)
assert_equal 10.0.0.42 "$ip"
govc host.info -json '*' | jq -r .hostSystems[].config.network.vnic[].spec.ip
name=$(govc host.info -json -host.ip 10.0.0.42 | jq -r .hostSystems[].name)
assert_equal 10.0.0.42 "$name"
}
@test "cluster.usage" {
vcsim_env -host 4
run govc cluster.usage enoent
assert_failure
run govc cluster.usage DC0_C0
assert_success
memory=$(govc cluster.usage -json DC0_C0 | jq -r .memory.summary.usage)
[ "$memory" = "34.3" ]
}
@test "cluster.stretch" {
vcsim_env -host 4
run govc cluster.stretch -witness DC0_H0 -first-fault-domain-hosts=DC0_C0_H1,DC0_C0_H2 -second-fault-domain-hosts DC0_C0_H2,DC0_C0_H3
assert_failure # no cluster specified
run govc cluster.stretch -witness DC0_H0 -first-fault-domain-hosts=DC0_C0_H1,DC0_C0_H2 DC0_C0
assert_failure # no second-fault-domain-hosts specified
run govc cluster.stretch -witness DC0_H0 -first-fault-domain-hosts=DC0_C0_H1,DC0_C0_H2 -second-fault-domain-hosts DC0_C0_H2,DC0_C0_H3 DC0_C0
assert_success
}
@test "cluster.module" {
vcsim_env
local output
run govc cluster.module.ls
assert_success # no tags defined yet
run govc cluster.module.ls -k=false
assert_failure
run govc cluster.module.ls -id enoent
assert_failure # specific module does not exist
run govc cluster.module.create -cluster DC0_C0
assert_success
id="$output"
run govc cluster.module.ls -id $id
assert_success
vm="/DC0/vm/DC0_C0_RP0_VM0"
run govc cluster.module.vm.add -id $id $vm
assert_success
count=$(govc cluster.module.ls -id $id | grep -c VirtualMachine)
[ "$count" = "1" ]
run govc cluster.module.vm.add -id $id $vm
assert_failure # already a member
run govc cluster.module.vm.rm -id $id $vm
assert_success
run govc cluster.module.ls -id $id
[ -z "$output" ]
run govc cluster.module.rm $id
assert_success
run govc cluster.module.ls -id $id
assert_failure
run govc cluster.module.rm "does_not_exist"
assert_failure
run govc cluster.module.rm --ignore-not-found "does_not_exist"
assert_success
run govc cluster.module.create -cluster DC0_C0
assert_success
id="$output"
run govc cluster.module.create -cluster DC0_C0
assert_success
id2="$output"
run govc cluster.module.rm --ignore-not-found "-" <<_EOF_
$id
does_not_exist
$id2
_EOF_
assert_success
}
@test "cluster.mv" {
vcsim_env -host 4 -cluster 2
# start with 4 hosts in each cluster
run govc find -type h /DC0/host/DC0_C0
assert_success
[ ${#lines[@]} -eq 4 ]
run govc find -type h /DC0/host/DC0_C1
assert_success
[ ${#lines[@]} -eq 4 ]
run govc cluster.mv -cluster DC0_C1 DC0_C0_H*
assert_failure
run govc host.maintenance.enter DC0_C0_H*
assert_success
# move 1 host from C0 to C1
run govc cluster.mv -cluster DC0_C1 DC0_C0_H2
assert_success
run govc find -type h /DC0/host/DC0_C0
assert_success
[ ${#lines[@]} -eq 3 ]
run govc find -type h /DC0/host/DC0_C1
assert_success
[ ${#lines[@]} -eq 5 ]
# move remaining 3 hosts from C0 to C1
run govc cluster.mv -cluster DC0_C1 DC0_C0_H{0,1,3}
assert_success
run govc find -type h /DC0/host/DC0_C0
assert_success
[ ${#lines[@]} -eq 0 ]
run govc find -type h /DC0/host/DC0_C1
assert_success
[ ${#lines[@]} -eq 8 ]
# move a standalone host into the cluster
run govc cluster.mv -cluster DC0_C1 DC0_H0
assert_success
run govc find -type h /DC0/host/DC0_C1
assert_success
[ ${#lines[@]} -eq 9 ]
run govc cluster.mv -cluster DC0_C1 DC0_C0_H*
assert_failure # hosts are already in the cluster
# TODO: vcsim's MoveIntoFolder_Task only supports moving from folders
# # move a cluster host to a standalone host
# run govc object.mv /DC0/host/DC0_C1/DC0_H0 /DC0/host
# assert_success
}
@test "cluster.change" {
vcsim_env
run govc cluster.change -drs-enabled -ha-enabled -ha-admission-control-enabled=false /DC0/host/DC0_C0
assert_success
config=$(govc object.collect -o -json /DC0/host/DC0_C0 | jq .configurationEx)
assert_equal true "$(jq -r .drsConfig.enabled <<<"$config")"
assert_equal true "$(jq -r .dasConfig.enabled <<<"$config")"
assert_equal false "$(jq -r .dasConfig.admissionControlEnabled <<<"$config")"
}