github.com/vmware/govmomi@v0.37.1/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 result=$(govc device.ls -vm "$vm" | grep -c disk-) 690 [ "$result" -eq 1 ] 691 } 692 693 @test "vm.disk.attach" { 694 esx_env 695 696 import_ttylinux_vmdk 697 698 vm=$(new_id) 699 700 govc vm.create -disk $GOVC_TEST_VMDK -on=false $vm 701 result=$(govc device.ls -vm $vm | grep disk- | wc -l) 702 [ $result -eq 1 ] 703 704 id=$(new_id) 705 run govc import.vmdk $GOVC_TEST_VMDK_SRC $id 706 assert_success 707 708 run govc vm.disk.attach -vm $vm -link=false -disk enoent.vmdk 709 assert_failure "govc: File [${GOVC_DATASTORE##*/}] enoent.vmdk was not found" 710 711 run govc vm.disk.attach -vm $vm -disk enoent.vmdk 712 assert_failure "govc: Invalid configuration for device '0'." 713 714 run govc vm.disk.attach -vm $vm -disk $id/$(basename $GOVC_TEST_VMDK) -controller lsilogic-1000 715 assert_success 716 result=$(govc device.ls -vm $vm | grep disk- | wc -l) 717 [ $result -eq 2 ] 718 } 719 720 @test "vm.create new disk with datastore argument" { 721 vcsim_env 722 723 vm=$(new_id) 724 725 run govc vm.create -disk="1GiB" -ds="${GOVC_DATASTORE}" -on=false -link=false $vm 726 assert_success 727 728 run govc device.info -vm $vm disk-* 729 assert_success 730 assert_line "File: [${GOVC_DATASTORE##*/}] ${vm}/${vm}.vmdk" 731 } 732 733 @test "vm.create new disk with datastore cluster argument" { 734 vcsim_env -pod 1 -ds 3 735 736 vm=$(new_id) 737 738 run govc object.mv /DC0/datastore/LocalDS_{1,2} /DC0/datastore/DC0_POD0 739 assert_success 740 741 run govc vm.create -disk="1GiB" -datastore-cluster=/DC0/datastore/DC0_POD0 -on=false -link=false "$vm" 742 assert_success 743 744 run govc device.info -vm $vm disk-* 745 assert_success 746 } 747 748 @test "vm.register" { 749 vcsim_env 750 751 run govc vm.unregister enoent 752 assert_failure 753 754 vm=$(new_empty_vm) 755 756 run govc vm.unregister "$vm" 757 assert_success 758 759 run govc vm.register "$vm/${vm}.vmx" 760 assert_success 761 } 762 763 @test "vm.register vcsim" { 764 vcsim_env -autostart=false 765 766 host=$GOVC_HOST 767 pool=$GOVC_RESOURCE_POOL 768 769 unset GOVC_HOST GOVC_RESOURCE_POOL 770 771 vm=DC0_H0_VM0 772 773 run govc vm.unregister $vm 774 assert_success 775 776 run govc vm.register "$vm/${vm}.vmx" 777 assert_failure # -pool is required 778 779 run govc vm.register -pool "$pool" "$vm/${vm}.vmx" 780 assert_success 781 782 run govc vm.unregister $vm 783 assert_success 784 785 run govc vm.register -template -pool "$pool" "$vm/${vm}.vmx" 786 assert_failure # -pool is not allowed w/ template 787 788 run govc vm.register -template -host "$host" "$vm/${vm}.vmx" 789 assert_success 790 } 791 792 @test "vm.clone" { 793 vcsim_env 794 795 vm="DC0_H0_VM0" 796 clone=$(new_id) 797 798 run govc vm.clone -vm "$vm" -host.ipath /DC0/host/DC0_C0/DC0_C0_H0 -annotation $$ "$clone" 799 assert_success 800 801 backing=$(govc device.info -json -vm "$clone" disk-* | jq .devices[].backing) 802 assert_equal false "$(jq .eagerlyScrub <<<"$backing")" 803 assert_equal true "$(jq .thinProvisioned <<<"$backing")" 804 805 run govc object.collect -s "/$GOVC_DATACENTER/vm/$clone" config.annotation 806 assert_success $$ 807 808 clone=$(new_id) 809 run govc vm.clone -vm "$vm" -snapshot X "$clone" 810 assert_failure 811 812 run govc snapshot.create -vm "$vm" X 813 assert_success 814 815 run govc vm.clone -vm "$vm" -snapshot X "$clone" 816 assert_success 817 818 clone=$(new_id) 819 run govc vm.clone -cluster enoent -vm "$vm" "$clone" 820 assert_failure 821 822 run govc vm.clone -cluster DC0_C0 -vm "$vm" "$clone" 823 assert_success 824 825 run govc vm.clone -cluster DC0_C0 -vm "$vm" "$clone" 826 assert_failure # already exists 827 828 run govc datastore.cp "$clone"/"$clone".vmx "$clone"/"$clone".vmx.copy 829 run govc vm.destroy "$clone" 830 run govc datastore.mv "$clone"/"$clone".vmx.copy "$clone"/"$clone".vmx # leave vmx file 831 run govc vm.clone -force -vm "$vm" "$clone" 832 assert_success # clone vm with the same name vmx file 833 834 vm=$(new_empty_vm) 835 run govc vm.disk.create -vm "$vm" -thick -eager -size 10M -name "$vm/data.vmdk" 836 assert_success 837 838 backing=$(govc device.info -json -vm "$vm" disk-* | jq .devices[].backing) 839 assert_equal true "$(jq .eagerlyScrub <<<"$backing")" 840 assert_equal false "$(jq .thinProvisioned <<<"$backing")" 841 842 clone=$(new_id) 843 run govc vm.clone -vm "$vm" "$clone" 844 assert_success 845 846 backing=$(govc device.info -json -vm "$clone" disk-* | jq .devices[].backing) 847 assert_equal true "$(jq .eagerlyScrub <<<"$backing")" 848 assert_equal false "$(jq .thinProvisioned <<<"$backing")" 849 850 # test that each vm has a unique vmdk path 851 for item in fileName uuid; do 852 items=$(govc object.collect -json -type m / config.hardware.device | \ 853 jq ".changeSet[].val._value[].backing.$item | select(. != null)") 854 855 nitems=$(wc -l <<<"$items") 856 uitems=$(sort -u <<<"$items" | wc -l) 857 assert_equal "$nitems" "$uitems" 858 done 859 } 860 861 @test "vm.clone change resources" { 862 vcsim_env 863 864 vm=$(new_empty_vm) 865 clone=$(new_id) 866 867 run govc vm.info -r "$vm" 868 assert_success 869 assert_line "Network: $(basename "$GOVC_NETWORK")" # DVPG0 870 871 run govc vm.clone -m 1024 -c 2 -net "VM Network" -vm "$vm" "$clone" 872 assert_success 873 874 run govc vm.info -r "$clone" 875 assert_success 876 assert_line "Memory: 1024MB" 877 assert_line "CPU: 2 vCPU(s)" 878 assert_line "Network: VM Network" 879 880 # Remove all NICs from source vm 881 run govc device.remove -vm "$vm" "$(govc device.ls -vm "$vm" | grep ethernet- | awk '{print $1}')" 882 assert_success 883 884 clone=$(new_id) 885 886 mac=00:00:0f:a7:a0:f1 887 run govc vm.clone -net "VM Network" -net.address $mac -vm "$vm" "$clone" 888 assert_success 889 890 run govc vm.info -r "$clone" 891 assert_success 892 assert_line "Network: VM Network" 893 894 run govc device.info -vm "$clone" 895 assert_success 896 assert_line "MAC Address: $mac" 897 } 898 899 @test "vm.clone usage" { 900 # validate we require -vm flag 901 run govc vm.clone enoent 902 assert_failure 903 } 904 905 @test "vm.migrate" { 906 vcsim_env -cluster 2 907 908 host0=/DC0/host/DC0_C0/DC0_C0_H0 909 host1=/DC0/host/DC0_C0/DC0_C0_H1 910 moid0=$(govc find -maxdepth 0 -i $host0) 911 moid1=$(govc find -maxdepth 0 -i $host1) 912 913 vm=$(new_id) 914 run govc vm.create -on=false -host $host0 "$vm" 915 assert_success 916 917 # assert VM is on H0 918 run govc object.collect "vm/$vm" -runtime.host "$moid0" 919 assert_success 920 921 # WaitForUpdates until the VM runtime.host changes to H1 922 govc object.collect "vm/$vm" -runtime.host "$moid1" & 923 pid=$! 924 925 # migrate from H0 to H1 926 run govc vm.migrate -host $host1 "$vm" 927 assert_success 928 929 run govc events -type VmMigratedEvent "vm/$vm" 930 assert_success 931 assert_matches "Migration of virtual machine" 932 933 wait $pid 934 935 # (re-)assert VM is now on H1 936 run govc object.collect "vm/$vm" -runtime.host "$moid1" 937 assert_success 938 939 # migrate from C0 to C1 940 run govc vm.migrate -pool DC0_C1/Resources "$vm" 941 assert_success 942 943 run govc folder.create vm/new-folder 944 assert_success 945 946 run govc object.collect -s "vm/$vm" parent 947 assert_success 948 949 uuid=$(govc object.collect -s "vm/$vm" config.uuid) 950 run govc vm.migrate -folder vm/new-folder -vm.uuid "$uuid" 951 assert_success 952 953 run govc object.collect -s "vm/new-folder/$vm" parent 954 assert_success 955 } 956 957 @test "object name with slash" { 958 vcsim_env 959 960 vm=DC0_H0_VM0 961 962 name="$vm/with-slash" 963 964 # rename VM to include a '/' 965 run govc vm.change -vm "$vm" -name "$name" 966 assert_success 967 968 path=$(govc ls "vm/$name") 969 970 run govc vm.info "$name" 971 assert_success 972 assert_line "Name: $name" 973 assert_line "Path: $path" 974 975 run govc vm.info "$path" 976 assert_success 977 assert_line "Name: $name" 978 assert_line "Path: $path" 979 980 run govc find vm -name "$name" 981 assert_success "vm/$name" 982 983 # create a portgroup where name includes a '/' 984 net=$(new_id)/with-slash 985 986 run govc host.portgroup.add -vswitch vSwitch0 "$net" 987 assert_success 988 989 run govc vm.network.change -vm "$name" -net "$net" ethernet-0 990 assert_success 991 992 # change VM eth0 to use network that includes a '/' in the name 993 run govc device.info -vm "$name" ethernet-0 994 assert_success 995 assert_line "Summary: $net" 996 997 run govc host.portgroup.remove "$net" 998 assert_success 999 } 1000 1001 @test "vm.console" { 1002 esx_env 1003 1004 vm=$(new_empty_vm) 1005 1006 run govc vm.console "$vm" 1007 assert_success 1008 1009 run govc vm.console -wss "$vm" 1010 assert_failure 1011 1012 run govc vm.power -on "$vm" 1013 assert_success 1014 1015 run govc vm.console "$vm" 1016 assert_success 1017 1018 run govc vm.console -wss "$vm" 1019 assert_success 1020 1021 run govc vm.console -capture - "$vm" 1022 assert_success 1023 } 1024 1025 @test "vm.upgrade" { 1026 vcsim_env 1027 1028 vm=$(new_id) 1029 1030 run govc vm.create -on=false -version 0.5 "$vm" 1031 assert_failure 1032 1033 run govc vm.create -on=false -version 5.5 "$vm" 1034 assert_success 1035 1036 run govc object.collect -s "vm/$vm" config.version 1037 assert_success "vmx-10" 1038 1039 run govc vm.upgrade -vm "$vm" 1040 assert_success 1041 1042 version=$(govc object.collect -s "vm/$vm" config.version) 1043 [[ "$version" > "vmx-10" ]] 1044 1045 run govc vm.upgrade -vm "$vm" 1046 assert_failure 1047 1048 run govc vm.create -on=false -version vmx-11 "$(new_id)" 1049 assert_success 1050 } 1051 1052 @test "vm.markastemplate" { 1053 vcsim_env 1054 1055 id=$(new_id) 1056 1057 run govc vm.create -on=true "$id" 1058 assert_success 1059 1060 run govc vm.change -vm "$id" -e testing=123 1061 assert_success 1062 1063 run govc vm.markastemplate "$id" 1064 assert_failure 1065 1066 run govc vm.power -off "$id" 1067 assert_success 1068 1069 run govc vm.markasvm "$id" 1070 assert_failure # already a vm 1071 1072 run govc vm.markastemplate "$id" 1073 assert_success 1074 1075 run govc vm.markastemplate "$id" 1076 assert_failure # already a template 1077 1078 run govc vm.change -vm "$id" -e testing=456 1079 assert_failure # template reconfigure only allows name and annotation change 1080 1081 run govc vm.change -vm "$id" -annotation testing123 1082 assert_success 1083 1084 run govc vm.power -on "$id" 1085 assert_failure 1086 1087 run govc vm.clone -vm "$id" -on=false new-vm 1088 assert_success 1089 1090 run govc vm.markasvm "$id" 1091 assert_success 1092 } 1093 1094 @test "vm.option.info" { 1095 vcsim_env 1096 1097 run govc vm.option.info -host "$GOVC_HOST" 1098 assert_success 1099 1100 run govc vm.option.info -cluster "$(dirname "$GOVC_HOST")" 1101 assert_success 1102 1103 run govc vm.option.info -vm DC0_H0_VM0 1104 assert_success 1105 1106 family=$(govc vm.option.info -json ubuntu64Guest | jq -r .guestOSDescriptor[].family) 1107 assert_equal linuxGuest "$family" 1108 1109 family=$(govc vm.option.info -json windows8_64Guest | jq -r .guestOSDescriptor[].family) 1110 assert_equal windowsGuest "$family" 1111 1112 run govc vm.option.info enoent 1113 assert_success # returns the entire simulator.GuestID list 1114 [ ${#lines[@]} -ge 100 ] 1115 } 1116 1117 @test "vm.target.info" { 1118 vcsim_env 1119 1120 run govc vm.target.info -host "$GOVC_HOST" 1121 assert_success 1122 1123 run govc vm.target.info -cluster "$(dirname "$GOVC_HOST")" 1124 assert_success 1125 1126 run govc vm.target.info -vm DC0_H0_VM0 1127 assert_success 1128 1129 run govc vm.target.info -json 1130 assert_success 1131 } 1132 1133 @test "vm.customize" { 1134 vcsim_env 1135 1136 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.42 -netmask 255.255.0.0 vcsim-linux-static 1137 assert_failure # power must be off 1138 1139 run govc vm.power -off DC0_H0_VM0 1140 assert_success 1141 1142 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.42 -netmask 255.255.0.0 vcsim-linux-static 1143 assert_success 1144 1145 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.42 -netmask 255.255.0.0 vcsim-linux-static 1146 assert_failure # pending customization 1147 1148 run govc vm.power -on DC0_H0_VM0 1149 assert_success 1150 1151 run govc object.collect -s vm/DC0_H0_VM0 guest.ipAddress 1152 assert_success 10.0.0.42 1153 1154 run govc object.collect -s vm/DC0_H0_VM0 guest.hostName 1155 assert_success vcsim-1 1156 1157 run govc vm.power -off DC0_H0_VM0 1158 assert_success 1159 1160 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 1161 assert_success 1162 1163 run govc vm.power -on DC0_H0_VM0 1164 assert_success 1165 1166 run govc object.collect -s vm/DC0_H0_VM0 guest.ipAddress 1167 assert_success 10.0.0.43 1168 1169 run govc object.collect -s vm/DC0_H0_VM0 summary.guest.ipAddress 1170 assert_success 10.0.0.43 1171 1172 run govc object.collect -s vm/DC0_H0_VM0 summary.guest.hostName 1173 assert_success windoze 1174 1175 run govc vm.info DC0_H0_VM0 1176 assert_success 1177 assert_matches 10.0.0.43 1178 1179 run govc object.collect -s vm/DC0_H0_VM0 guest.hostName 1180 assert_success windoze 1181 1182 run govc vm.power -off DC0_H0_VM0 1183 assert_success 1184 1185 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.44 -netmask 255.255.0.0 -type Windows 1186 assert_success 1187 1188 run govc vm.power -on DC0_H0_VM0 1189 assert_success 1190 1191 run govc object.collect -s vm/DC0_H0_VM0 guest.ipAddress 1192 assert_success 10.0.0.44 1193 1194 run govc vm.power -off DC0_H0_VM0 1195 assert_success 1196 1197 run govc vm.customize -vm DC0_H0_VM0 -type Linux 1198 assert_failure # no -ip specified 1199 1200 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 1201 assert_success 1202 1203 run govc vm.power -on DC0_H0_VM0 1204 assert_success 1205 1206 run govc object.collect -s vm/DC0_H0_VM0 guest.ipAddress 1207 assert_success 10.0.0.45 1208 1209 host=$(govc ls -L "$(govc object.collect -s vm/DC0_H0_VM0 runtime.host)") 1210 run govc host.maintenance.enter "$host" 1211 assert_success 1212 1213 run govc vm.power -off DC0_H0_VM0 1214 assert_success 1215 1216 run govc vm.power -on DC0_H0_VM0 1217 assert_failure # InvalidState 1218 1219 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.45 -netmask 255.255.0.0 -type Linux 1220 assert_failure # InvalidState 1221 1222 run govc host.maintenance.exit "$host" 1223 assert_success 1224 1225 run govc vm.customize -vm DC0_H0_VM0 -ip 10.0.0.45 -netmask 255.255.0.0 -type Linux 1226 assert_success 1227 }