github.com/vmware/govmomi@v0.43.0/govc/test/cluster.bats (about) 1 #!/usr/bin/env bats 2 3 load test_helper 4 5 @test "cluster.group" { 6 vcsim_env -cluster 2 -host 4 -vm 8 7 8 run govc cluster.group.ls -cluster DC0_C0 9 assert_success "" # no groups 10 11 run govc cluster.group.ls -cluster DC0_C0 -name my_vm_group 12 assert_failure # group does not exist 13 14 run govc cluster.group.create -cluster DC0_C0 -name my_vm_group -vm DC0_C0_H{0,1} 15 assert_failure # -vm or -host required 16 17 run govc cluster.group.create -cluster DC0_C0 -name my_vm_group -vm DC0_C0_H{0,1} 18 assert_failure # -vm with HostSystem type args 19 20 run govc cluster.group.create -cluster DC0_C0 -name my_vm_group -vm DC0_C0_RP0_VM{0,1} 21 assert_success 22 23 run govc cluster.group.ls -cluster DC0_C0 24 assert_success "my_vm_group" 25 26 run govc cluster.group.create -cluster DC0_C0 -name my_vm_group -vm DC0_C0_RP0_VM{0,1} 27 assert_failure # group exists 28 29 run govc cluster.group.ls -cluster DC0_C0 -name my_vm_group 30 assert_success "$(printf "%s\n" DC0_C0_RP0_VM{0,1})" 31 32 run govc cluster.group.change -cluster DC0_C0 -name my_vm_group DC0_C0_RP0_VM{0,1,2} 33 assert_success 34 35 run govc cluster.group.ls -cluster DC0_C0 -name my_vm_group 36 assert_success "$(printf "%s\n" DC0_C0_RP0_VM{0,1,2})" 37 38 run govc cluster.group.create -cluster DC0_C0 -name my_host_group -host DC0_C0_RP0_VM{0,1} 39 assert_failure # -host with VirtualMachine type args 40 41 run govc cluster.group.create -cluster DC0_C0 -name my_host_group -host DC0_C0_H{0,1} 42 assert_success 43 44 run govc cluster.group.ls -cluster DC0_C0 -name my_host_group 45 assert_success 46 47 run govc cluster.group.ls -cluster DC0_C0 -l 48 assert_success 49 [ ${#lines[@]} -eq 2 ] 50 51 run bash -c 'govc cluster.group.ls -cluster DC0_C0 -l | grep ClusterVmGroup' 52 assert_success 53 [ ${#lines[@]} -eq 1 ] 54 55 run bash -c 'govc cluster.group.ls -cluster DC0_C0 -l | grep ClusterHostGroup' 56 assert_success 57 [ ${#lines[@]} -eq 1 ] 58 59 run govc cluster.group.remove -cluster DC0_C0 -name my_vm_group 60 assert_success 61 62 run govc cluster.group.remove -cluster DC0_C0 -name my_vm_group 63 assert_failure # group does not exist 64 65 run govc cluster.group.ls -cluster DC0_C0 66 assert_success "my_host_group" 67 68 run govc cluster.group.ls -cluster DC0_C0 -l 69 assert_success 70 [ ${#lines[@]} -eq 1 ] 71 } 72 73 @test "cluster.rule" { 74 vcsim_env -cluster 2 -host 4 -vm 8 75 76 run govc cluster.rule.ls -cluster DC0_C0 77 assert_success "" # no rules 78 79 run govc object.collect -json /DC0/host/DC0_C0 configurationEx.rule 80 assert_success 81 82 run govc cluster.rule.ls -cluster DC0_C0 -name pod1 83 assert_failure # rule does not exist 84 85 run govc cluster.rule.create -cluster DC0_C0 -name pod1 -affinity DC0_C0_RP0_VM0 86 assert_failure # requires >= 2 VMs 87 88 run govc cluster.rule.create -cluster DC0_C0 -name pod1 -affinity DC0_C0_RP0_VM{0,1,2,3} 89 assert_success 90 91 run govc cluster.rule.ls -cluster DC0_C0 92 assert_success "pod1" 93 94 run govc cluster.rule.ls -cluster DC0_C0 -l=true 95 assert_success "pod1 (ClusterAffinityRuleSpec)" 96 97 run govc cluster.rule.ls -cluster DC0_C0 -name pod1 98 assert_success "$(printf "%s\n" DC0_C0_RP0_VM{0,1,2,3})" 99 100 run govc cluster.rule.ls -cluster DC0_C0 -name pod1 -l=true 101 assert_success "$(printf "%s (VM)\n" DC0_C0_RP0_VM{0,1,2,3})" 102 103 run govc cluster.rule.info -cluster DC0_C0 104 assert_success "$(cat <<_EOF_ 105 Rule: pod1 106 Type: ClusterAffinityRuleSpec 107 VM: DC0_C0_RP0_VM0 108 VM: DC0_C0_RP0_VM1 109 VM: DC0_C0_RP0_VM2 110 VM: DC0_C0_RP0_VM3 111 _EOF_ 112 )" 113 114 run govc cluster.rule.change -cluster DC0_C0 -name pod1 DC0_C0_RP0_VM{2,3,4} 115 assert_success 116 117 run govc cluster.rule.ls -cluster DC0_C0 -name pod1 118 assert_success "$(printf "%s\n" DC0_C0_RP0_VM{2,3,4})" 119 120 run govc object.collect -json /DC0/host/DC0_C0 configurationEx.rule 121 assert_success 122 123 run govc cluster.group.create -cluster DC0_C0 -name my_vms -vm DC0_C0_RP0_VM{0,1,2,3} 124 assert_success 125 126 run govc cluster.group.create -cluster DC0_C0 -name even_hosts -host DC0_C0_H{0,2} 127 assert_success 128 129 run govc cluster.group.create -cluster DC0_C0 -name odd_hosts -host DC0_C0_H{1,3} 130 assert_success 131 132 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 133 assert_success 134 135 run govc cluster.rule.remove -cluster DC0_C0 -name pod1 136 assert_success 137 138 run govc cluster.rule.ls -cluster DC0_C0 -l 139 assert_success "pod2 (ClusterVmHostRuleInfo)" 140 141 run govc cluster.rule.ls -cluster DC0_C0 -name pod2 142 assert_success "$(printf "%s\n" {my_vms,even_hosts,odd_hosts})" 143 144 run govc cluster.rule.ls -cluster DC0_C0 -name pod2 -l 145 assert_success "$(printf "%s\n" {'my_vms (vmGroupName)','even_hosts (affineHostGroupName)','odd_hosts (antiAffineHostGroupName)'})" 146 147 run govc cluster.rule.remove -cluster DC0_C0 -name pod1 -depends 148 assert_failure # rule does not exist 149 150 run govc cluster.rule.create -cluster DC0_C0 -name my_deps -depends 151 assert_failure # requires 2 groups 152 153 run govc cluster.group.create -cluster DC0_C0 -name my_app -vm DC0_C0_RP0_VM{4,5} 154 assert_success 155 156 run govc cluster.group.create -cluster DC0_C0 -name my_db -vm DC0_C0_RP0_VM{6,7} 157 assert_success 158 159 run govc cluster.rule.create -cluster DC0_C0 -name my_deps -depends my_app my_db 160 assert_success 161 162 run govc cluster.rule.ls -cluster DC0_C0 -l 163 assert_success "$(printf "%s\n" {'pod2 (ClusterVmHostRuleInfo)','my_deps (ClusterDependencyRuleInfo)'})" 164 165 run govc cluster.rule.ls -cluster DC0_C0 -name my_deps 166 assert_success "$(printf "%s\n" {'my_app','my_db'})" 167 168 run govc cluster.rule.ls -cluster DC0_C0 -name my_deps -l 169 assert_success "$(printf "%s\n" {'my_app (VmGroup)','my_db (DependsOnVmGroup)'})" 170 171 run govc cluster.rule.info -cluster DC0_C0 172 assert_success "$(cat <<_EOF_ 173 Rule: pod2 174 Type: ClusterVmHostRuleInfo 175 vmGroupName: my_vms 176 affineHostGroupName even_hosts 177 antiAffineHostGroupName odd_hosts 178 Rule: my_deps 179 Type: ClusterDependencyRuleInfo 180 VmGroup my_app 181 DependsOnVmGroup my_db 182 _EOF_ 183 )" 184 185 } 186 187 @test "cluster.vm" { 188 vcsim_env -host 4 -vm 8 189 190 run govc cluster.override.info 191 assert_success "" # no overrides == empty output 192 193 run govc cluster.override.change 194 assert_failure # -vm required 195 196 run govc cluster.override.change -vm DC0_C0_RP0_VM0 197 assert_failure # no changes specified 198 199 # DRS override 200 query=".overrides[] | select(.name == \"DC0_C0_RP0_VM0\") | .drs.enabled" 201 202 run govc cluster.override.change -vm DC0_C0_RP0_VM0 -drs-enabled=false 203 assert_success 204 [ "$(govc cluster.override.info -json | jq "$query")" == "false" ] 205 206 run govc cluster.override.change -vm DC0_C0_RP0_VM0 -drs-enabled=true 207 assert_success 208 [ "$(govc cluster.override.info -json | jq "$query")" == "true" ] 209 210 run govc cluster.override.change -vm DC0_C0_RP0_VM0 -drs-mode=manual 211 assert_success 212 213 # DAS override 214 query=".overrides[] | select(.name == \"DC0_C0_RP0_VM0\") | .das.dasSettings.restartPriority" 215 216 [ "$(govc cluster.override.info -json | jq -r "$query")" != "high" ] 217 218 run govc cluster.override.change -vm DC0_C0_RP0_VM0 -ha-restart-priority high 219 assert_success 220 [ "$(govc cluster.override.info -json | jq -r "$query")" == "high" ] 221 222 # Orchestration override 223 query=".overrides[] | select(.name == \"DC0_C0_RP0_VM0\") | .orchestration.vmReadiness.postReadyDelay" 224 225 run govc cluster.override.change -vm DC0_C0_RP0_VM0 -ha-additional-delay 60 226 assert_success 227 [ "$(govc cluster.override.info -json | jq -r "$query")" == "60" ] 228 229 query=".overrides[] | select(.name == \"DC0_C0_RP0_VM0\") | .orchestration.vmReadiness.readyCondition" 230 231 run govc cluster.override.change -vm DC0_C0_RP0_VM0 -ha-ready-condition poweredOn 232 assert_success 233 [ "$(govc cluster.override.info -json | jq -r "$query")" == "poweredOn" ] 234 235 # remove overrides 236 run govc cluster.override.remove -vm DC0_C0_RP0_VM0 237 assert_success 238 run govc cluster.override.info 239 assert_success "" # no overrides == empty output 240 } 241 242 @test "cluster.add" { 243 vcsim_env 244 unset GOVC_HOST 245 246 ip=$(govc object.collect -o -json host/DC0_C0/DC0_C0_H0 | jq -r .config.network.vnic[].spec.ip.ipAddress) 247 assert_equal 127.0.0.1 "$ip" 248 249 govc cluster.add -cluster DC0_C0 -hostname 10.0.0.42 -username user -password pass 250 assert_success 251 252 ip=$(govc object.collect -o -json host/DC0_C0/10.0.0.42 | jq -r .config.network.vnic[].spec.ip.ipAddress) 253 254 assert_equal 10.0.0.42 "$ip" 255 govc host.info -json '*' | jq -r .hostSystems[].config.network.vnic[].spec.ip 256 name=$(govc host.info -json -host.ip 10.0.0.42 | jq -r .hostSystems[].name) 257 assert_equal 10.0.0.42 "$name" 258 } 259 260 @test "cluster.usage" { 261 vcsim_env -host 4 262 263 run govc cluster.usage enoent 264 assert_failure 265 266 run govc cluster.usage DC0_C0 267 assert_success 268 269 memory=$(govc cluster.usage -json DC0_C0 | jq -r .memory.summary.usage) 270 [ "$memory" = "34.3" ] 271 } 272 273 @test "cluster.stretch" { 274 vcsim_env -host 4 275 276 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 277 assert_failure # no cluster specified 278 279 run govc cluster.stretch -witness DC0_H0 -first-fault-domain-hosts=DC0_C0_H1,DC0_C0_H2 DC0_C0 280 assert_failure # no second-fault-domain-hosts specified 281 282 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 283 assert_success 284 } 285 286 @test "cluster.module" { 287 vcsim_env 288 local output 289 290 run govc cluster.module.ls 291 assert_success # no tags defined yet 292 293 run govc cluster.module.ls -k=false 294 assert_failure 295 296 run govc cluster.module.ls -id enoent 297 assert_failure # specific module does not exist 298 299 run govc cluster.module.create -cluster DC0_C0 300 assert_success 301 302 id="$output" 303 304 run govc cluster.module.ls -id $id 305 assert_success 306 307 vm="/DC0/vm/DC0_C0_RP0_VM0" 308 309 run govc cluster.module.vm.add -id $id $vm 310 assert_success 311 312 count=$(govc cluster.module.ls -id $id | grep -c VirtualMachine) 313 [ "$count" = "1" ] 314 315 run govc cluster.module.vm.add -id $id $vm 316 assert_failure # already a member 317 318 run govc cluster.module.vm.rm -id $id $vm 319 assert_success 320 321 run govc cluster.module.ls -id $id 322 [ -z "$output" ] 323 324 run govc cluster.module.rm $id 325 assert_success 326 327 run govc cluster.module.ls -id $id 328 assert_failure 329 330 run govc cluster.module.rm "does_not_exist" 331 assert_failure 332 333 run govc cluster.module.rm --ignore-not-found "does_not_exist" 334 assert_success 335 336 run govc cluster.module.create -cluster DC0_C0 337 assert_success 338 339 id="$output" 340 341 run govc cluster.module.create -cluster DC0_C0 342 assert_success 343 344 id2="$output" 345 346 run govc cluster.module.rm --ignore-not-found "-" <<_EOF_ 347 $id 348 does_not_exist 349 $id2 350 _EOF_ 351 assert_success 352 353 } 354 355 @test "cluster.mv" { 356 vcsim_env -host 4 -cluster 2 357 358 # start with 4 hosts in each cluster 359 run govc find -type h /DC0/host/DC0_C0 360 assert_success 361 [ ${#lines[@]} -eq 4 ] 362 363 run govc find -type h /DC0/host/DC0_C1 364 assert_success 365 [ ${#lines[@]} -eq 4 ] 366 367 run govc cluster.mv -cluster DC0_C1 DC0_C0_H* 368 assert_failure 369 370 run govc host.maintenance.enter DC0_C0_H* 371 assert_success 372 373 # move 1 host from C0 to C1 374 run govc cluster.mv -cluster DC0_C1 DC0_C0_H2 375 assert_success 376 377 run govc find -type h /DC0/host/DC0_C0 378 assert_success 379 [ ${#lines[@]} -eq 3 ] 380 381 run govc find -type h /DC0/host/DC0_C1 382 assert_success 383 [ ${#lines[@]} -eq 5 ] 384 385 # move remaining 3 hosts from C0 to C1 386 run govc cluster.mv -cluster DC0_C1 DC0_C0_H{0,1,3} 387 assert_success 388 389 run govc find -type h /DC0/host/DC0_C0 390 assert_success 391 [ ${#lines[@]} -eq 0 ] 392 393 run govc find -type h /DC0/host/DC0_C1 394 assert_success 395 [ ${#lines[@]} -eq 8 ] 396 397 # move a standalone host into the cluster 398 run govc cluster.mv -cluster DC0_C1 DC0_H0 399 assert_success 400 401 run govc find -type h /DC0/host/DC0_C1 402 assert_success 403 [ ${#lines[@]} -eq 9 ] 404 405 run govc cluster.mv -cluster DC0_C1 DC0_C0_H* 406 assert_failure # hosts are already in the cluster 407 408 # TODO: vcsim's MoveIntoFolder_Task only supports moving from folders 409 # # move a cluster host to a standalone host 410 # run govc object.mv /DC0/host/DC0_C1/DC0_H0 /DC0/host 411 # assert_success 412 } 413 414 @test "cluster.change" { 415 vcsim_env 416 417 run govc cluster.change -drs-enabled -ha-enabled -ha-admission-control-enabled=false /DC0/host/DC0_C0 418 assert_success 419 420 config=$(govc object.collect -o -json /DC0/host/DC0_C0 | jq .configurationEx) 421 assert_equal true "$(jq -r .drsConfig.enabled <<<"$config")" 422 assert_equal true "$(jq -r .dasConfig.enabled <<<"$config")" 423 assert_equal false "$(jq -r .dasConfig.admissionControlEnabled <<<"$config")" 424 }