github.com/vmware/govmomi@v0.43.0/govc/test/vm.bats (about) 1 #!/usr/bin/env bats 2 3 load test_helper 4 5 @test "vm.ip" { 6 vcsim_env -autostart=false 7 8 id=/DC0/vm/DC0_H0_VM0 9 10 mac=00:50:56:83:3a:5d 11 run govc vm.customize -vm $id -mac $mac -ip 10.0.0.1 -netmask 255.255.0.0 -type Linux 12 assert_success 13 14 run govc vm.power -on $id 15 assert_success 16 17 run govc vm.ip -wait 5s $id 18 assert_success 19 20 run govc vm.ip -wait 5s -a -v4 $id 21 assert_success 22 23 run govc vm.ip -wait 5s -n $mac $id 24 assert_success 25 26 run govc vm.ip -wait 5s -n ethernet-0 $id 27 assert_success 28 29 ip=$(govc vm.ip -wait 5s $id) 30 31 # add a second nic 32 run govc vm.network.add -vm $id "VM Network" 33 assert_success 34 35 res=$(govc vm.ip -wait 5s -n ethernet-0 $id) 36 assert_equal $ip $res 37 } 38 39 @test "vm.ip capital MAC" { 40 vcsim_env -autostart=false 41 42 id=/DC0/vm/DC0_H0_VM0 43 44 mac=00:50:56:83:3A:5D 45 run govc vm.customize -vm $id -mac $mac -ip 10.0.0.1 -netmask 255.255.0.0 -type Linux 46 assert_success 47 48 run govc vm.power -on $id 49 assert_success 50 51 run govc vm.ip -wait 5s $id 52 assert_success 53 54 run govc vm.ip -wait 5s -a -v4 $id 55 assert_success 56 57 run govc vm.ip -wait 5s -n $mac $id 58 assert_success 59 60 run govc vm.ip -wait 5s -n ethernet-0 $id 61 assert_success 62 63 ip=$(govc vm.ip -wait 5s $id) 64 65 # add a second nic 66 run govc vm.network.add -vm $id "VM Network" 67 assert_success 68 69 res=$(govc vm.ip -wait 5s -n ethernet-0 $id) 70 assert_equal $ip $res 71 } 72 73 @test "vm.ip -esxcli" { 74 esx_env 75 76 ok=$(govc host.esxcli system settings advanced list -o /Net/GuestIPHack | grep ^IntValue: | awk '{print $2}') 77 if [ "$ok" != "1" ] ; then 78 skip "/Net/GuestIPHack=0" 79 fi 80 id=$(new_ttylinux_vm) 81 82 run govc vm.power -on $id 83 assert_success 84 85 run govc vm.ip -esxcli $id 86 assert_success 87 88 ip_esxcli=$output 89 90 run govc vm.ip $id 91 assert_success 92 ip_tools=$output 93 94 assert_equal $ip_esxcli $ip_tools 95 } 96 97 @test "vm.create" { 98 unset GOVC_DATASTORE 99 vcsim_start 100 101 run govc cluster.create empty-cluster 102 assert_success 103 104 id=$(new_id) 105 run govc vm.create -on=false "$id" 106 assert_failure # -pool must be specified 107 108 run govc vm.create -pool DC0_C0/Resources "$id" 109 assert_success 110 111 id=$(new_id) 112 run govc vm.create -cluster enoent "$id" 113 assert_failure # cluster does not exist 114 115 run govc vm.create -cluster empty-cluster "$id" 116 assert_failure # cluster has no hosts 117 118 run govc vm.create -cluster DC0_C0 "$id" 119 assert_success 120 121 run govc vm.create -force -cluster DC0_C0 "$id" 122 assert_success # create vm with the same name 123 124 run govc vm.create -cluster DC0_C0 "my:vm" 125 assert_success # vm has special characters (moref) 126 127 run govc object.collect -s vm/my:vm name 128 assert_success my:vm 129 } 130 131 @test "vm.change" { 132 vcsim_env 133 134 id=DC0_H0_VM0 135 136 run govc vm.change -g ubuntu64Guest -m 1024 -c 2 -vm $id 137 assert_success 138 139 run govc vm.info $id 140 assert_success 141 assert_matches "buntu" 142 assert_line "Memory: 1024MB" 143 assert_line "CPU: 2 vCPU(s)" 144 145 # test extraConfig 146 run govc vm.change -e "guestinfo.a=1" -e "guestinfo.b=2" -vm $id 147 assert_success 148 149 run govc vm.info -e $id 150 assert_success 151 assert_line "guestinfo.a: 1" 152 assert_line "guestinfo.b: 2" 153 154 # test extraConfigFile 155 run govc vm.change -f "guestinfo.c=this_is_not_an_existing.file" -vm $id 156 assert_failure 157 158 echo -n "3" > "$BATS_TMPDIR/extraConfigFile.conf" 159 run govc vm.change -f "guestinfo.d=$BATS_TMPDIR/extraConfigFile.conf" -vm $id 160 assert_success 161 162 run govc vm.info -e $id 163 assert_success 164 assert_line "guestinfo.d: 3" 165 166 run govc vm.change -sync-time-with-host=false -vm $id 167 assert_success 168 169 run govc vm.info -t $id 170 assert_success 171 assert_line "SyncTimeWithHost: false" 172 173 run govc vm.change -sync-time-with-host=true -vm $id 174 assert_success 175 176 run govc vm.info -t $id 177 assert_success 178 assert_line "SyncTimeWithHost: true" 179 180 run govc object.collect -s "vm/$id" config.memoryAllocation.reservation 181 assert_success 0 182 183 govc vm.change -vm "$id" -mem.reservation 1024 184 185 run govc object.collect -s "vm/$id" config.memoryAllocation.reservation 186 assert_success 1024 187 188 run govc vm.change -annotation $$ -vm "$id" 189 assert_success 190 191 run govc object.collect -s "vm/$id" config.annotation 192 assert_success $$ 193 194 uuid=$(vcsim uuidgen) 195 run govc vm.change -vm $id -uuid "$uuid" 196 assert_success 197 run govc object.collect -s "vm/$id" config.uuid 198 assert_success "$uuid" 199 200 nid=$(new_id) 201 run govc vm.change -name $nid -vm $id 202 assert_success 203 204 run govc vm.info $id 205 [ ${#lines[@]} -eq 0 ] 206 207 run govc vm.info $nid 208 [ ${#lines[@]} -gt 0 ] 209 } 210 211 @test "vm.change vcsim" { 212 vcsim_env 213 214 run govc vm.change -vm DC0_H0_VM0 -latency fail 215 assert_failure 216 217 run govc object.collect -s vm/DC0_H0_VM0 config.latencySensitivity.level 218 assert_success normal 219 220 run govc vm.change -vm DC0_H0_VM0 -latency high 221 assert_success 222 223 run govc object.collect -s vm/DC0_H0_VM0 config.latencySensitivity.level 224 assert_success high 225 } 226 227 @test "vm.power" { 228 vcsim_env -autostart=false 229 230 vm=DC0_H0_VM0 231 232 run vm_power_state $vm 233 assert_success "poweredOff" 234 235 run govc vm.power $vm 236 assert_failure 237 238 run govc vm.power -on -off $vm 239 assert_failure 240 241 # off -> on 242 run govc vm.power -on $vm 243 assert_success 244 run vm_power_state $vm 245 assert_success "poweredOn" 246 run govc vm.power -on $vm 247 assert_failure # already powered on 248 249 # on -> shutdown 250 run govc vm.power -s $vm 251 assert_success 252 run vm_power_state $vm 253 assert_success "poweredOff" 254 run govc vm.power -off $vm 255 assert_failure # already powered off 256 run govc vm.power -on $vm 257 assert_success 258 259 # on -> suspended 260 run govc vm.power -suspend $vm 261 assert_success 262 run vm_power_state $vm 263 assert_success "suspended" 264 run govc vm.power -suspend $vm 265 assert_failure # already suspended 266 267 # suspended -> on 268 run govc vm.power -on $vm 269 assert_success 270 run vm_power_state $vm 271 assert_success "poweredOn" 272 273 # on -> standby 274 run govc vm.power -standby $vm 275 assert_success 276 run vm_power_state $vm 277 assert_success "suspended" 278 run govc vm.power -standby $vm 279 assert_failure # already suspended 280 } 281 282 @test "vm.power -on -M" { 283 for esx in true false ; do 284 vcsim_env -esx=$esx -autostart=false 285 286 vms=($(govc find / -type m | sort)) 287 288 # All VMs are off with -autostart=false 289 off=($(govc find / -type m -runtime.powerState poweredOff | sort)) 290 assert_equal "${vms[*]}" "${off[*]}" 291 292 # Power on 1 VM to test that -M is idempotent 293 run govc vm.power -on "${vms[0]}" 294 assert_success 295 296 run govc vm.power -on -M "${vms[@]}" 297 assert_success 298 299 # All VMs should be powered on now 300 on=($(govc find / -type m -runtime.powerState poweredOn | sort)) 301 assert_equal "${vms[*]}" "${on[*]}" 302 303 vcsim_stop 304 done 305 } 306 307 @test "vm.power -force" { 308 vcsim_env 309 310 vm=$(new_id) 311 govc vm.create $vm 312 313 run govc vm.power -r $vm 314 assert_failure 315 316 run govc vm.power -r -force $vm 317 assert_success 318 319 run govc vm.power -s $vm 320 assert_success 321 322 run govc vm.power -off $vm 323 assert_failure 324 325 run govc vm.power -off -force $vm 326 assert_success 327 328 run govc vm.destroy $vm 329 assert_success 330 331 run govc vm.power -off $vm 332 assert_failure 333 334 run govc vm.power -off -force $vm 335 assert_failure 336 } 337 338 @test "vm.destroy" { 339 vcsim_env 340 341 vm=$(new_id) 342 govc vm.create $vm 343 344 # destroy powers off vm before destruction 345 run govc vm.destroy $vm 346 assert_success 347 348 run govc vm.destroy '*' 349 assert_success 350 351 run govc find / -type m 352 assert_success "" # expect all VMs are gone 353 } 354 355 @test "vm.create pvscsi" { 356 vcsim_env 357 358 vm=$(new_id) 359 govc vm.create -on=false -disk.controller pvscsi $vm 360 361 result=$(govc device.ls -vm $vm | grep pvscsi- | wc -l) 362 [ $result -eq 1 ] 363 364 result=$(govc device.ls -vm $vm | grep lsilogic- | wc -l) 365 [ $result -eq 0 ] 366 367 vm=$(new_id) 368 govc vm.create -on=false -disk.controller pvscsi -disk=1GB $vm 369 } 370 371 @test "vm.create in cluster" { 372 vcsim_env 373 374 # using GOVC_HOST and its resource pool 375 run govc vm.create -on=false $(new_id) 376 assert_success 377 378 # using no -host and the default resource pool for DC0 379 unset GOVC_HOST 380 run govc vm.create -on=false $(new_id) 381 assert_success 382 } 383 384 @test "vm.create -datastore-cluster" { 385 vcsim_env -pod 1 -ds 3 386 387 pod=/DC0/datastore/DC0_POD0 388 id=$(new_id) 389 390 run govc vm.create -disk 10M -datastore-cluster $pod "$id" 391 assert_failure 392 393 run govc object.mv /DC0/datastore/LocalDS_{1,2} $pod 394 assert_success 395 396 run govc vm.create -disk 10M -datastore-cluster $pod "$id" 397 assert_success 398 } 399 400 @test "vm.info" { 401 vcsim_env -esx 402 403 local num=3 404 405 local prefix=$(new_id) 406 407 for x in $(seq $num) 408 do 409 local id="${prefix}-${x}" 410 411 # If VM is not found: No output, exit code==0 412 run govc vm.info $id 413 assert_success 414 [ ${#lines[@]} -eq 0 ] 415 416 # If VM is not found (using -json flag): Valid json output, exit code==0 417 run env GOVC_INDENT=false govc vm.info -json $id 418 assert_success 419 assert_line "{\"virtualMachines\":null}" 420 421 run govc vm.info -dump $id 422 assert_success 423 424 run govc vm.create -on=false $id 425 assert_success 426 427 local info=$(govc vm.info -r $id) 428 local found=$(grep Name: <<<"$info" | wc -l) 429 [ "$found" -eq 1 ] 430 431 # test that mo names are printed 432 found=$(grep Host: <<<"$info" | awk '{print $2}') 433 [ -n "$found" ] 434 found=$(grep Storage: <<<"$info" | awk '{print $2}') 435 [ -n "$found" ] 436 found=$(grep Network: <<<"$info" | awk '{print $2}') 437 [ -n "$found" ] 438 done 439 440 # test find slice 441 local slice=$(govc vm.info ${prefix}-*) 442 local found=$(grep Name: <<<"$slice" | wc -l) 443 [ "$found" -eq $num ] 444 445 # test -r 446 found=$(grep Storage: <<<"$slice" | wc -l) 447 [ "$found" -eq 0 ] 448 found=$(grep Network: <<<"$slice" | wc -l) 449 [ "$found" -eq 0 ] 450 slice=$(govc vm.info -r ${prefix}-*) 451 found=$(grep Storage: <<<"$slice" | wc -l) 452 [ "$found" -eq $num ] 453 found=$(grep Network: <<<"$slice" | wc -l) 454 [ "$found" -eq $num ] 455 456 # test extraConfig 457 run govc vm.change -e "guestinfo.a=2" -vm $id 458 assert_success 459 run govc vm.info -e $id 460 assert_success 461 assert_line "guestinfo.a: 2" 462 run govc vm.change -e "guestinfo.a=" -vm $id 463 assert_success 464 refute_line "guestinfo.a: 2" 465 466 # test extraConfigFile 467 run govc vm.change -f "guestinfo.b=this_is_not_an_existing.file" -vm $id 468 assert_failure 469 echo -n "3" > "$BATS_TMPDIR/extraConfigFile.conf" 470 run govc vm.change -f "guestinfo.b=$BATS_TMPDIR/extraConfigFile.conf" -vm $id 471 assert_success 472 run govc vm.info -e $id 473 assert_success 474 assert_line "guestinfo.b: 3" 475 run govc vm.change -f "guestinfo.b=" -vm $id 476 assert_success 477 refute_line "guestinfo.b: 3" 478 479 # test optional bool Config 480 run govc vm.change -nested-hv-enabled=true -vm "$id" 481 assert_success 482 483 hv=$(govc vm.info -json "$id" | jq '.[][0].config.nestedHVEnabled') 484 assert_equal "$hv" "true" 485 } 486 487 @test "vm.info multi dc" { 488 vcsim_start -dc 2 489 490 run govc vm.info /DC1/vm/DC1_H0_VM1 491 assert_success 492 493 run govc vm.info DC1_H0_VM1 494 assert_failure 495 496 run govc vm.info -vm.ipath /DC1/vm/DC1_H0_VM1 497 assert_success 498 uuid=$(grep "UUID:" <<<"$output" | awk '{print $2}') 499 500 run govc vm.info -vm.ipath DC1_H0_VM1 501 assert_failure 502 503 run govc vm.info -vm.uuid enoent 504 assert_failure 505 506 run govc vm.info -vm.uuid "$uuid" 507 assert_failure 508 509 run govc vm.info -dc DC1 -vm.uuid "$uuid" 510 assert_success 511 } 512 513 @test "vm.create linked ide disk" { 514 esx_env 515 516 import_ttylinux_vmdk 517 518 vm=$(new_id) 519 520 run govc vm.create -disk $GOVC_TEST_VMDK -disk.controller ide -on=false $vm 521 assert_success 522 523 run govc device.info -vm $vm disk-200-0 524 assert_success 525 assert_line "Controller: ide-200" 526 } 527 528 @test "vm.create linked scsi disk" { 529 esx_env 530 531 import_ttylinux_vmdk 532 533 vm=$(new_id) 534 535 run govc vm.create -disk enoent -on=false $vm 536 assert_failure "govc: cannot stat '[${GOVC_DATASTORE##*/}] enoent': No such file" 537 538 run govc vm.create -disk $GOVC_TEST_VMDK -on=false $vm 539 assert_success 540 541 run govc device.info -vm $vm disk-1000-0 542 assert_success 543 assert_line "Controller: lsilogic-1000" 544 assert_line "Parent: [${GOVC_DATASTORE##*/}] $GOVC_TEST_VMDK" 545 assert_line "File: [${GOVC_DATASTORE##*/}] $vm/${vm}.vmdk" 546 } 547 548 @test "vm.create scsi disk" { 549 esx_env 550 551 import_ttylinux_vmdk 552 553 vm=$(new_id) 554 555 run govc vm.create -disk enoent -on=false $vm 556 assert_failure "govc: cannot stat '[${GOVC_DATASTORE##*/}] enoent': No such file" 557 558 run govc vm.create -disk $GOVC_TEST_VMDK -on=false -link=false $vm 559 assert_success 560 561 run govc device.info -vm $vm disk-1000-0 562 assert_success 563 assert_line "Controller: lsilogic-1000" 564 refute_line "Parent: [${GOVC_DATASTORE##*/}] $GOVC_TEST_VMDK" 565 assert_line "File: [${GOVC_DATASTORE##*/}] $GOVC_TEST_VMDK" 566 } 567 568 @test "vm.create scsi disk with datastore argument" { 569 esx_env 570 571 import_ttylinux_vmdk 572 573 vm=$(new_id) 574 575 run govc vm.create -disk="${GOVC_TEST_VMDK}" -disk-datastore="${GOVC_DATASTORE}" -on=false -link=false $vm 576 assert_success 577 578 run govc device.info -vm $vm disk-1000-0 579 assert_success 580 assert_line "File: [${GOVC_DATASTORE##*/}] $GOVC_TEST_VMDK" 581 } 582 583 @test "vm.create iso" { 584 vcsim_env -esx 585 586 upload_iso 587 588 vm=$(new_id) 589 590 run govc vm.create -iso enoent -on=false $vm 591 assert_failure "govc: cannot stat '[${GOVC_DATASTORE##*/}] enoent': No such file" 592 593 run govc vm.create -iso $GOVC_TEST_ISO -on=false $vm 594 assert_success 595 596 run govc device.info -vm $vm cdrom-* 597 assert_success 598 assert_line "Type: VirtualCdrom" 599 assert_line "Summary: ISO [${GOVC_DATASTORE##*/}] $GOVC_TEST_ISO" 600 } 601 602 @test "vm.create iso with datastore argument" { 603 vcsim_env 604 605 upload_iso 606 607 vm=$(new_id) 608 609 run govc vm.create -iso="${GOVC_TEST_ISO}" -iso-datastore="${GOVC_DATASTORE}" -on=false $vm 610 assert_success 611 612 run govc device.info -vm $vm cdrom-* 613 assert_success 614 assert_line "Summary: ISO [${GOVC_DATASTORE##*/}] $GOVC_TEST_ISO" 615 } 616 617 @test "vm.disk.create empty vm" { 618 vcsim_env 619 620 vm=$(new_empty_vm) 621 622 local name=$(new_id) 623 624 run govc vm.disk.create -vm "$vm" -name "$name" -size 1G 625 assert_success 626 result=$(govc device.ls -vm "$vm" | grep -c disk-) 627 [ "$result" -eq 1 ] 628 govc device.info -json -vm "$vm" disk-* | jq .devices[].backing.sharing | grep -v sharingMultiWriter 629 630 name=$(new_id) 631 632 run govc vm.disk.create -vm "$vm" -name "$vm/$name" -size 2G 633 assert_success 634 635 result=$(govc device.ls -vm "$vm" | grep -c disk-) 636 [ "$result" -eq 2 ] 637 } 638 639 @test "vm.disk.share" { 640 esx_env 641 642 vm=$(new_empty_vm) 643 644 run govc vm.disk.create -vm "$vm" -name "$vm/shared.vmdk" -size 1G -eager -thick -sharing sharingMultiWriter 645 assert_success 646 govc device.info -json -vm "$vm" disk-* | jq .devices[].backing.sharing | grep sharingMultiWriter 647 648 run govc vm.power -on "$vm" 649 assert_success 650 651 vm2=$(new_empty_vm) 652 653 run govc vm.disk.attach -vm "$vm2" -link=false -disk "$vm/shared.vmdk" 654 assert_success 655 656 run govc vm.power -on "$vm2" 657 assert_failure # requires sharingMultiWriter 658 659 run govc device.remove -vm "$vm2" -keep disk-1000-0 660 assert_success 661 662 run govc vm.disk.attach -vm "$vm2" -link=false -sharing sharingMultiWriter -disk "$vm/shared.vmdk" 663 assert_success 664 665 run govc vm.power -on "$vm2" 666 assert_success 667 668 run govc vm.power -off "$vm" 669 assert_success 670 671 run govc vm.disk.change -vm "$vm" -disk.filePath "[$GOVC_DATASTORE] $vm/shared.vmdk" -sharing sharingNone 672 assert_success 673 674 ! govc device.info -json -vm "$vm" disk-* | jq .devices[].backing.sharing | grep sharingMultiWriter 675 } 676 677 @test "vm.disk.create" { 678 vcsim_env 679 680 vm=$(new_id) 681 682 govc vm.create -on=false "$vm" 683 assert_success 684 685 name=$(new_id) 686 687 run govc vm.disk.create -vm "$vm" -name "$vm/$name" -size 1M 688 assert_success 689 disk=$(govc device.ls -vm "$vm" disk-* | awk '{print $1}') 690 result=$(grep -c disk- <<<"$disk") 691 [ "$result" -eq 1 ] 692 693 run govc vm.disk.change -vm "$vm" -disk.name "$disk" -size 2M 694 assert_success 695 696 run govc vm.disk.change -vm "$vm" -disk.name "$disk" -size 1M 697 assert_failure # cannot shrink disk 698 699 name=$(new_id) 700 run govc vm.disk.create -vm "$vm" -name "$vm/$name" -profile enoent 701 assert_failure # profile does not exist 702 703 run govc vm.disk.create -vm "$vm" -name "$vm/$name" -profile "vSAN Default Storage Policy" 704 assert_success 705 } 706 707 @test "vm.disk.attach" { 708 esx_env 709 710 import_ttylinux_vmdk 711 712 vm=$(new_id) 713 714 govc vm.create -disk $GOVC_TEST_VMDK -on=false $vm 715 result=$(govc device.ls -vm $vm | grep disk- | wc -l) 716 [ $result -eq 1 ] 717 718 id=$(new_id) 719 run govc import.vmdk $GOVC_TEST_VMDK_SRC $id 720 assert_success 721 722 run govc vm.disk.attach -vm $vm -link=false -disk enoent.vmdk 723 assert_failure "govc: File [${GOVC_DATASTORE##*/}] enoent.vmdk was not found" 724 725 run govc vm.disk.attach -vm $vm -disk enoent.vmdk 726 assert_failure "govc: Invalid configuration for device '0'." 727 728 run govc vm.disk.attach -vm $vm -disk $id/$(basename $GOVC_TEST_VMDK) -controller lsilogic-1000 729 assert_success 730 result=$(govc device.ls -vm $vm | grep disk- | wc -l) 731 [ $result -eq 2 ] 732 } 733 734 @test "vm.create new disk with datastore argument" { 735 vcsim_env 736 737 vm=$(new_id) 738 739 run govc vm.create -disk="1GiB" -ds="${GOVC_DATASTORE}" -on=false -link=false $vm 740 assert_success 741 742 run govc device.info -vm $vm disk-* 743 assert_success 744 assert_line "File: [${GOVC_DATASTORE##*/}] ${vm}/${vm}.vmdk" 745 } 746 747 @test "vm.create new disk with datastore cluster argument" { 748 vcsim_env -pod 1 -ds 3 749 750 vm=$(new_id) 751 752 run govc object.mv /DC0/datastore/LocalDS_{1,2} /DC0/datastore/DC0_POD0 753 assert_success 754 755 run govc vm.create -disk="1GiB" -datastore-cluster=/DC0/datastore/DC0_POD0 -on=false -link=false "$vm" 756 assert_success 757 758 run govc device.info -vm $vm disk-* 759 assert_success 760 } 761 762 @test "vm.register" { 763 vcsim_env 764 765 run govc vm.unregister enoent 766 assert_failure 767 768 vm=$(new_empty_vm) 769 770 run govc vm.unregister "$vm" 771 assert_success 772 773 run govc vm.register "$vm/${vm}.vmx" 774 assert_success 775 } 776 777 @test "vm.register vcsim" { 778 vcsim_env -autostart=false 779 780 host=$GOVC_HOST 781 pool=$GOVC_RESOURCE_POOL 782 783 unset GOVC_HOST GOVC_RESOURCE_POOL 784 785 vm=DC0_H0_VM0 786 787 run govc vm.unregister $vm 788 assert_success 789 790 run govc vm.register "$vm/${vm}.vmx" 791 assert_failure # -pool is required 792 793 run govc vm.register -pool "$pool" "$vm/${vm}.vmx" 794 assert_success 795 796 run govc vm.unregister $vm 797 assert_success 798 799 run govc vm.register -template -pool "$pool" "$vm/${vm}.vmx" 800 assert_failure # -pool is not allowed w/ template 801 802 run govc vm.register -template -host "$host" "$vm/${vm}.vmx" 803 assert_success 804 } 805 806 @test "vm.clone" { 807 vcsim_env 808 809 vm="DC0_H0_VM0" 810 clone=$(new_id) 811 812 run govc vm.clone -vm "$vm" -host.ipath /DC0/host/DC0_C0/DC0_C0_H0 -annotation $$ "$clone" 813 assert_success 814 815 backing=$(govc device.info -json -vm "$clone" disk-* | jq .devices[].backing) 816 assert_equal false "$(jq .eagerlyScrub <<<"$backing")" 817 assert_equal true "$(jq .thinProvisioned <<<"$backing")" 818 819 run govc object.collect -s "/$GOVC_DATACENTER/vm/$clone" config.annotation 820 assert_success $$ 821 822 clone=$(new_id) 823 run govc vm.clone -vm "$vm" -snapshot X "$clone" 824 assert_failure 825 826 run govc snapshot.create -vm "$vm" X 827 assert_success 828 829 run govc vm.clone -vm "$vm" -snapshot X "$clone" 830 assert_success 831 832 clone=$(new_id) 833 run govc vm.clone -cluster enoent -vm "$vm" "$clone" 834 assert_failure 835 836 run govc vm.clone -cluster DC0_C0 -vm "$vm" "$clone" 837 assert_success 838 839 run govc vm.clone -cluster DC0_C0 -vm "$vm" "$clone" 840 assert_failure # already exists 841 842 run govc datastore.cp "$clone"/"$clone".vmx "$clone"/"$clone".vmx.copy 843 run govc vm.destroy "$clone" 844 run govc datastore.mv "$clone"/"$clone".vmx.copy "$clone"/"$clone".vmx # leave vmx file 845 run govc vm.clone -force -vm "$vm" "$clone" 846 assert_success # clone vm with the same name vmx file 847 848 vm=$(new_empty_vm) 849 run govc vm.disk.create -vm "$vm" -thick -eager -size 10M -name "$vm/data.vmdk" 850 assert_success 851 852 backing=$(govc device.info -json -vm "$vm" disk-* | jq .devices[].backing) 853 assert_equal true "$(jq .eagerlyScrub <<<"$backing")" 854 assert_equal false "$(jq .thinProvisioned <<<"$backing")" 855 856 clone=$(new_id) 857 run govc vm.clone -vm "$vm" "$clone" 858 assert_success 859 860 backing=$(govc device.info -json -vm "$clone" disk-* | jq .devices[].backing) 861 assert_equal true "$(jq .eagerlyScrub <<<"$backing")" 862 assert_equal false "$(jq .thinProvisioned <<<"$backing")" 863 864 # test that each vm has a unique vmdk path 865 for item in fileName uuid; do 866 items=$(govc object.collect -json -type m / config.hardware.device | \ 867 jq ".changeSet[].val._value[].backing.$item | select(. != null)") 868 869 nitems=$(wc -l <<<"$items") 870 uitems=$(sort -u <<<"$items" | wc -l) 871 assert_equal "$nitems" "$uitems" 872 done 873 } 874 875 @test "vm.clone change resources" { 876 vcsim_env 877 878 vm=$(new_empty_vm) 879 clone=$(new_id) 880 881 run govc vm.info -r "$vm" 882 assert_success 883 assert_line "Network: $(basename "$GOVC_NETWORK")" # DVPG0 884 885 run govc vm.clone -m 1024 -c 2 -net "VM Network" -vm "$vm" "$clone" 886 assert_success 887 888 run govc vm.info -r "$clone" 889 assert_success 890 assert_line "Memory: 1024MB" 891 assert_line "CPU: 2 vCPU(s)" 892 assert_line "Network: VM Network" 893 894 # Remove all NICs from source vm 895 run govc device.remove -vm "$vm" "$(govc device.ls -vm "$vm" | grep ethernet- | awk '{print $1}')" 896 assert_success 897 898 clone=$(new_id) 899 900 mac=00:00:0f:a7:a0:f1 901 run govc vm.clone -net "VM Network" -net.address $mac -vm "$vm" "$clone" 902 assert_success 903 904 run govc vm.info -r "$clone" 905 assert_success 906 assert_line "Network: VM Network" 907 908 run govc device.info -vm "$clone" 909 assert_success 910 assert_line "MAC Address: $mac" 911 } 912 913 @test "vm.clone usage" { 914 # validate we require -vm flag 915 run govc vm.clone enoent 916 assert_failure 917 } 918 919 @test "vm.migrate" { 920 vcsim_env -cluster 2 921 922 host0=/DC0/host/DC0_C0/DC0_C0_H0 923 host1=/DC0/host/DC0_C0/DC0_C0_H1 924 moid0=$(govc find -maxdepth 0 -i $host0) 925 moid1=$(govc find -maxdepth 0 -i $host1) 926 927 vm=$(new_id) 928 run govc vm.create -on=false -host $host0 "$vm" 929 assert_success 930 931 # assert VM is on H0 932 run govc object.collect "vm/$vm" -runtime.host "$moid0" 933 assert_success 934 935 # WaitForUpdates until the VM runtime.host changes to H1 936 govc object.collect "vm/$vm" -runtime.host "$moid1" & 937 pid=$! 938 939 # migrate from H0 to H1 940 run govc vm.migrate -host $host1 "$vm" 941 assert_success 942 943 run govc events -type VmMigratedEvent "vm/$vm" 944 assert_success 945 assert_matches "Migration of virtual machine" 946 947 wait $pid 948 949 # (re-)assert VM is now on H1 950 run govc object.collect "vm/$vm" -runtime.host "$moid1" 951 assert_success 952 953 # migrate from C0 to C1 954 run govc vm.migrate -pool DC0_C1/Resources "$vm" 955 assert_success 956 957 run govc folder.create vm/new-folder 958 assert_success 959 960 run govc object.collect -s "vm/$vm" parent 961 assert_success 962 963 uuid=$(govc object.collect -s "vm/$vm" config.uuid) 964 run govc vm.migrate -folder vm/new-folder -vm.uuid "$uuid" 965 assert_success 966 967 run govc object.collect -s "vm/new-folder/$vm" parent 968 assert_success 969 970 run govc vm.info -r "$vm" 971 assert_matches "Network: +DC0_DVPG0" 972 973 run govc vm.migrate -host "$host0" -net "VM Network" "$vm" 974 assert_success 975 976 run govc vm.info -r "$vm" 977 assert_matches "Network: +VM Network" 978 } 979 980 @test "object name with slash" { 981 vcsim_env 982 983 vm=DC0_H0_VM0 984 985 name="$vm/with-slash" 986 987 # rename VM to include a '/' 988 run govc vm.change -vm "$vm" -name "$name" 989 assert_success 990 991 path=$(govc ls "vm/$name") 992 993 run govc vm.info "$name" 994 assert_success 995 assert_line "Name: $name" 996 assert_line "Path: $path" 997 998 run govc vm.info "$path" 999 assert_success 1000 assert_line "Name: $name" 1001 assert_line "Path: $path" 1002 1003 run govc find vm -name "$name" 1004 assert_success "vm/$name" 1005 1006 # create a portgroup where name includes a '/' 1007 net=$(new_id)/with-slash 1008 1009 run govc host.portgroup.add -vswitch vSwitch0 "$net" 1010 assert_success 1011 1012 run govc vm.network.change -vm "$name" -net "$net" ethernet-0 1013 assert_success 1014 1015 # change VM eth0 to use network that includes a '/' in the name 1016 run govc device.info -vm "$name" ethernet-0 1017 assert_success 1018 assert_line "Summary: $net" 1019 1020 run govc host.portgroup.remove "$net" 1021 assert_success 1022 } 1023 1024 @test "vm.console" { 1025 esx_env 1026 1027 vm=$(new_empty_vm) 1028 1029 run govc vm.console "$vm" 1030 assert_success 1031 1032 run govc vm.console -wss "$vm" 1033 assert_failure 1034 1035 run govc vm.power -on "$vm" 1036 assert_success 1037 1038 run govc vm.console "$vm" 1039 assert_success 1040 1041 run govc vm.console -wss "$vm" 1042 assert_success 1043 1044 run govc vm.console -capture - "$vm" 1045 assert_success 1046 } 1047 1048 @test "vm.upgrade" { 1049 vcsim_env 1050 1051 vm=$(new_id) 1052 1053 run govc vm.create -on=false -version 0.5 "$vm" 1054 assert_failure 1055 1056 run govc vm.create -on=false -version 5.5 "$vm" 1057 assert_success 1058 1059 run govc object.collect -s "vm/$vm" config.version 1060 assert_success "vmx-10" 1061 1062 run govc vm.upgrade -vm "$vm" 1063 assert_success 1064 1065 version=$(govc object.collect -s "vm/$vm" config.version) 1066 [[ "$version" > "vmx-10" ]] 1067 1068 run govc vm.upgrade -vm "$vm" 1069 assert_failure 1070 1071 run govc vm.create -on=false -version vmx-11 "$(new_id)" 1072 assert_success 1073 } 1074 1075 @test "vm.markastemplate" { 1076 vcsim_env 1077 1078 id=$(new_id) 1079 1080 run govc vm.create -on=true "$id" 1081 assert_success 1082 1083 run govc vm.change -vm "$id" -e testing=123 1084 assert_success 1085 1086 run govc vm.markastemplate "$id" 1087 assert_failure 1088 1089 run govc vm.power -off "$id" 1090 assert_success 1091 1092 run govc vm.markasvm "$id" 1093 assert_failure # already a vm 1094 1095 run govc vm.markastemplate "$id" 1096 assert_success 1097 1098 run govc vm.markastemplate "$id" 1099 assert_failure # already a template 1100 1101 run govc vm.change -vm "$id" -e testing=456 1102 assert_failure # template reconfigure only allows name and annotation change 1103 1104 run govc vm.change -vm "$id" -annotation testing123 1105 assert_success 1106 1107 run govc vm.power -on "$id" 1108 assert_failure 1109 1110 run govc vm.clone -vm "$id" -on=false new-vm 1111 assert_success 1112 1113 run govc vm.markasvm "$id" 1114 assert_success 1115 } 1116 1117 @test "vm.option.info" { 1118 vcsim_env 1119 1120 run govc vm.option.info -host "$GOVC_HOST" 1121 assert_success 1122 1123 run govc vm.option.info -cluster "$(dirname "$GOVC_HOST")" 1124 assert_success 1125 1126 run govc vm.option.info -vm DC0_H0_VM0 1127 assert_success 1128 1129 family=$(govc vm.option.info -json ubuntu64Guest | jq -r .guestOSDescriptor[].family) 1130 assert_equal linuxGuest "$family" 1131 1132 family=$(govc vm.option.info -json windows8_64Guest | jq -r .guestOSDescriptor[].family) 1133 assert_equal windowsGuest "$family" 1134 1135 run govc vm.option.info enoent 1136 assert_success # returns the entire simulator.GuestID list 1137 [ ${#lines[@]} -ge 100 ] 1138 } 1139 1140 @test "vm.target.info" { 1141 vcsim_env 1142 1143 run govc vm.target.info -host "$GOVC_HOST" 1144 assert_success 1145 1146 run govc vm.target.info -cluster "$(dirname "$GOVC_HOST")" 1147 assert_success 1148 1149 run govc vm.target.info -vm DC0_H0_VM0 1150 assert_success 1151 1152 run govc vm.target.info -json 1153 assert_success 1154 } 1155 1156 @test "vm.customize" { 1157 vcsim_env 1158 1159 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.42 -netmask 255.255.0.0 vcsim-linux-static 1160 assert_failure # power must be off 1161 1162 run govc vm.power -off DC0_H0_VM0 1163 assert_success 1164 1165 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.42 -netmask 255.255.0.0 vcsim-linux-static 1166 assert_success 1167 1168 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.42 -netmask 255.255.0.0 vcsim-linux-static 1169 assert_failure # pending customization 1170 1171 run govc vm.power -on DC0_H0_VM0 1172 assert_success 1173 1174 run govc object.collect -s vm/DC0_H0_VM0 guest.ipAddress 1175 assert_success 10.0.0.42 1176 1177 run govc object.collect -s vm/DC0_H0_VM0 guest.hostName 1178 assert_success vcsim-1 1179 1180 run govc vm.power -off DC0_H0_VM0 1181 assert_success 1182 1183 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.43 -netmask 255.255.0.0 -domain HOME -tz D -name windoze vcsim-windows-static 1184 assert_success 1185 1186 run govc vm.power -on DC0_H0_VM0 1187 assert_success 1188 1189 run govc object.collect -s vm/DC0_H0_VM0 guest.ipAddress 1190 assert_success 10.0.0.43 1191 1192 run govc object.collect -s vm/DC0_H0_VM0 summary.guest.ipAddress 1193 assert_success 10.0.0.43 1194 1195 run govc object.collect -s vm/DC0_H0_VM0 summary.guest.hostName 1196 assert_success windoze 1197 1198 run govc vm.info DC0_H0_VM0 1199 assert_success 1200 assert_matches 10.0.0.43 1201 1202 run govc object.collect -s vm/DC0_H0_VM0 guest.hostName 1203 assert_success windoze 1204 1205 run govc vm.power -off DC0_H0_VM0 1206 assert_success 1207 1208 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.44 -netmask 255.255.0.0 -type Windows 1209 assert_success 1210 1211 run govc vm.power -on DC0_H0_VM0 1212 assert_success 1213 1214 run govc object.collect -s vm/DC0_H0_VM0 guest.ipAddress 1215 assert_success 10.0.0.44 1216 1217 run govc vm.power -off DC0_H0_VM0 1218 assert_success 1219 1220 run govc vm.customize -vm DC0_H0_VM0 -type Linux 1221 assert_failure # no -ip specified 1222 1223 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.45 -netmask 255.255.0.0 -type Linux -dns-server 1.1.1.1 -dns-suffix example.com 1224 assert_success 1225 1226 run govc vm.power -on DC0_H0_VM0 1227 assert_success 1228 1229 run govc object.collect -s vm/DC0_H0_VM0 guest.ipAddress 1230 assert_success 10.0.0.45 1231 1232 host=$(govc ls -L "$(govc object.collect -s vm/DC0_H0_VM0 runtime.host)") 1233 run govc host.maintenance.enter "$host" 1234 assert_success 1235 1236 run govc vm.power -off DC0_H0_VM0 1237 assert_success 1238 1239 run govc vm.power -on DC0_H0_VM0 1240 assert_failure # InvalidState 1241 1242 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.45 -netmask 255.255.0.0 -type Linux 1243 assert_failure # InvalidState 1244 1245 run govc host.maintenance.exit "$host" 1246 assert_success 1247 1248 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.45 -netmask 255.255.0.0 -type Linux 1249 assert_success 1250 } 1251 1252 @test "vm.check.config" { 1253 vcsim_env -cluster 2 1254 1255 export GOVC_SHOW_UNRELEASED=true 1256 1257 vm=DC0_C0_RP0_VM0 1258 run govc vm.create -spec -pool DC0_C0/Resources $vm 1259 assert_success 1260 spec="$output" 1261 1262 run govc vm.check.config -vm $vm <<<"$spec" 1263 assert_success 1264 1265 # we can use any host in the VM's cluster 1266 for host in $(govc find /DC0/host/DC0_C0 -type f) ; do 1267 run govc vm.check.config -host "$host" <<<"$spec" 1268 assert_success 1269 done 1270 1271 run govc vm.check.config -host DC0_C1_H0 <<<"$spec" 1272 assert_failure # pool and host do not belong to the same compute resource 1273 1274 run govc vm.check.config -pool DC0_C1/Resources <<<"$spec" 1275 assert_failure # pool and host do not belong to the same compute resource 1276 1277 # spec.memoryMB 1278 max_mem=$(govc object.collect -s DC0_C1_H0 capability.maxSupportedVmMemory) 1279 run govc vm.create -spec -m "$((max_mem+100))" $vm 1280 assert_success 1281 spec="$output" 1282 1283 run govc vm.check.config -vm $vm -json <<<"$spec" 1284 assert_success 1285 assert_matches "outside the range" 1286 1287 # spec.numCPUs 1288 max_cpu=$(govc object.collect -s "$host" summary.hardware.numCpuCores) 1289 run govc vm.create -spec -c "$((max_cpu+100))" $vm 1290 assert_success 1291 spec="$output" 1292 1293 run govc vm.check.config -vm $vm -json <<<"$spec" 1294 assert_success 1295 assert_matches "vm requires 100 CPUs" 1296 1297 # spec.guestId 1298 run govc vm.create -spec -g ttylinux -pool DC0_C0/Resources $vm 1299 assert_success 1300 spec="$output" 1301 1302 run govc vm.check.config -vm $vm -json <<<"$spec" 1303 assert_success 1304 assert_matches unsupported 1305 } 1306 1307 @test "vm.check.compat" { 1308 vcsim_env -cluster 2 1309 1310 export GOVC_SHOW_UNRELEASED=true 1311 1312 vm=DC0_C0_RP0_VM0 1313 1314 run govc vm.check.compat -vm $vm -pool DC0_C0/Resources 1315 assert_success 1316 1317 run govc vm.check.compat -vm $vm -pool DC0_C1/Resources 1318 assert_failure # InvalidArgument spec.pool 1319 } 1320 1321 @test "vm.check.relocate" { 1322 vcsim_env -cluster 2 1323 1324 export GOVC_SHOW_UNRELEASED=true 1325 1326 vm=DC0_C0_RP0_VM0 1327 run govc vm.migrate -spec -pool DC0_C0/Resources $vm 1328 assert_success 1329 spec="$output" 1330 1331 run govc vm.check.relocate -vm $vm <<<"$spec" 1332 assert_success 1333 }