Fix the dependency issue (#231)

This commit is contained in:
Robbie Zhang
2018-06-21 12:09:42 -07:00
committed by GitHub
parent 027b76651d
commit 6ec1098bb8
16629 changed files with 74837 additions and 4975021 deletions

View File

@@ -1,2 +0,0 @@
.vagrant
govc_ca.*

View File

@@ -1,59 +0,0 @@
# Functional tests for govc
The govc tests use [bats](https://github.com/sstephenson/bats/)
## Download test images
Some tests depend on ttylinux images, these can be downloaded by running:
```
./images/update.sh
```
These images are uploaded to the `$GOVC_TEST_URL` as needed by tests and can be
removed with the following command:
```
./clean.sh
```
## GOVC_TEST_URL
Some of the govc tests need an ESX instance to run against. Any ESX box can be used by exporting the following variable:
```
export GOVC_TEST_URL=user:pass@hostname
```
## Running tests
Tests can be run using the top-level Makefile:
```
make govc-test
```
Or the following command:
```
bats .
```
Or individually, for example:
```
./cli.bats
```
Note that the test helper prepends `$GOPATH/bin` to `PATH` as the tests depend on both the *govc* and *vcsim* binaries.
## Platform specific notes
### Darwin (MacOSX)
Install gxargs, greadlink and gmktemp on Darwin
```
brew install coreutils
brew install findutils
```

View File

@@ -1,74 +0,0 @@
#!/bin/bash -e
# This test is not run via bats.
# A VNC session will be opened to observe the VM boot order:
# 1) from floppy (followed by: eject floppy, reboot)
# 2) from cdrom (followed by: eject cdrom, reboot)
# 3) from network (will timeout)
# 4) from disk
. $(dirname $0)/test_helper.bash
upload_img
upload_iso
id=$(new_ttylinux_vm)
function cleanup() {
quit_vnc $vnc
govc vm.destroy $id
pkill -TERM -g $$ ^nc
}
trap cleanup EXIT
govc device.cdrom.add -vm $id > /dev/null
govc device.cdrom.insert -vm $id $GOVC_TEST_ISO
govc device.floppy.add -vm $id > /dev/null
govc device.floppy.insert -vm $id $GOVC_TEST_IMG
govc device.boot -vm $id -delay 1000 -order floppy,cdrom,ethernet,disk
vnc=$(govc vm.vnc -port 21122 -password govmomi -enable "${id}" | awk '{print $2}')
echo "booting from floppy..."
govc vm.power -on $id
open_vnc $vnc
sleep 10
govc vm.power -off $id
govc device.floppy.eject -vm $id
# this is ttylinux-live, notice the 'boot:' prompt vs 'login:' prompt when booted from disk
echo "booting from cdrom..."
govc vm.power -on $id
sleep 10
govc vm.power -off $id
govc device.cdrom.eject -vm $id
govc device.serial.add -vm $id > /dev/null
govc device.serial.connect -vm $id -
echo "booting from network, will timeout then boot from disk..."
govc vm.power -on $id
# serial console log
device=$(govc device.ls -vm "$id" | grep serialport- | awk '{print $1}')
govc datastore.tail -f "$id/$device.log" &
ip=$(govc vm.ip $id)
echo "VM booted from disk (ip=$ip)"
sleep 5
govc vm.power -s $id
sleep 5

View File

@@ -1,25 +0,0 @@
#!/bin/bash
#
# Cleanup any artifacts created by govc
#
. $(dirname $0)/test_helper.bash
teardown
datastore_rm() {
name=$1
govc datastore.rm $name 2> /dev/null
}
datastore_rm $GOVC_TEST_IMG
datastore_rm $GOVC_TEST_ISO
datastore_rm $GOVC_TEST_VMDK
datastore_rm $(echo $GOVC_TEST_VMDK | sed 's/.vmdk/-flat.vmdk/')
datastore_rm $(dirname $GOVC_TEST_VMDK)
# Recursively destroy all resource pools created by the test suite
govc ls host/*/Resources/govc-test-* | \
xargs -rt govc pool.destroy -r
govc datastore.ls

View File

@@ -1,153 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "about" {
vcsim_env -esx
run govc about
assert_success
assert_line "Vendor: VMware, Inc."
run env GOVC_TLS_HANDSHAKE_TIMEOUT=10s govc about
assert_success
assert_line "Vendor: VMware, Inc."
run env GOVC_TLS_HANDSHAKE_TIMEOUT=NOT_A_DURATION govc about
assert_failure
run govc about -json
assert_success
run govc about -json -l
assert_success
run govc about -dump
assert_success
run govc about -dump -l
assert_success
}
@test "about.cert" {
vcsim_env -esx
run govc about.cert
assert_success
run govc about.cert -json
assert_success
run govc about.cert -show
assert_success
# with -k=true we get thumbprint output and exit 0
thumbprint=$(govc about.cert -k=true -thumbprint)
# with -k=true we get thumbprint output and exit 60
run govc about.cert -k=false -thumbprint
if [ "$status" -ne 60 ]; then
flunk $(printf "expected failed exit status=60, got status=%d" $status)
fi
assert_output "$thumbprint"
run govc about -k=false
assert_failure
run govc about -k=false -tls-known-hosts <(echo "$thumbprint")
assert_success
run govc about -k=false -tls-known-hosts <(echo "nope nope")
assert_failure
}
@test "version" {
vcsim_env -esx
run govc version
assert_success
v=$(govc version | awk '{print $NF}')
run govc version -require "$v"
assert_success
run govc version -require "not-a-version-string"
assert_failure
run govc version -require 100.0.0
assert_failure
}
@test "login attempt without credentials" {
vcsim_env -esx
host=$(govc env -x GOVC_URL_HOST)
port=$(govc env -x GOVC_URL_PORT)
run govc about -u "enoent@$host:$port"
assert_failure "govc: ServerFaultCode: Login failure"
}
@test "login attempt with GOVC_URL, GOVC_USERNAME, and GOVC_PASSWORD" {
vcsim_env -esx
govc_url_to_vars
run govc about
assert_success
}
@test "API version check" {
vcsim_env -esx
run env GOVC_MIN_API_VERSION=24.4 govc about
assert grep -q "^govc: Require API version \"24.4\"," <<<"${output}"
run env GOVC_MIN_API_VERSION=no.no govc about
assert_failure
run env GOVC_MIN_API_VERSION=- govc about
assert_success
run env GOVC_MIN_API_VERSION=5.0 govc about
assert_success
run govc about -vim-namespace urn:vim25 -vim-version 6.0
assert_success
}
@test "govc env" {
output="$(govc env -x -u 'user:pass@enoent:99999?key=val#anchor')"
assert grep -q GOVC_URL=enoent:99999 <<<${output}
assert grep -q GOVC_USERNAME=user <<<${output}
assert grep -q GOVC_PASSWORD=pass <<<${output}
assert grep -q GOVC_URL_SCHEME=https <<<${output}
assert grep -q GOVC_URL_HOST=enoent <<<${output}
assert grep -q GOVC_URL_PORT=99999 <<<${output}
assert grep -q GOVC_URL_PATH=/sdk <<<${output}
assert grep -q GOVC_URL_QUERY=key=val <<<${output}
assert grep -q GOVC_URL_FRAGMENT=anchor <<<${output}
password="pa\$sword!ok"
run govc env -u "user:${password}@enoent:99999" GOVC_PASSWORD
assert_output "$password"
}
@test "govc help" {
run govc
assert_failure
run govc -h
assert_success
run govc -enoent
assert_failure
run govc vm.create
assert_failure
run govc vm.create -h
assert_success
run govc vm.create -enoent
assert_failure
}

View File

@@ -1,160 +0,0 @@
#!/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.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"
}
@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 -name pod1
assert_success "$(printf "%s\n" DC0_C0_RP0_VM{0,1,2,3})"
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.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
}
@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" ]
# 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" ]
run govc cluster.override.remove -vm DC0_C0_RP0_VM0
assert_success
run govc cluster.override.info
assert_success "" # no overrides == empty output
run govc cluster.override.change -vm DC0_C0_RP0_VM0 -drs-mode=manual
assert_success
run govc cluster.override.remove -vm DC0_C0_RP0_VM0
assert_success
}

View File

@@ -1,53 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "datacenter.info" {
vcsim_env -esx
dc=$(govc ls -t Datacenter / | head -n1)
run govc datacenter.info "$dc"
assert_success
run govc datacenter.info -json "$dc"
assert_success
run govc datacenter.info /enoent
assert_failure
}
@test "datacenter.create" {
vcsim_env
unset GOVC_DATACENTER
# name not specified
run govc datacenter.create
assert_failure
dcs=($(new_id) $(new_id))
run govc datacenter.create "${dcs[@]}"
assert_success
for dc in ${dcs[*]}; do
run govc ls "/$dc"
assert_success
# /<datacenter>/{vm,network,host,datastore}
[ ${#lines[@]} -eq 4 ]
run govc datacenter.info "/$dc"
assert_success
done
run govc object.destroy "/$dc"
assert_success
}
@test "datacenter commands fail against ESX" {
vcsim_env -esx
run govc datacenter.create something
assert_failure
run govc object.destroy /ha-datacenter
assert_failure
}

View File

@@ -1,370 +0,0 @@
#!/usr/bin/env bats
load test_helper
upload_file() {
name=$(new_id)
echo "Hello world" | govc datastore.upload - "$name"
assert_success
echo "$name"
}
@test "datastore.ls" {
vcsim_env -esx
name=$(upload_file)
# Single argument
run govc datastore.ls "${name}"
assert_success
[ ${#lines[@]} -eq 1 ]
# Multiple arguments
run govc datastore.ls "${name}" "${name}"
assert_success
[ ${#lines[@]} -eq 2 ]
# Pattern argument
run govc datastore.ls "./govc-test-*"
assert_success
[ ${#lines[@]} -ge 1 ]
# Long listing
run govc datastore.ls -l "./govc-test-*"
assert_success
assert_equal "12B" $(awk '{ print $1 }' <<<${output})
}
@test "datastore.ls-R" {
esx_env
dir=$(new_id)
run govc datastore.mkdir "$dir"
assert_success
for name in one two three ; do
echo "$name world" | govc datastore.upload - "$dir/file-$name"
run govc datastore.mkdir -p "$dir/dir-$name/subdir-$name"
run govc datastore.mkdir -p "$dir/dir-$name/.hidden"
assert_success
echo "$name world" | govc datastore.upload - "$dir/dir-$name/.hidden/other-$name"
echo "$name world" | govc datastore.upload - "$dir/dir-$name/other-$name"
echo "$name world" | govc datastore.upload - "$dir/dir-$name/subdir-$name/last-$name"
done
# without -R
json=$(govc datastore.ls -json -l -p "$dir")
result=$(jq -r .[].File[].Path <<<"$json" | wc -l)
[ "$result" -eq 6 ]
result=$(jq -r .[].FolderPath <<<"$json" | wc -l)
[ "$result" -eq 1 ]
# with -R
json=$(govc datastore.ls -json -l -p -R "$dir")
result=$(jq -r .[].File[].Path <<<"$json" | wc -l)
[ "$result" -eq 15 ]
result=$(jq -r .[].FolderPath <<<"$json" | wc -l)
[ "$result" -eq 7 ]
# with -R -a
json=$(govc datastore.ls -json -l -p -R -a "$dir")
result=$(jq -r .[].File[].Path <<<"$json" | wc -l)
[ "$result" -eq 21 ]
result=$(jq -r .[].FolderPath <<<"$json" | wc -l)
[ "$result" -eq 10 ]
}
@test "datastore.rm" {
vcsim_env -esx
name=$(upload_file)
# Not found is a failure
run govc datastore.rm "${name}.notfound"
assert_failure
# Not found is NOT a failure with the force flag
run govc datastore.rm -f "${name}.notfound"
assert_success
assert_empty "${output}"
# Verify the file is present
run govc datastore.ls "${name}"
assert_success
# Delete the file
run govc datastore.rm "${name}"
assert_success
assert_empty "${output}"
# Verify the file is gone
run govc datastore.ls "${name}"
assert_failure
}
@test "datastore.info" {
vcsim_env -esx
run govc datastore.info enoent
assert_failure
run govc datastore.info
assert_success
[ ${#lines[@]} -gt 1 ]
}
@test "datastore.mkdir" {
vcsim_env -esx
name=$(new_id)
# Not supported datastore type is a failure
run govc datastore.mkdir -namespace "notfound"
assert_failure
assert_matches "govc: ServerFaultCode: .*" "${output}"
run govc datastore.mkdir "${name}"
assert_success
assert_empty "${output}"
# Verify the dir is present
run govc datastore.ls "${name}"
assert_success
# Delete the dir on an unsupported datastore type is a failure
run govc datastore.rm -namespace "${name}"
assert_failure
assert_matches "govc: ServerFaultCode: .*" "${output}"
# Delete the dir
run govc datastore.rm "${name}"
assert_success
assert_empty "${output}"
# Verify the dir is gone
run govc datastore.ls "${name}"
assert_failure
}
@test "datastore.download" {
vcsim_env -esx
name=$(upload_file)
run govc datastore.download "$name" -
assert_success
assert_output "Hello world"
run govc datastore.download "$name" "$BATS_TMPDIR/$name"
assert_success
run cat "$BATS_TMPDIR/$name"
assert_output "Hello world"
rm "$BATS_TMPDIR/$name"
}
@test "datastore.upload" {
esx_env
name=$(new_id)
echo -n "Hello world" | govc datastore.upload - "$name"
run govc datastore.download "$name" -
assert_success
assert_output "Hello world"
}
@test "datastore.tail" {
esx_env
run govc datastore.tail "enoent/enoent.log"
assert_failure
id=$(new_id)
govc vm.create "$id"
govc vm.power -off "$id"
# test with .log (> bufSize) and .vmx (< bufSize)
for file in "$id/vmware.log" "$id/$id.vmx" ; do
log=$(govc datastore.download "$file" -)
for n in 0 1 5 10 123 456 7890 ; do
expect=$(tail -n $n <<<"$log")
run govc datastore.tail -n $n "$file"
assert_output "$expect"
expect=$(tail -c $n <<<"$log")
run govc datastore.tail -c $n "$file"
assert_output "$expect"
done
done
}
@test "datastore.disk" {
esx_env
id=$(new_id)
vmdk="$id/$id.vmdk"
run govc datastore.mkdir "$id"
assert_success
run govc datastore.disk.create "$vmdk"
assert_success
run govc datastore.disk.info "$vmdk"
assert_success
run govc datastore.rm "$vmdk"
assert_success
run govc datastore.mkdir -p "$id"
assert_success
run govc datastore.disk.create "$vmdk"
assert_success
id=$(new_id)
run govc vm.create -on=false -link -disk "$vmdk" "$id"
assert_success
run govc datastore.disk.info -d "$vmdk"
assert_success
run govc datastore.disk.info -p=false "$vmdk"
assert_success
run govc datastore.disk.info -c "$vmdk"
assert_success
run govc datastore.disk.info -json "$vmdk"
assert_success
# should fail due to: ddb.deletable=false
run govc datastore.rm "$vmdk"
assert_failure
run govc datastore.rm -f "$vmdk"
assert_success
# one more time, but rm the directory w/o -f
run govc datastore.mkdir -p "$id"
assert_success
run govc datastore.disk.create "$vmdk"
assert_success
id=$(new_id)
run govc vm.create -on=false -link -disk "$vmdk" "$id"
assert_success
run govc datastore.rm "$(dirname "$vmdk")"
assert_success
}
@test "datastore.cp" {
vcsim_env -dc 2 -ds 2
id=$(new_id)
vmdk="$id/$id.vmdk"
# GOVC_DATACENTER and GOVC_DATACENTER are set during these tests
run govc datastore.mkdir "$id"
assert_success
run govc datastore.disk.create "$vmdk"
assert_success
clone="$id/$id-2.vmdk"
run govc datastore.cp "$vmdk" "$clone"
assert_success
# Specifying -dc and -ds flags in the tests below
unset GOVC_DATASTORE GOVC_DATACENTER
run govc datastore.ls -dc DC0 -ds LocalDS_0 "$clone"
assert_success # created this file above
run govc datastore.ls -dc DC0 -ds LocalDS_1 "$clone"
assert_failure # should not exist in DS_1
run govc datastore.ls -dc DC1 -ds LocalDS_1 "$clone"
assert_failure # should not exist in DC1 DS_1
run govc datastore.mkdir -dc DC1 -ds LocalDS_1 "$id"
assert_success
for op in cp mv ; do
run govc datastore.ls -dc DC1 -ds LocalDS_0 "$clone"
assert_failure # should not exist in DC1 DS_0
# From DC0 DS_0 to DC1 DS_1
run govc datastore.$op -dc DC0 -ds LocalDS_0 -dc-target DC1 -ds-target LocalDS_1 "$clone" "$clone"
assert_success
run govc datastore.ls -dc DC1 -ds LocalDS_1 "$clone"
assert_success # now the file exists
run govc datastore.rm -dc DC1 -ds LocalDS_1 "$clone"
assert_success
done
}
@test "datastore.disk.info" {
esx_env
import_ttylinux_vmdk
run govc datastore.disk.info
assert_failure
run govc datastore.disk.info enoent
assert_failure
run govc datastore.disk.info "$GOVC_TEST_VMDK"
assert_success
run govc datastore.disk.info -d "$GOVC_TEST_VMDK"
assert_success
run govc datastore.disk.info -c "$GOVC_TEST_VMDK"
assert_success
}
@test "datastore.disk.inflate" {
esx_env
id=$(new_id)
vmdk="$id/$id.vmdk"
run govc datastore.mkdir "$id"
assert_success
run govc datastore.disk.create -size 10MB "$vmdk"
assert_success
type=$(govc datastore.disk.info -json "$vmdk" | jq -r .[].DiskType)
[ "$type" = "thin" ]
run govc datastore.disk.inflate "$vmdk"
assert_success
type=$(govc datastore.disk.info -json "$vmdk" | jq -r .[].DiskType)
[ "$type" = "eagerZeroedThick" ]
run govc datastore.disk.shrink "$vmdk"
assert_success
run govc datastore.disk.shrink -copy "$vmdk"
assert_success
run govc datastore.disk.shrink -copy=false "$vmdk"
assert_success
}

View File

@@ -1,102 +0,0 @@
#!/bin/bash -e
# This test is not run via bats
# See also: datastore.bats@test "datastore.disk"
export GOVC_TEST_URL=$GOVC_URL
. "$(dirname "$0")"/test_helper.bash
echo -n "checking datastore type..."
type=$(govc object.collect -s "datastore/$GOVC_DATASTORE" summary.type)
echo "$type"
if [ "$type" = "vsan" ] ; then
echo -n "checking for orphan objects..."
objs=($(govc datastore.vsan.dom.ls -o))
echo "${#objs[@]}"
if [ "${#objs[@]}" -ne "0" ] ; then
govc datastore.vsan.dom.rm "${objs[@]}"
fi
fi
dir=govc-test-dfm
echo "uploading plain file..."
cal | govc datastore.upload - $dir/cal.txt
echo "removing plain file..."
govc datastore.rm $dir/cal.txt
scratch=$dir/govc-test-scratch/govc-test-scratch.vmdk
govc datastore.mkdir -p "$(dirname $scratch)"
echo "creating disk $scratch..."
govc datastore.disk.create -size 1M $scratch
id=$(new_id)
echo "creating $id VM with disk linked to $scratch..."
govc vm.create -on=false -link -disk $scratch "$id"
info=$(govc device.info -vm "$id" disk-*)
echo "$info"
disk="$(grep Name: <<<"$info" | awk '{print $2}')"
vmdk="$id/$id.vmdk"
echo "removing $disk device but keeping the .vmdk backing file..."
govc device.remove -vm "$id" -keep "$disk"
echo -n "checking delta disk ddb.deletable..."
govc datastore.download "$vmdk" - | grep -q -v ddb.deletable
echo "yes"
echo -n "checking scratch disk ddb.deletable..."
govc datastore.download "$scratch" - | grep ddb.deletable | grep -q false
echo "no"
echo "removing $vmdk"
govc datastore.rm "$vmdk"
echo -n "checking that rm $scratch fails..."
govc datastore.rm "$scratch" 2>/dev/null || echo "yes"
echo -n "checking that rm -f $scratch deletes..."
govc datastore.rm -f "$scratch" && echo "yes"
echo "removing disk Directory via FileManager..."
govc datastore.mkdir -p "$(dirname $scratch)"
govc datastore.disk.create -size 1M $scratch
govc datastore.rm "$(dirname $scratch)"
echo -n "checking for remaining files..."
govc datastore.ls -p -R $dir
teardown
status=0
if [ "$type" = "vsan" ] ; then
echo -n "checking for leaked objects..."
objs=($(govc datastore.vsan.dom.ls -l -o | awk '{print $3}'))
echo "${#objs[@]}"
if [ "${#objs[@]}" -ne "0" ] ; then
printf "%s\n" "${objs[@]}"
status=1
else
# this is expected to leak on vSAN currently
echo -n "checking if FileManager.Delete still leaks..."
govc datastore.mkdir -p "$(dirname $scratch)"
govc datastore.disk.create -size 1M $scratch
# '-t=false' forces use of FileManager instead of VirtualDiskManager
govc datastore.rm -t=false $scratch
govc datastore.rm $dir
govc datastore.vsan.dom.ls -o | xargs -r govc datastore.vsan.dom.rm -v
fi
fi
exit $status

View File

@@ -1,26 +0,0 @@
#!/bin/bash -xe
# This test is not run via bats as the bats pipeline hangs when we background a process
. "$(dirname "$0")"/test_helper.bash
name=$(new_id)
n=16
tmp=$(mktemp --tmpdir "${name}-XXXXX")
echo -n | govc datastore.upload - "$name"
govc datastore.tail -f "$name" > "$tmp" &
pid=$!
sleep 1
yes | dd bs=${n}K count=1 2>/dev/null | govc datastore.upload - "$name"
sleep 2
# stops following when the file has gone away
govc datastore.mv "$name" "${name}.old"
wait $pid
govc datastore.download "${name}.old" - | cmp "$tmp" -
rm "$tmp"
teardown

View File

@@ -1,319 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "device.ls" {
esx_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep ethernet-0 | wc -l)
[ $result -eq 1 ]
}
@test "device.info" {
esx_env
vm=$(new_empty_vm)
run govc device.info -vm $vm ide-200
assert_success
run govc device.info -vm $vm ide-20000
assert_failure
run govc device.info -vm $vm -net enoent
assert_failure
run govc device.info -vm $vm -net "VM Network" ide-200
assert_failure
result=$(govc device.info -vm $vm -net "VM Network" | grep "MAC Address" | wc -l)
[ $result -eq 1 ]
run govc device.info -vm $vm -json
assert_matches ethernet-0
assert_matches '"Name":' # injected field
assert_matches '"Type":' # injected field
}
@test "device.boot" {
esx_env
vm=$(new_ttylinux_vm)
result=$(govc device.ls -vm $vm -boot | wc -l)
[ $result -eq 0 ]
run govc device.boot -vm $vm -order floppy,cdrom,ethernet,disk
assert_success
result=$(govc device.ls -vm $vm -boot | wc -l)
[ $result -eq 2 ]
run govc device.cdrom.add -vm $vm
assert_success
run govc device.floppy.add -vm $vm
assert_success
run govc device.boot -vm $vm -order floppy,cdrom,ethernet,disk
assert_success
result=$(govc device.ls -vm $vm -boot | wc -l)
[ $result -eq 4 ]
run govc device.boot -vm $vm -order -
assert_success
result=$(govc device.ls -vm $vm -boot | wc -l)
[ $result -eq 0 ]
}
@test "device.cdrom" {
esx_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep cdrom- | wc -l)
[ $result -eq 0 ]
run govc device.cdrom.add -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
run govc device.info -vm $vm $id
assert_success
run govc device.cdrom.insert -vm $vm -device $id x.iso
assert_success
run govc device.info -vm $vm $id
assert_line "Summary: ISO [${GOVC_DATASTORE}] x.iso"
run govc device.disconnect -vm $vm $id
assert_success
run govc device.connect -vm $vm $id
assert_success
run govc device.remove -vm $vm $id
assert_success
run govc device.disconnect -vm $vm $id
assert_failure "govc: device '$id' not found"
run govc device.cdrom.insert -vm $vm -device $id x.iso
assert_failure "govc: device '$id' not found"
run govc device.remove -vm $vm $id
assert_failure "govc: device '$id' not found"
}
@test "device.floppy" {
esx_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep floppy- | wc -l)
[ $result -eq 0 ]
run govc device.floppy.add -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
run govc device.info -vm $vm $id
assert_success
run govc device.floppy.insert -vm $vm -device $id x.img
assert_success
run govc device.info -vm $vm $id
assert_line "Summary: Image [${GOVC_DATASTORE}] x.img"
run govc device.disconnect -vm $vm $id
assert_success
run govc device.connect -vm $vm $id
assert_success
run govc device.remove -vm $vm $id
assert_success
run govc device.disconnect -vm $vm $id
assert_failure "govc: device '$id' not found"
run govc device.floppy.insert -vm $vm -device $id x.img
assert_failure "govc: device '$id' not found"
run govc device.remove -vm $vm $id
assert_failure "govc: device '$id' not found"
}
@test "device.serial" {
esx_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep serial- | wc -l)
[ $result -eq 0 ]
run govc device.serial.add -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
run govc device.info -vm $vm $id
assert_success
run govc device.serial.connect -vm $vm -
assert_success
run govc device.info -vm $vm $id
assert_line "Summary: File [$GOVC_DATASTORE] $vm/${id}.log"
uri=telnet://:33233
run govc device.serial.connect -vm $vm -device $id $uri
assert_success
run govc device.info -vm $vm $id
assert_line "Summary: Remote $uri"
run govc device.serial.disconnect -vm $vm -device $id
assert_success
run govc device.info -vm $vm $id
assert_line "Summary: Remote localhost:0"
run govc device.disconnect -vm $vm $id
assert_success
run govc device.connect -vm $vm $id
assert_success
run govc device.remove -vm $vm $id
assert_success
run govc device.disconnect -vm $vm $id
assert_failure "govc: device '$id' not found"
run govc device.serial.connect -vm $vm -device $id $uri
assert_failure "govc: device '$id' not found"
run govc device.remove -vm $vm $id
assert_failure "govc: device '$id' not found"
}
@test "device.scsi" {
esx_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep lsilogic- | wc -l)
[ $result -eq 1 ]
run govc device.scsi.add -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
result=$(govc device.ls -vm $vm | grep lsilogic- | wc -l)
[ $result -eq 2 ]
run govc device.scsi.add -vm $vm -type pvscsi
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
}
@test "device.usb" {
esx_env
vm=$(new_empty_vm)
result=$(govc device.ls -vm $vm | grep usb | wc -l)
[ $result -eq 0 ]
run govc device.usb.add -type enoent -vm $vm
assert_failure
run govc device.usb.add -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
run govc device.usb.add -vm $vm
assert_failure # 1 per vm max
run govc device.usb.add -type xhci -vm $vm
assert_success
id=$output
result=$(govc device.ls -vm $vm | grep $id | wc -l)
[ $result -eq 1 ]
run govc device.usb.add -type xhci -vm $vm
assert_failure # 1 per vm max
}
@test "device.scsi slots" {
esx_env
vm=$(new_empty_vm)
for i in $(seq 1 15) ; do
name="disk-${i}"
run govc vm.disk.create -vm "$vm" -name "$name" -size 1K
assert_success
result=$(govc device.ls -vm "$vm" | grep disk- | wc -l)
[ "$result" -eq "$i" ]
done
# We're at the max, so this will fail
run govc vm.disk.create -vm "$vm" -name disk-16 -size 1K
assert_failure
# Remove disk #2
run govc device.remove -vm "$vm" disk-1000-2
assert_success
# No longer at the max, this should use the UnitNumber released by the remove above
run govc vm.disk.create -vm "$vm" -name disk-16 -size 1K
assert_success
}
@test "device nil config" {
esx_env
vm=$(new_empty_vm)
run govc device.ls -vm "$vm"
assert_success
run govc datastore.rm "$vm"
assert_success
run govc object.reload "vm/$vm"
assert_success
run govc device.ls -vm "$vm"
assert_failure
run govc vm.unregister "$vm"
assert_success
}

View File

@@ -1,49 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "network vm list" {
esx_env
# make sure there's at least 1 VM so we get a table header to count against
vm=$(new_empty_vm)
govc vm.power -on $vm
nlines=$(govc host.esxcli network vm list | wc -l)
vm=$(new_empty_vm)
govc vm.power -on $vm
xlines=$(govc host.esxcli network vm list | wc -l)
# test that we see a new row
[ $(($nlines + 1)) -eq $xlines ]
run govc host.esxcli network vm list enoent
assert_failure
}
@test "network ip connection list" {
esx_env
run govc host.esxcli -- network ip connection list -t tcp
assert_success
# test that we get the expected number of table columns
nf=$(echo "${lines[3]}" | awk '{print NF}')
[ $nf -eq 9 ]
run govc host.esxcli -- network ip connection list -t enoent
assert_failure
}
@test "system settings advanced list" {
esx_env
run govc host.esxcli -- system settings advanced list -o /Net/GuestIPHack
assert_success
assert_line "Path: /Net/GuestIPHack"
run govc host.esxcli -- system settings advanced list -o /Net/ENOENT
assert_failure
}

View File

@@ -1,88 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "events dc" {
esx_env
run govc events
assert_success
nevents=${#lines[@]}
# there should be plenty more than 1 event at the top (dc) level
[ $nevents -ge 1 ]
# test -n flag
run govc events -n $((nevents - 1))
assert_success
[ ${#lines[@]} -le $nevents ]
}
@test "events host" {
esx_env
run govc events 'host/*'
assert_success
[ ${#lines[@]} -ge 1 ]
}
@test "events vm" {
esx_env
vm=$(new_id)
run govc vm.create -on=false $vm
assert_success
run govc events vm/$vm
assert_success
nevents=${#lines[@]}
[ $nevents -gt 1 ]
# glob should have same # of events
run govc events vm/${vm}*
assert_success
[ ${#lines[@]} -eq $nevents ]
# create a new vm, glob should match more events
run govc vm.create -on=false "${vm}-2"
assert_success
run govc events vm/${vm}*
assert_success
[ ${#lines[@]} -gt $nevents ]
nevents=${#lines[@]}
run govc events vm
assert_success
[ ${#lines[@]} -ge $nevents ]
run govc events -type VmPoweredOffEvent -type VmPoweredOnEvent "vm/$vm"
[ ${#lines[@]} -eq 0 ]
run govc vm.power -on "$vm"
assert_success
run govc events -type VmPoweredOffEvent -type VmPoweredOnEvent "vm/$vm"
[ ${#lines[@]} -eq 1 ]
run govc vm.power -off "$vm"
assert_success
run govc events -type VmPoweredOffEvent -type VmPoweredOnEvent "vm/$vm"
[ ${#lines[@]} -eq 2 ]
}
@test "events json" {
esx_env
# make sure we fmt.Printf properly
govc events | grep -v '%!s(MISSING)'
govc events -json | jq .
# test multiple objects
govc vm.create "$(new_id)"
govc vm.create "$(new_id)"
govc events 'vm/*'
govc events -json 'vm/*' | jq .
}

View File

@@ -1,39 +0,0 @@
#!/usr/bin/env bats
load test_helper
# ovftool -tt=ovf --noSSLVerify --skipManifestCheck "vi://$GOVC_URL/$GOVC_VM" .
@test "export.ovf" {
esx_env
id=$(new_ttylinux_vm)
dir=$BATS_TMPDIR/$id-export
run govc export.ovf -vm "$id" "$dir"
assert_success
run ls "$dir/$id/$id-disk-0.vmdk" "$dir/$id/$id.ovf"
assert_success
if [ -e "$dir/$id/$id.mf" ] ; then
flunk ".mf was created"
fi
run govc export.ovf -vm "$id" "$dir"
assert_failure
run govc export.ovf -i -f -sha 256 -vm "$id" "$dir"
assert_success
run ls "$dir/$id/$id.mf"
assert_success
# make it an ova
(cd "$dir/$id" && tar -cf "../$id.ova" .)
# ovftool --noSSLVerify --skipManifestCheck --name="$GOVC_VM-import" "$GOVC_VM/$GOVC_VM.ovf" "vi://$GOVC_URL"
run govc import.ova -name "${id}-import" "$dir/$id.ova"
assert_success
rm -rf "$dir"
}

View File

@@ -1,73 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "extension" {
vcsim_env_todo
govc extension.info | grep Name: | grep govc-test | awk '{print $2}' | $xargs -r govc extension.unregister
run govc extension.info enoent
assert_failure
id=$(new_id)
result=$(govc extension.info | grep $id | wc -l)
[ $result -eq 0 ]
# register extension
run govc extension.register $id <<EOS
{
"Description": {
"Label": "govc",
"Summary": "Go interface to vCenter"
},
"Key": "${id}",
"Company": "VMware, Inc.",
"Version": "0.2.0"
}
EOS
assert_success
# check info output is legit
run govc extension.info $id
assert_line "Name: $id"
json=$(govc extension.info -json $id)
label=$(jq -r .Extensions[].Description.Label <<<"$json")
assert_equal "govc" "$label"
# change label and update extension
json=$(jq -r '.Extensions[] | .Description.Label = "novc"' <<<"$json")
run govc extension.register -update $id <<<"$json"
assert_success
# check label changed in info output
json=$(govc extension.info -json $id)
label=$(jq -r .Extensions[].Description.Label <<<"$json")
assert_equal "novc" "$label"
# set extension certificate to generated certificate
run govc extension.setcert -cert-pem '+' $id
assert_success
# test client certificate authentication
(
# remove password from env, set user to extension id and turn of session cache
govc_url_to_vars
unset GOVC_PASSWORD
GOVC_USERNAME=$id
export GOVC_PERSIST_SESSION=false
run govc about -cert "${id}.crt" -key "${id}.key"
assert_success
)
# remove generated cert and key
rm ${id}.{crt,key}
run govc extension.unregister $id
assert_success
result=$(govc extension.info | grep $id | wc -l)
[ $result -eq 0 ]
}

View File

@@ -1,48 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "fields" {
vcsim_env
vm_id=$(new_id)
run govc vm.create $vm_id
assert_success
field=$(new_id)
result=$(govc fields.ls | grep $field | wc -l)
[ $result -eq 0 ]
key=$(govc fields.add $field)
result=$(govc fields.ls | grep $field | wc -l)
[ $result -eq 1 ]
key=$(govc fields.ls | grep $field | awk '{print $1}')
val="foo"
run govc fields.set $field $val vm/$vm_id
assert_success
info=$(govc vm.info -json $vm_id | jq .VirtualMachines[0].CustomValue[0])
ikey=$(jq -r .Key <<<"$info")
assert_equal $key $ikey
ival=$(jq -r .Value <<<"$info")
assert_equal $val $ival
old_field=$field
field=$(new_id)
run govc fields.rename $key $field
assert_success
result=$(govc fields.ls | grep $old_field | wc -l)
[ $result -eq 0 ]
run govc fields.rm $field
assert_success
result=$(govc fields.ls | grep $field | wc -l)
[ $result -eq 0 ]
}

View File

@@ -1,22 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "firewall.ruleset.find" {
vcsim_env -esx
# Assumes sshServer ruleset is enabled
run govc firewall.ruleset.find -c=false -direction inbound -port 22
assert_success
run govc firewall.ruleset.find -c=false -direction outbound -port 22
if [ "$status" -eq 1 ] ; then
# If outbound port 22 is blocked, we should be able to list disabled rules via:
run govc firewall.ruleset.find -c=false -direction outbound -port 22 -enabled=false
assert_success
# find disabled should include sshClient ruleset in output
result=$(govc firewall.ruleset.find -c=false -direction outbound -port 22 -enabled=false | grep sshClient | wc -l)
[ $result -eq 1 ]
fi
}

View File

@@ -1,76 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "folder.info" {
vcsim_env -esx
for name in / vm host network datastore ; do
run govc folder.info $name
assert_success
govc folder.info -json $name
assert_success
done
result=$(govc folder.info '*' | grep -c Name:)
[ "$result" -eq 4 ]
run govc info.info /enoent
assert_failure
}
@test "folder.create" {
vcsim_env
name=$(new_id)
# relative to $GOVC_DATACENTER
run govc folder.create $name
assert_failure
run govc folder.create vm/$name
assert_success
run govc folder.info vm/$name
assert_success
run govc folder.info /$GOVC_DATACENTER/vm/$name
assert_success
run govc object.destroy vm/$name
assert_success
unset GOVC_DATACENTER
# relative to /
run govc folder.create /$name
assert_success
run govc folder.info /$name
assert_success
child=$(new_id)
run govc folder.create /$child
assert_success
run govc folder.info /$name/$child
assert_failure
run govc object.mv /$child /$name
assert_success
run govc folder.info /$name/$child
assert_success
new=$(new_id)
run govc object.rename /$name $new
assert_success
name=$new
run govc folder.info /$name
assert_success
run govc object.destroy /$name
assert_success
}

View File

@@ -1,119 +0,0 @@
#!/bin/bash -e
# This test is not run via bats.
# 1) Test guest operations (govc guest.* commands)
# 2) Test vm disk persistence
. "$(dirname "$0")"/test_helper.bash
esx_env
import_ttylinux_vmdk
export GOVC_GUEST_LOGIN=root:password
for persist in true false ; do
id=govc-test-persist-$persist
govc ls vm/$id | xargs -r govc vm.destroy
if [ "$persist" = "true" ] ; then
grepf=-v
mode=persistent
else
mode=independent_nonpersistent
fi
echo "Creating vm..."
govc vm.create -m 32 -disk.controller ide -on=false $id
# Save some noise by defaulting to '-vm $id'
export GOVC_VM=$id
echo "Attaching linked disk..."
govc vm.disk.attach -controller ide -persist=$persist -link=true -disk "$GOVC_TEST_VMDK"
echo "Creating data disk..."
govc vm.disk.create -controller ide -mode=$mode -name "$id"/data -size "10M"
echo "Powering on vm..."
govc vm.power -on $id 1>/dev/null
echo "Waiting for tools to initialize..."
govc vm.ip $id 1>/dev/null
echo "Formatting the data disk..."
govc guest.mkdir /data
script=$(govc guest.mktemp)
govc guest.upload -f - "$script" <<'EOF'
#!/bin/sh -xe
opts=(n p 1 1 ' ' w)
printf "%s\n" "${opts[@]}" | fdisk /dev/hdb
mkfs.ext3 /dev/hdb1
mount /dev/hdb1 /data
df -h
cp /etc/motd /data
EOF
govc guest.chown 65534 "$script"
govc guest.chown 65534:65534 "$script"
govc guest.ls "$script" | grep 65534
govc guest.chmod 0755 "$script"
pid=$(govc guest.start "$script" '>&' /tmp/disk.log)
status=$(govc guest.ps -p "$pid" -json -X | jq .ProcessInfo[].ExitCode)
govc guest.download /tmp/disk.log -
if [ "$status" -ne "0" ] ; then
exit 1
fi
echo "Writing some data to the disks..."
for d in /etc /data ; do
govc guest.touch "$d/motd.bak"
govc guest.touch -d "$(date -d '1 day ago')" "$d/motd"
govc guest.ls "$d/motd"
govc guest.download $d/motd - | grep Chop
done
govc version | govc guest.upload -f - /etc/motd
govc guest.download /etc/motd - | grep -v Chop
pid=$(govc guest.start /bin/sync)
status=$(govc guest.ps -p "$pid" -json -X | jq .ProcessInfo[].ExitCode)
if [ "$status" -ne "0" ] ; then
exit 1
fi
echo "Rebooting vm..."
govc vm.power -off $id
govc vm.power -on $id
echo "Waiting for tools to initialize..."
govc vm.ip $id 1>/dev/null
echo "Verifying data persistence..."
govc guest.download /etc/motd - | grep $grepf Chop
pid=$(govc guest.start /bin/mount /dev/hdb1 /data)
status=$(govc guest.ps -p "$pid" -json -X | jq .ProcessInfo[].ExitCode)
if [ "$persist" = "true" ] ; then
govc guest.ls /data
govc guest.download /data/motd - | grep -v Chop
govc guest.rm /data/motd
govc guest.mkdir /data/foo/bar/baz 2>/dev/null && exit 1 # should fail
govc guest.mkdir -p /data/foo/bar/baz
govc guest.rmdir /data/foo 2>/dev/null && exit 1 # should fail
govc guest.rmdir /data/foo/bar/baz
dir=$(govc guest.mktemp -d -p /data/foo -s govc)
file=$(govc guest.mktemp -p "$dir")
govc guest.mv -n "$(govc guest.mktemp)" "$file" 2>/dev/null && exit 1 # should fail
govc guest.mv "$file" "${file}-old"
govc guest.mv "$dir" "${dir}-old"
govc guest.rmdir -r /data/foo
govc guest.ls /data | grep -v foo
else
if [ "$status" -eq "0" ] ; then
echo "expected failure"
exit 1
fi
fi
done

View File

@@ -1,240 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "host info esx" {
esx_env
run govc host.info
assert_success
grep -q Manufacturer: <<<"$output"
run govc host.info -host enoent
assert_failure "govc: host 'enoent' not found"
for opt in dns ip ipath uuid
do
run govc host.info "-host.$opt" enoent
assert_failure "govc: no such host"
done
# avoid hardcoding the esxbox hostname
local name=$(govc ls '/*/host/*' | grep -v Resources)
run govc host.info -host "$name"
assert_success
grep -q Manufacturer: <<<"$output"
run govc host.info -host ${name##*/}
assert_success
grep -q Manufacturer: <<<"$output"
run govc host.info -host.ipath "$name"
assert_success
run govc host.info -host.dns "$(basename $(dirname $name))"
assert_success
uuid=$(govc host.info -json | jq -r .HostSystems[].Hardware.SystemInfo.Uuid)
run govc host.info -host.uuid "$uuid"
assert_success
run govc host.info "*"
assert_success
}
@test "host info vc" {
vcsim_env
run govc host.info
assert_success
grep -q Manufacturer: <<<"$output"
run govc host.info -host enoent
assert_failure "govc: host 'enoent' not found"
for opt in ipath uuid # dns ip # TODO: SearchIndex:SearchIndex does not implement: FindByDnsName
do
run govc host.info "-host.$opt" enoent
assert_failure "govc: no such host"
done
local name=$GOVC_HOST
unset GOVC_HOST
run govc host.info
assert_failure "govc: default host resolves to multiple instances, please specify"
run govc host.info -host "$name"
assert_success
grep -q Manufacturer: <<<"$output"
run govc host.info -host.ipath "$name"
assert_success
run govc host.info -host.dns $(basename "$name")
assert_failure # TODO: SearchIndex:SearchIndex does not implement: FindByDnsName
uuid=$(govc host.info -host "$name" -json | jq -r .HostSystems[].Summary.Hardware.Uuid)
run govc host.info -host.uuid "$uuid"
assert_success
# summary.host should have a reference to the generated moid, not the template esx.HostSystem.Self (ha-host)
govc object.collect -s -type h / summary.host | grep -v ha-host
}
@test "host maintenance vc" {
vcsim_env
run govc host.info
assert_success
grep -q -v Maintenance <<<"$output"
run govc host.maintenance.enter "$GOVC_HOST"
assert_success
run govc host.info
assert_success
grep -q Maintenance <<<"$output"
run govc host.maintenance.exit "$GOVC_HOST"
assert_success
run govc host.info
assert_success
grep -q -v Maintenance <<<"$output"
}
@test "host.vnic.info" {
esx_env
run govc host.vnic.info
assert_success
}
@test "host.vswitch.info" {
esx_env
run govc host.vswitch.info
assert_success
run govc host.vswitch.info -json
assert_success
}
@test "host.portgroup.info" {
esx_env
run govc host.portgroup.info
assert_success
run govc host.portgroup.info -json
assert_success
}
@test "host.storage.info" {
esx_env
run govc host.storage.info -rescan -refresh -rescan-vmfs
assert_success
}
@test "host.options" {
esx_env
run govc host.option.ls Config.HostAgent.plugins.solo.enableMob
assert_success
run govc host.option.ls Config.HostAgent.plugins.
assert_success
run govc host.option.ls -json Config.HostAgent.plugins.
assert_success
run govc host.option.ls Config.HostAgent.plugins.solo.ENOENT
assert_failure
}
@test "host.service" {
esx_env
run govc host.service.ls
assert_success
run govc host.service.ls -json
assert_success
run govc host.service status TSM-SSH
assert_success
}
@test "host.cert.info" {
esx_env
run govc host.cert.info
assert_success
run govc host.cert.info -json
assert_success
expires=$(govc host.cert.info -json | jq -r .NotAfter)
about_expires=$(govc about.cert -json | jq -r .NotAfter)
assert_equal "$expires" "$about_expires"
}
@test "host.cert.csr" {
esx_env
# Requested Extensions:
# X509v3 Subject Alternative Name:
# IP Address:...
result=$(govc host.cert.csr -ip | openssl req -text -noout)
assert_matches "IP Address:" "$result"
! assert_matches "DNS:" "$result"
# Requested Extensions:
# X509v3 Subject Alternative Name:
# DNS:...
result=$(govc host.cert.csr | openssl req -text -noout)
! assert_matches "IP Address:" "$result"
assert_matches "DNS:" "$result"
}
@test "host.cert.import" {
esx_env
issuer=$(govc host.cert.info -json | jq -r .Issuer)
expires=$(govc host.cert.info -json | jq -r .NotAfter)
# only mess with the cert if its already been signed by our test CA
if [[ "$issuer" != CN=govc-ca,* ]] ; then
skip "host cert not signed by govc-ca"
fi
govc host.cert.csr -ip | ./host_cert_sign.sh | govc host.cert.import
expires2=$(govc host.cert.info -json | jq -r .NotAfter)
# cert expiration should have changed
[ "$expires" != "$expires2" ]
# verify hostd is using the new cert too
expires=$(govc about.cert -json | jq -r .NotAfter)
assert_equal "$expires" "$expires2"
# our cert is not trusted against the system CA list
status=$(govc about.cert | grep Status:)
assert_matches ERROR "$status"
# with our CA trusted, the cert should be too
status=$(govc about.cert -tls-ca-certs ./govc_ca.pem | grep Status:)
assert_matches good "$status"
}
@test "host.date.info" {
esx_env
run govc host.date.info
assert_success
run govc host.date.info -json
assert_success
}

View File

@@ -1,30 +0,0 @@
#!/bin/bash -e
# Usage: govc host.cert.csr | ./host_cert_sign.sh | govc host.cert.import
pushd "$(dirname "$0")" >/dev/null
days=$((365 * 5))
if [ ! -e govc_ca.key ] ; then
echo "Generating CA private key..." 1>&2
openssl genrsa -out govc_ca.key 2048
echo "Generating CA self signed certificate..." 1>&2
openssl req -x509 -new -nodes -key govc_ca.key -out govc_ca.pem -subj /C=US/ST=CA/L=SF/O=VMware/OU=Eng/CN=govc-ca -days $days
fi
echo "Signing CSR with the CA certificate..." 1>&2
# The hostd generated CSR includes:
# Requested Extensions:
# X509v3 Subject Alternative Name:
# IP Address:$ip
# But seems it doesn't get copied by default, so we end up with:
# x509: cannot validate certificate for $ip because it doesn't contain any IP SANs (x509.HostnameError)
# Using -extfile to add it to the signed cert.
ip=$(govc env -x GOVC_URL_HOST)
openssl x509 -req -CA govc_ca.pem -CAkey govc_ca.key -CAcreateserial -days $days -extfile <(echo "subjectAltName=IP:$ip")
popd >/dev/null

View File

@@ -1,3 +0,0 @@
ttylinux-*
floppybird.img

View File

@@ -1,20 +0,0 @@
#!/bin/bash
pushd $(dirname $0)
# Sadly, the ttylinux project was abandoned in late 2015.
# But this release still serves us well.
base_url=http://dl.bintray.com/dougm/ttylinux
ttylinux="ttylinux-pc_i486-16.1"
files="${ttylinux}.iso ${ttylinux}-live.ova ${ttylinux}.ova"
for name in $files ; do
wget -qO $name $base_url/$name
done
wget -qN https://github.com/icebreaker/floppybird/raw/master/build/floppybird.img
# extract ova so we can also use the .vmdk and .ovf files directly
tar -xvf ${ttylinux}.ova
popd

View File

@@ -1,100 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "import.ova" {
esx_env
run govc import.ova $GOVC_IMAGES/${TTYLINUX_NAME}.ova
assert_success
run govc vm.destroy ${TTYLINUX_NAME}
assert_success
}
@test "import.ova with iso" {
esx_env
run govc import.ova $GOVC_IMAGES/${TTYLINUX_NAME}-live.ova
assert_success
run govc vm.destroy ${TTYLINUX_NAME}-live
assert_success
}
@test "import.ovf" {
esx_env
run govc import.ovf $GOVC_IMAGES/${TTYLINUX_NAME}.ovf
assert_success
run govc vm.destroy ${TTYLINUX_NAME}
assert_success
# test w/ relative dir
pushd $BATS_TEST_DIRNAME >/dev/null
run govc import.ovf ./images/${TTYLINUX_NAME}.ovf
assert_success
popd >/dev/null
run govc vm.destroy ${TTYLINUX_NAME}
assert_success
}
@test "import.ovf with name in options" {
esx_env
name=$(new_id)
file=$($mktemp --tmpdir govc-test-XXXXX)
echo "{ \"Name\": \"${name}\"}" > ${file}
run govc import.ovf -options="${file}" $GOVC_IMAGES/${TTYLINUX_NAME}.ovf
assert_success
run govc vm.destroy "${name}"
assert_success
rm -f ${file}
}
@test "import.ovf with import.spec result" {
esx_env
file=$($mktemp --tmpdir govc-test-XXXXX)
name=$(new_id)
govc import.spec $GOVC_IMAGES/${TTYLINUX_NAME}.ovf > ${file}
run govc import.ovf -name="${name}" -options="${file}" $GOVC_IMAGES/${TTYLINUX_NAME}.ovf
assert_success
run govc vm.destroy "${name}"
assert_success
}
@test "import.ovf with name as argument" {
esx_env
name=$(new_id)
run govc import.ova -name="${name}" $GOVC_IMAGES/${TTYLINUX_NAME}.ova
assert_success
run govc vm.destroy "${name}"
assert_success
}
@test "import.vmdk" {
esx_env
name=$(new_id)
run govc import.vmdk "$GOVC_TEST_VMDK_SRC" "$name"
assert_success
run govc import.vmdk "$GOVC_TEST_VMDK_SRC" "$name"
assert_failure # exists
run govc import.vmdk -force "$GOVC_TEST_VMDK_SRC" "$name"
assert_success # exists, but -force was used
}

View File

@@ -1,57 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "logs" {
esx_env
run govc logs
assert_success
nlogs=${#lines[@]}
# there should be plenty more than 1 line of hostd logs
[ $nlogs -ge 1 ]
# test -n flag
run govc logs -n $((nlogs - 10))
assert_success
[ ${#lines[@]} -le $nlogs ]
run govc logs -log vmkernel
assert_success
nlogs=${#lines[@]}
# there should be plenty more than 1 line of vmkernel logs
[ $nlogs -ge 1 ]
# test > 1 call to BrowseLog()
run govc logs -n 2002
assert_success
# -host ignored against ESX
run govc logs -host enoent
assert_success
run govc logs -log enoent
assert_failure
}
@test "logs.ls" {
esx_env
run govc logs.ls
assert_success
# -host ignored against ESX
run govc logs.ls -host enoent
assert_success
}
@test "logs opid" {
esx_env
id=$(new_id)
run env GOVC_OPERATION_ID="$id" govc events
assert_success
govc logs | grep "$id"
}

View File

@@ -1,195 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "ls" {
vcsim_env
run govc ls
assert_success
# /dc/{vm,network,host,datastore}
n=${#lines[@]}
[ $n -ge 4 ]
run govc ls -json
assert_success
# list entire inventory
run govc ls '/**'
assert_success
[ ${#lines[@]} -ge $n ]
run govc ls ./...
assert_success
[ ${#lines[@]} -ge $n ]
run govc ls -t HostSystem '*'
assert_success
[ ${#lines[@]} -eq 0 ]
run govc ls host
assert_success
[ ${#lines[@]} -ge 1 ]
run govc ls enoent
assert_success
[ ${#lines[@]} -eq 0 ]
}
@test "ls -R" {
vcsim_env -esx
# search entire inventory
run govc ls ./...
assert_success
# should have at least 1 dc + folders, 1 host, 1 network, 1 datastore
[ ${#lines[@]} -ge 9 ]
run govc ls -t HostSystem ./...
assert_success
[ ${#lines[@]} -eq 1 ]
run govc ls -t Datacenter /...
assert_success
[ ${#lines[@]} -eq 1 ]
run govc ls -t ResourcePool host/...
assert_success
[ ${#lines[@]} -ge 1 ]
run govc ls -t ResourcePool vm/...
assert_success
[ ${#lines[@]} -eq 0 ]
c=$(govc ls -t ComputeResource ./... | head -1)
run govc ls -t ResourcePool "$c/..."
assert_success
[ ${#lines[@]} -ge 1 ]
}
@test "ls vm" {
vcsim_env -esx
vm=$(new_empty_vm)
run govc ls vm
assert_success
[ ${#lines[@]} -ge 1 ]
run govc ls vm/$vm
assert_success
[ ${#lines[@]} -eq 1 ]
run govc ls /*/vm/$vm
assert_success
[ ${#lines[@]} -eq 1 ]
}
@test "ls network" {
vcsim_env -esx
run govc ls network
assert_success
[ ${#lines[@]} -ge 1 ]
local path=${lines[0]}
run govc ls "$path"
assert_success
[ ${#lines[@]} -eq 1 ]
run govc ls "network/$(basename "$path")"
assert_success
[ ${#lines[@]} -eq 1 ]
run govc ls "/*/network/$(basename "$path")"
assert_success
[ ${#lines[@]} -eq 1 ]
}
@test "ls multi ds" {
vcsim_env -dc 2
run govc ls
assert_success
# /DC0/{vm,network,host,datastore}
[ ${#lines[@]} -eq 4 ]
run govc ls /DC*
assert_success
# /DC[0,1]/{vm,network,host,datastore}
[ ${#lines[@]} -eq 8 ]
# here 'vm' is relative to /DC0
run govc ls vm
assert_success
[ ${#lines[@]} -gt 0 ]
unset GOVC_DATACENTER
run govc ls
assert_success
# /DC[0,1]
[ ${#lines[@]} -eq 2 ]
run govc ls -dc enoent
assert_failure
[ ${#lines[@]} -gt 0 ]
# here 'vm' is relative to '/' - so there are no matches
run govc ls vm
assert_success
[ ${#lines[@]} -eq 0 ]
# ls all vms in all datacenters
run govc ls */vm
assert_success
[ ${#lines[@]} -gt 0 ]
}
@test "ls moref" {
vcsim_env -esx
# ensure the vm folder isn't empty
run govc vm.create -on=false "$(new_id)"
assert_success
# list dc folder paths
folders1=$(govc ls)
# list dc folder refs | govc ls -L ; should output the same paths
folders2=$(govc ls -i | xargs govc ls -L)
assert_equal "$folders1" "$folders2"
for folder in $folders1
do
# list paths in $folder
items1=$(govc ls "$folder")
# list refs in $folder | govc ls -L ; should output the same paths
items2=$(govc ls -i "$folder" | xargs -d '\n' govc ls -L)
assert_equal "$items1" "$items2"
done
ref=ViewManager:ViewManager
path=$(govc ls -L $ref)
assert_equal "$ref" "$path"
path=$(govc ls -L Folder:ha-folder-root)
assert_equal "/" "$path"
}
@test "ls substr" {
# Test fix for issue #815, introduced by b35abbc
vcsim_env
id=$(new_id)
run govc vm.create -on=false "${id}"
assert_success
run govc vm.create -on=false "bar${id}"
assert_success
assert [ "$(govc ls "vm/$id" | wc -l)" -eq 1 ]
}

View File

@@ -1,102 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "metric.ls" {
esx_env
run govc metric.ls
assert_failure
run govc metric.ls enoent
assert_failure
host=$(govc ls -t HostSystem ./... | head -n 1)
pool=$(govc ls -t ResourcePool ./... | head -n 1)
run govc metric.ls "$host"
assert_success
run govc metric.ls -json "$host"
assert_success
run govc metric.ls "$pool"
assert_success
}
@test "metric.sample" {
esx_env
host=$(govc ls -t HostSystem ./... | head -n 1)
metrics=($(govc metric.ls "$host"))
run govc metric.sample "$host" enoent
assert_failure
run govc metric.sample "$host" "${metrics[@]}"
assert_success
run govc metric.sample -instance - "$host" "${metrics[@]}"
assert_success
run govc metric.sample -json "$host" "${metrics[@]}"
assert_success
vm=$(new_ttylinux_vm)
run govc metric.ls "$vm"
assert_output ""
run govc vm.power -on "$vm"
assert_success
run govc vm.ip "$vm"
assert_success
metrics=($(govc metric.ls "$vm"))
run govc metric.sample "$vm" "${metrics[@]}"
assert_success
run govc metric.sample -json "$vm" "${metrics[@]}"
assert_success
run govc metric.sample "govc-test-*" "${metrics[@]}"
assert_success
}
@test "metric.info" {
esx_env
host=$(govc ls -t HostSystem ./... | head -n 1)
metrics=($(govc metric.ls "$host"))
run govc metric.info "$host" enoent
assert_failure
run govc metric.info "$host"
assert_success
run govc metric.info -json "$host"
assert_success
run govc metric.info -dump "$host"
assert_success
run govc metric.sample "$host" "${metrics[@]}"
assert_success
run govc metric.info "$host" "${metrics[@]}"
assert_success
run govc metric.info - "${metrics[@]}"
assert_success
}
@test "metric manager" {
vcsim_env
moid=$(govc object.collect -s - content.perfManager)
govc object.collect -json "$moid" | jq .
}

View File

@@ -1,20 +0,0 @@
#!/bin/bash -e
types="Datacenter HostSystem ClusterComputeResource ResourcePool VirtualMachine Datastore VirtualApp"
for type in $types ; do
echo "$type..."
obj=$(govc ls -t "$type" ./... | head -n 1)
if [ -z "$obj" ] ; then
echo "...no instances found"
continue
fi
if ! govc metric.info "$obj" 2>/dev/null ; then
echo "...N/A" # Datacenter, Datastore on ESX for example
continue
fi
govc metric.ls "$obj" | xargs govc metric.sample -n 5 "$obj"
done

View File

@@ -1,187 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "network dvs backing" {
vcsim_env
# DVS backed network by default (from vcsim_env)
vm=$(new_empty_vm)
eth0=$(govc device.ls -vm $vm | grep ethernet- | awk '{print $1}')
run govc device.info -vm $vm $eth0
assert_success
summary=$(govc device.info -vm $vm $eth0 | grep Summary: | awk '{print $2}')
assert_equal "DVSwitch:" $summary
run govc device.remove -vm $vm $eth0
assert_success
eth0=$(govc device.ls -vm $vm | grep ethernet- | awk '{print $1}')
[ -z "$eth0" ]
# Standard network backing
run govc vm.network.add -vm $vm -net "VM Network"
assert_success
eth0=$(govc device.ls -vm $vm | grep ethernet- | awk '{print $1}')
run govc device.info -vm $vm $eth0
assert_success
summary=$(govc device.info -vm $vm $eth0 | grep Summary: | awk -F: '{print $2}')
assert_equal "VM Network" "$(collapse_ws $summary)"
run govc device.remove -vm $vm $eth0
assert_success
run govc device.remove -vm $vm $eth0
assert_failure "govc: device '$eth0' not found"
}
@test "network change backing" {
vcsim_env
vm=$(new_empty_vm)
eth0=$(govc device.ls -vm $vm | grep ethernet- | awk '{print $1}')
run govc vm.network.change -vm $vm $eth0 enoent
assert_failure "govc: network 'enoent' not found"
run govc vm.network.change -vm $vm enoent "VM Network"
assert_failure "govc: device 'enoent' not found"
run govc vm.network.change -vm $vm $eth0 "VM Network"
assert_success
run govc vm.network.change -vm $vm $eth0
assert_success
unset GOVC_NETWORK
run govc vm.network.change -vm $vm $eth0
assert_failure "govc: default network resolves to multiple instances, please specify"
run govc vm.power -on $vm
assert_success
run govc vm.power -off $vm
mac=$(vm_mac $vm)
run govc vm.network.change -vm $vm -net "VM Network" $eth0
assert_success
# verify we didn't change the mac address
run govc vm.power -on $vm
assert_success
assert_equal $mac $(vm_mac $vm)
}
@test "network standard backing" {
esx_env
vm=$(new_empty_vm)
run govc device.info -vm $vm ethernet-0
assert_success
run govc device.remove -vm $vm ethernet-0
assert_success
run govc device.info -vm $vm ethernet-0
assert_failure
run govc vm.network.add -vm $vm enoent
assert_failure "govc: network 'enoent' not found"
run govc vm.network.add -vm $vm "VM Network"
assert_success
run govc device.info -vm $vm ethernet-0
assert_success
}
@test "network adapter" {
vcsim_env -esx
vm=$(new_id)
run govc vm.create -on=false -net.adapter=enoent $vm
assert_failure "govc: unknown ethernet card type 'enoent'"
vm=$(new_id)
run govc vm.create -on=false -net.adapter=vmxnet3 $vm
assert_success
eth0=$(govc device.ls -vm $vm | grep ethernet- | awk '{print $1}')
type=$(govc device.info -vm $vm $eth0 | grep Type: | awk -F: '{print $2}')
assert_equal "VirtualVmxnet3" $(collapse_ws $type)
run govc vm.network.add -vm $vm -net.adapter e1000e "VM Network"
assert_success
eth1=$(govc device.ls -vm $vm | grep ethernet- | grep -v $eth0 | awk '{print $1}')
type=$(govc device.info -vm $vm $eth1 | grep Type: | awk -F: '{print $2}')
assert_equal "VirtualE1000e" $(collapse_ws $type)
}
@test "network flag required" {
vcsim_env
# -net flag is required when there are multiple networks
unset GOVC_NETWORK
run govc vm.create -on=false $(new_id)
assert_failure "govc: default network resolves to multiple instances, please specify"
}
@test "network change hardware address" {
esx_env
mac="00:00:0f$(dd bs=1 count=3 if=/dev/random 2>/dev/null | hexdump -v -e '/1 ":%02x"')"
vm=$(new_id)
run govc vm.create -on=false $vm
assert_success
run govc vm.network.change -vm $vm -net.address $mac ethernet-0
assert_success
run govc vm.power -on $vm
assert_success
assert_equal $mac $(vm_mac $vm)
}
@test "dvs.portgroup" {
vcsim_env
id=$(new_id)
run govc dvs.create "$id"
assert_success
local host=$GOVC_HOST
run govc dvs.add -dvs "$id" "$host"
assert_success
run govc dvs.portgroup.add -dvs "$id" -type earlyBinding -nports 16 "${id}-ExternalNetwork"
assert_success
run govc dvs.portgroup.add -dvs "$id" -type ephemeral -vlan 3122 "${id}-InternalNetwork"
assert_success
info=$(govc dvs.portgroup.info "$id" | grep VlanId: | uniq | grep 3122)
[ -n "$info" ]
run govc dvs.portgroup.change -vlan 3123 "${id}-InternalNetwork"
assert_success
info=$(govc dvs.portgroup.info "$id" | grep VlanId: | uniq | grep 3123)
[ -n "$info" ]
info=$(govc dvs.portgroup.info -json "$id" | jq '.Port[].Config.Setting.Vlan | select(.VlanId == 3123)')
[ -n "$info" ]
info=$(govc dvs.portgroup.info -json "$id" | jq '.Port[].Config.Setting.Vlan | select(.VlanId == 7777)')
[ -z "$info" ]
run govc object.destroy "network/${id}-ExternalNetwork" "network/${id}-InternalNetwork" "network/${id}"
assert_success
}

View File

@@ -1,474 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "object.destroy" {
vcsim_env
run govc object.destroy "/enoent"
assert_failure
run govc object.destroy
assert_failure
vm=$(new_id)
run govc vm.create "$vm"
assert_success
# fails when powered on
run govc object.destroy "vm/$vm"
assert_failure
run govc vm.power -off "$vm"
assert_success
run govc object.destroy "vm/$vm"
assert_success
}
@test "object.rename" {
esx_env
run govc object.rename "/enoent" "nope"
assert_failure
vm=$(new_id)
run govc vm.create -on=false "$vm"
assert_success
run govc object.rename "vm/$vm" "${vm}-renamed"
assert_success
run govc object.rename "vm/$vm" "${vm}-renamed"
assert_failure
run govc object.destroy "vm/${vm}-renamed"
assert_success
}
@test "object.mv" {
vcsim_env
folder=$(new_id)
run govc folder.create "vm/$folder"
assert_success
for _ in $(seq 1 3) ; do
vm=$(new_id)
run govc vm.create -folder "$folder" "$vm"
assert_success
done
result=$(govc ls "vm/$folder" | wc -l)
[ "$result" -eq "3" ]
run govc folder.create "vm/${folder}-2"
assert_success
run govc object.mv "vm/$folder/*" "vm/${folder}-2"
assert_success
result=$(govc ls "vm/${folder}-2" | wc -l)
[ "$result" -eq "3" ]
result=$(govc ls "vm/$folder" | wc -l)
[ "$result" -eq "0" ]
}
@test "object.collect" {
esx_env
run govc object.collect
assert_success
run govc object.collect -json
assert_success
run govc object.collect -
assert_success
run govc object.collect -json -
assert_success
run govc object.collect - content
assert_success
run govc object.collect -json - content
assert_success
root=$(govc object.collect - content | grep content.rootFolder | awk '{print $3}')
dc=$(govc object.collect "$root" childEntity | awk '{print $3}' | cut -d, -f1)
hostFolder=$(govc object.collect "$dc" hostFolder | awk '{print $3}')
cr=$(govc object.collect "$hostFolder" childEntity | awk '{print $3}' | cut -d, -f1)
host=$(govc object.collect "$cr" host | awk '{print $3}' | cut -d, -f1)
run govc object.collect "$host"
assert_success
run govc object.collect "$host" hardware
assert_success
run govc object.collect "$host" hardware.systemInfo
assert_success
uuid=$(govc object.collect "$host" hardware.systemInfo.uuid | awk '{print $3}')
uuid_s=$(govc object.collect -s "$host" hardware.systemInfo.uuid)
assert_equal "$uuid" "$uuid_s"
run govc object.collect "$(govc ls host | head -n1)"
assert_success
# test against slice of interface
perfman=$(govc object.collect -s - content.perfManager)
result=$(govc object.collect -s "$perfman" description.counterType)
assert_equal "..." "$result"
# test against an interface field
run govc object.collect '/ha-datacenter/network/VM Network' summary
assert_success
}
@test "object.collect vcsim" {
vcsim_env -app 1 -pool 1
run govc object.collect -s -type ClusterComputeResource / configStatus
assert_success green
run govc object.collect -s -type ClusterComputeResource / effectiveRole
assert_number
run govc object.collect -s -type ComputeResource / configStatus
assert_success "$(printf "green\ngreen")"
run govc object.collect -s -type ComputeResource / effectiveRole
assert_number
run govc object.collect -s -type Datacenter / effectiveRole
assert_number
run govc object.collect -s -type Datastore / effectiveRole
assert_number
run govc object.collect -s -type DistributedVirtualPortgroup / config.key
assert_matches dvportgroup-
run govc object.collect -s -type DistributedVirtualPortgroup / config.name
assert_matches DC0_DVPG0
assert_matches DVS0-DVUplinks-
run govc object.collect -s -type DistributedVirtualPortgroup / effectiveRole
assert_number
run govc object.collect -s -type DistributedVirtualSwitch / effectiveRole
assert_number
run govc object.collect -s -type DistributedVirtualSwitch / summary.name
assert_success DVS0
run govc object.collect -s -type DistributedVirtualSwitch / summary.productInfo.name
assert_success DVS
run govc object.collect -s -type DistributedVirtualSwitch / summary.productInfo.vendor
assert_success "VMware, Inc."
run govc object.collect -s -type DistributedVirtualSwitch / summary.productInfo.version
assert_success 6.5.0
run govc object.collect -s -type DistributedVirtualSwitch / summary.uuid
assert_matches "-"
run govc object.collect -s -type Folder / effectiveRole
assert_number
run govc object.collect -json -type HostSystem / config.storageDevice.scsiLun
assert_matches /vmfs/devices
run govc object.collect -json -type HostSystem / config.storageDevice.scsiTopology
assert_matches host.ScsiTopology
run govc object.collect -s -type HostSystem / effectiveRole
assert_number
run govc object.collect -s -type Network / effectiveRole
assert_number
run govc object.collect -s -type ResourcePool / resourcePool
# DC0_C0/Resources has 1 child ResourcePool and 1 child VirtualApp
assert_matches "ResourcePool:"
assert_matches "VirtualApp:"
run govc object.collect -s -type VirtualApp / effectiveRole
assert_number
run govc object.collect -s -type VirtualApp / name
assert_success DC0_C0_APP0
run govc object.collect -s -type VirtualApp / owner
assert_matches ":"
run govc object.collect -s -type VirtualApp / parent
assert_matches ":"
run govc object.collect -s -type VirtualApp / resourcePool
assert_success "" # no VirtualApp children
run govc object.collect -s -type VirtualApp / summary.config.cpuAllocation.limit
assert_number
run govc object.collect -s -type VirtualApp / summary.config.cpuAllocation.reservation
assert_number
run govc object.collect -s -type VirtualApp / summary.config.memoryAllocation.limit
assert_number
run govc object.collect -s -type VirtualApp / summary.config.memoryAllocation.reservation
assert_number
run govc object.collect -s -type VirtualApp / vm
assert_matches "VirtualMachine:"
run govc object.collect -s -type VirtualMachine / config.tools.toolsVersion
assert_number
run govc object.collect -s -type VirtualMachine / effectiveRole
assert_number
run govc object.collect -s -type VirtualMachine / summary.guest.toolsStatus
assert_matches toolsNotInstalled
run govc object.collect -s /DC0/vm/DC0_H0_VM0 config.hardware.numCoresPerSocket
assert_success 1
run govc object.collect -s -type ClusterComputeResource / summary.effectiveCpu
assert_number
run govc object.collect -s -type ClusterComputeResource / summary.effectiveMemory
assert_number
run govc object.collect -s -type ClusterComputeResource / summary.numCpuCores
assert_number
run govc object.collect -s -type ClusterComputeResource / summary.numCpuThreads
assert_number
run govc object.collect -s -type ClusterComputeResource / summary.numEffectiveHosts
assert_number
run govc object.collect -s -type ClusterComputeResource / summary.numHosts
assert_number
run govc object.collect -s -type ClusterComputeResource / summary.totalCpu
assert_number
run govc object.collect -s -type ClusterComputeResource / summary.totalMemory
assert_number
run govc object.collect -s -type ComputeResource / summary.effectiveCpu
assert_number
run govc object.collect -s -type ComputeResource / summary.effectiveMemory
assert_number
run govc object.collect -s -type ComputeResource / summary.numCpuCores
assert_number
run govc object.collect -s -type ComputeResource / summary.numCpuThreads
assert_number
run govc object.collect -s -type ComputeResource / summary.numEffectiveHosts
assert_number
run govc object.collect -s -type ComputeResource / summary.numHosts
assert_number
run govc object.collect -s -type ComputeResource / summary.totalCpu
assert_number
run govc object.collect -s -type ComputeResource / summary.totalMemory
assert_number
run govc object.collect -s -type Network / summary.accessible
assert_success "$(printf "true\ntrue\ntrue")"
run govc object.collect -s -type Network / summary.ipPoolName
assert_success ""
# check that uuid and instanceUuid are set under both config and summary.config
for prop in config summary.config ; do
uuids=$(govc object.collect -s -type m / "$prop.uuid" | sort)
[ -n "$uuids" ]
iuuids=$(govc object.collect -s -type m / "$prop.instanceUuid" | sort)
[ -n "$iuuids" ]
[ "$uuids" != "$iuuids" ]
done
}
@test "object.collect view" {
vcsim_env -dc 2 -folder 1
run govc object.collect -type m
assert_success
run govc object.collect -type m / -name '*C0*'
assert_success
run govc object.collect -type m / -name
assert_success
run govc object.collect -type m / name runtime.powerState
assert_success
run govc object.collect -type m -type h /F0 name
assert_success
run govc object.collect -type n / name
assert_success
run govc object.collect -type enoent / name
assert_failure
}
@test "object.collect raw" {
vcsim_env
govc object.collect -R - <<EOF | grep serverClock
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<CreateFilter xmlns="urn:vim25">
<_this type="PropertyCollector">PropertyCollector</_this>
<spec>
<propSet>
<type>ServiceInstance</type>
<all>true</all>
</propSet>
<objectSet>
<obj type="ServiceInstance">ServiceInstance</obj>
</objectSet>
</spec>
<partialUpdates>false</partialUpdates>
</CreateFilter>
</Body>
</Envelope>
EOF
govc object.collect -O | grep types.CreateFilter
govc object.collect -O -json | jq .
}
@test "object.find" {
esx_env
unset GOVC_DATACENTER
run govc find "/enoent"
assert_failure
run govc find
assert_success
run govc find .
assert_success
run govc find /
assert_success
run govc find . -type HostSystem
assert_success
dc=$(govc find / -type Datacenter | head -1)
run govc find "$dc" -maxdepth 0
assert_output "$dc"
run govc find "$dc/vm" -maxdepth 0
assert_output "$dc/vm"
run govc find "$dc" -maxdepth 1 -type Folder
assert_success
# /<datacenter>/{vm,network,host,datastore}
[ ${#lines[@]} -eq 4 ]
folder=$(govc find -type Folder -name vm)
vm=$(new_empty_vm)
run govc find . -name "$vm"
assert_output "$folder/$vm"
run govc find "$folder" -name "$vm"
assert_output "$folder/$vm"
# moref for VM Network
net=$(govc find -i network -name "$GOVC_NETWORK")
# $vm.network.contains($net) == true
run govc find . -type m -name "$vm" -network "$net"
assert_output "$folder/$vm"
# remove network reference
run govc device.remove -vm "$vm" ethernet-0
assert_success
# $vm.network.contains($net) == false
run govc find . -type VirtualMachine -name "$vm" -network "$net"
assert_output ""
run govc find "$folder" -type VirtualMachine -name "govc-test-*" -runtime.powerState poweredOn
assert_output ""
run govc find "$folder" -type VirtualMachine -name "govc-test-*" -runtime.powerState poweredOff
assert_output "$folder/$vm"
run govc vm.power -on "$vm"
assert_success
run govc find "$folder" -type VirtualMachine -name "govc-test-*" -runtime.powerState poweredOff
assert_output ""
run govc find "$folder" -type VirtualMachine -name "govc-test-*" -runtime.powerState poweredOn
assert_output "$folder/$vm"
# output paths should be relative to "." in these cases
export GOVC_DATACENTER=$dc
folder="./vm"
run govc find . -name "$vm"
assert_output "$folder/$vm"
run govc find "$folder" -name "$vm"
}
@test "object.method" {
vcsim_env_todo
vm=$(govc find vm -type m | head -1)
run govc object.method -enable=false -name NoSuchMethod "$vm"
assert_failure
run govc object.method -enable=false -name Destroy_Task enoent
assert_failure
run govc object.collect -s "$vm" disabledMethod
! assert_matches "Destroy_Task" "$output"
run govc object.method -enable=false -name Destroy_Task "$vm"
assert_success
run govc object.collect -s "$vm" disabledMethod
assert_matches "Destroy_Task" "$output"
run govc object.method -enable -name Destroy_Task "$vm"
assert_success
run govc object.collect -s "$vm" disabledMethod
! assert_matches "Destroy_Task" "$output"
}

View File

@@ -1,327 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "pool.create" {
vcsim_env -esx
path="*/Resources/$(new_id)/$(new_id)"
run govc pool.create $path
assert_failure
assert_line "govc: cannot create resource pool '$(basename ${path})': parent not found"
id=$(new_id)
path="*/Resources/$id"
run govc pool.create -cpu.shares low -mem.reservation 500 $path
assert_success
run govc pool.info $path
assert_success
assert_line "Name: $id"
assert_line "CPU Shares: low"
assert_line "Mem Reservation: 500MB (expandable=true)"
run govc pool.destroy $path
assert_success
}
@test "pool.create multiple" {
vcsim_env -esx
id=$(new_id)
path="*/Resources/$id"
govc pool.create $path
# Finder.List($path)
run govc pool.info "$path"
assert_success
# Finder.Find($name)
run govc pool.info "$id"
assert_success
# Create multiple parent pools with multiple arguments (without globbing)
run govc pool.create $path/a $path/b
assert_success
result=$(govc ls "host/$path/*" | wc -l)
[ $result -eq 2 ]
# Create multiple child pools with one argument (with globbing)
run govc pool.create $path/*/{a,b}
assert_success
result=$(govc ls "host/$path/*/*" | wc -l)
[ $result -eq 4 ]
# Clean up
run govc pool.destroy $path/*/* $path/* $path
assert_success
}
@test "pool.change" {
vcsim_env -esx
id=$(new_id)
root=$(govc find /ha-datacenter/host -type p -name Resources)
path="$root/$id"
run govc pool.create -cpu.reservation 100 $path
assert_success
run govc object.collect -s $path config.cpuAllocation.reservation
assert_success "100"
run govc pool.change -cpu.reservation 0 -mem.shares high $path
assert_success
run govc pool.info $path
assert_success
assert_line "Mem Shares: high"
assert_line "CPU Shares: normal"
run govc object.collect -s $path config.cpuAllocation.reservation
assert_success "0"
nid=$(new_id)
run govc pool.change -name $nid $path
assert_success
path="*/Resources/$nid"
run govc pool.info $path
assert_success
assert_line "Name: $nid"
run govc pool.destroy $path
assert_success
}
@test "pool.change multiple" {
esx_env
id=$(new_id)
path="*/Resources/$id"
govc pool.create $path
# Create some nested pools so that we can test changing multiple in one call
govc pool.create $path/{a,b} $path/{a,b}/test
# Test precondition
run govc pool.info $path/a/test
assert_success
assert_line "Name: test"
run govc pool.info $path/b/test
assert_success
assert_line "Name: test"
# Change name of both test pools
run govc pool.change -name hello $path/*/test
assert_success
# Test postcondition
run govc pool.info $path/a/hello
assert_success
assert_line "Name: hello"
run govc pool.info $path/b/hello
assert_success
assert_line "Name: hello"
# Clean up
govc pool.destroy $path/a/hello
govc pool.destroy $path/a
govc pool.destroy $path/b/hello
govc pool.destroy $path/b
govc pool.destroy $path
}
@test "pool.destroy" {
esx_env
id=$(new_id)
# parent pool
path="*/Resources/$id"
run govc pool.create $path
assert_success
result=$(govc ls "host/$path/*" | wc -l)
[ $result -eq 0 ]
# child pools
id1=$(new_id)
run govc pool.create $path/$id1
assert_success
id2=$(new_id)
run govc pool.create $path/$id2
assert_success
# 2 child pools
result=$(govc ls "host/$path/*" | wc -l)
[ $result -eq 2 ]
# 1 parent pool
result=$(govc ls "host/$path" | wc -l)
[ $result -eq 1 ]
run govc pool.destroy $path
assert_success
# no more parent pool
result=$(govc ls "host/$path" | wc -l)
[ $result -eq 0 ]
# the child pools are not present anymore
# the only place they could pop into is the parent pool
# first child pool
result=$(govc ls "host/*/Resources/$id1" | wc -l)
[ $result -eq 0 ]
# second child pool
result=$(govc ls "host/*/Resources/$id2" | wc -l)
[ $result -eq 0 ]
}
@test "pool.destroy children" {
esx_env
id=$(new_id)
# parent pool
path="*/Resources/$id"
run govc pool.create $path
assert_success
result=$(govc ls "host/$path/*" | wc -l)
[ $result -eq 0 ]
# child pools
run govc pool.create $path/$(new_id)
assert_success
run govc pool.create $path/$(new_id)
assert_success
# 2 child pools
result=$(govc ls "host/$path/*" | wc -l)
[ $result -eq 2 ]
# 1 parent pool
result=$(govc ls "host/*/Resources/govc-test-*" | wc -l)
[ $result -eq 1 ]
# delete childs
run govc pool.destroy -children $path
assert_success
# no more child pools
result=$(govc ls "host/$path/*" | wc -l)
[ $result -eq 0 ]
# cleanup
run govc pool.destroy $path
assert_success
# cleanup check
result=$(govc ls "host/$path" | wc -l)
[ $result -eq 0 ]
}
@test "pool.destroy multiple" {
vcsim_env -esx
id=$(new_id)
path="*/Resources/$id"
govc pool.create $path
# Create some nested pools so that we can test destroying multiple in one call
govc pool.create $path/{a,b}
# Test precondition
result=$(govc ls "host/$path/*" | wc -l)
[ $result -eq 2 ]
# Destroy both pools
run govc pool.destroy $path/{a,b}
assert_success
# Test postcondition
result=$(govc ls "host/$path/*" | wc -l)
[ $result -eq 0 ]
# Clean up
govc pool.destroy $path
}
@test "vm.create -pool" {
esx_env
# test with full inventory path to pools
parent_path=$(govc ls 'host/*/Resources')
parent_name=$(basename $parent_path)
[ "$parent_name" = "Resources" ]
child_name=$(new_id)
child_path="$parent_path/$child_name"
grand_child_name=$(new_id)
grand_child_path="$child_path/$grand_child_name"
run govc pool.create $parent_path/$child_name{,/$grand_child_name}
assert_success
for path in $parent_path $child_path $grand_child_path
do
run govc vm.create -pool $path $(new_id)
assert_success
done
run govc pool.change -mem.limit 100 -mem.expandable=false $child_path
assert_failure
run govc pool.change -mem.limit 100 $child_path
assert_success
run govc pool.change -mem.limit 120 -mem.expandable $child_path
assert_success
# test with glob inventory path to pools
parent_path="*/$parent_name"
child_path="$parent_path/$child_name"
grand_child_path="$child_path/$grand_child_name"
for path in $grand_child_path $child_path
do
run govc pool.destroy $path
assert_success
done
}
@test "vm.create -pool host" {
vcsim_env -esx
id=$(new_id)
path=$(govc ls host)
run govc vm.create -on=false -pool enoent $id
assert_failure "govc: resource pool 'enoent' not found"
run govc vm.create -on=false -pool $path $id
assert_success
}
@test "vm.create -pool cluster" {
vcsim_env
id=$(new_id)
path=$(dirname $GOVC_HOST)
unset GOVC_HOST
unset GOVC_RESOURCE_POOL
run govc vm.create -on=false -pool enoent $id
assert_failure "govc: resource pool 'enoent' not found"
run govc vm.create -on=false -pool $path $id
assert_success
}

View File

@@ -1,121 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "permissions" {
vcsim_env
perm=$(govc permissions.ls /DC0)
run govc permissions.ls -json
assert_success
run govc permissions.set -principal root -role Admin /DC0
assert_success
run govc permissions.ls /DC0
refute_line "$perm"
run govc permissions.remove -principal root /DC0
assert_success
run govc permissions.ls /DC0
assert_success "$perm"
}
@test "role.ls" {
vcsim_env
run govc role.ls
assert_success
run govc role.ls -json
assert_success
run govc role.ls Admin
assert_success
run govc role.ls -json Admin
assert_success
run govc role.ls enoent
assert_failure
}
@test "role.usage" {
vcsim_env
run govc role.usage
assert_success
run govc role.usage -json
assert_success
run govc role.usage Admin
assert_success
run govc role.usage -json Admin
assert_success
run govc role.usage enoent
assert_failure
}
@test "role.create" {
vcsim_env
id=$(new_id)
run govc role.create "$id"
assert_success
run govc role.ls "$id"
assert_success
priv=$(govc role.ls "$id" | wc -l)
[ "$priv" -eq 3 ]
vm_priv=($(govc role.ls Admin | grep VirtualMachine.))
# Test set
run govc role.update "$id" "${vm_priv[@]}"
assert_success
# invalid priv id
run govc role.update "$id" enoent
assert_failure
npriv=$(govc role.ls "$id" | wc -l)
[ "$npriv" -gt "$priv" ]
priv=$npriv
op_priv=($(govc role.ls "$id" | grep VirtualMachine.GuestOperations.))
# Test remove
run govc role.update -r "$id" "${op_priv[@]}"
assert_success
npriv=$(govc role.ls "$id" | wc -l)
[ "$npriv" -lt "$priv" ]
priv=$npriv
# Test add
run govc role.update -a "$id" "${op_priv[@]}"
assert_success
npriv=$(govc role.ls "$id" | wc -l)
[ "$npriv" -gt "$priv" ]
priv=$npriv
# Test rename
run govc role.update -name "${id}-N" "$id"
assert_success
id="${id}-N"
# Test we didn't drop any privileges during rename
[ "$priv" -eq "$(govc role.ls "$id" | wc -l)" ]
run govc role.remove "${id}"
assert_success
run govc role.ls "$id"
assert_failure
}

View File

@@ -1,61 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "session.ls" {
esx_env
run govc session.ls
assert_success
run govc session.ls -json
assert_success
# Test User-Agent
govc session.ls | grep "$(govc version | tr ' ' /)"
}
@test "session.rm" {
esx_env
run govc session.rm enoent
assert_failure
assert_output "govc: ServerFaultCode: The object or item referred to could not be found."
# Can't remove the current session
id=$(govc session.ls -json | jq -r .CurrentSession.Key)
run govc session.rm "$id"
assert_failure
thumbprint=$(govc about.cert -thumbprint)
# persist session just to avoid the Logout() so we can session.rm below
dir=$(mktemp -d govc-test-XXXXX)
id=$(GOVMOMI_HOME="$dir" govc session.ls -json -k=false -persist-session -tls-known-hosts <(echo "$thumbprint") | jq -r .CurrentSession.Key)
rm -rf "$dir"
run govc session.rm "$id"
assert_success
}
@test "session.login" {
esx_env
# Remove username/password
host=$(govc env GOVC_URL)
# Validate auth is not required for service content
run govc about -u "$host"
assert_success
# Auth is required here
run govc ls -u "$host"
assert_failure
cookie=$(govc session.login -l)
ticket=$(govc session.login -cookie "$cookie" -clone)
run govc session.login -u "$host" -ticket "$ticket"
assert_success
}

View File

@@ -1,129 +0,0 @@
#!/usr/bin/env bats
load test_helper
test_vm_snapshot() {
vm=$1
id=$(new_id)
# No snapshots == no output
run govc snapshot.tree -vm "$vm"
assert_success ""
run govc snapshot.remove -vm "$vm" '*'
assert_success
run govc snapshot.revert -vm "$vm"
assert_failure
run govc snapshot.create -vm "$vm" "$id"
assert_success
run govc snapshot.revert -vm "$vm" enoent
assert_failure
run govc snapshot.revert -vm "$vm"
assert_success
run govc snapshot.remove -vm "$vm" "$id"
assert_success
run govc snapshot.create -vm "$vm" root
assert_success
run govc snapshot.tree -C -vm "$vm"
assert_success "root"
run govc snapshot.create -vm "$vm" child
assert_success
run govc snapshot.tree -C -vm "$vm"
assert_success "child"
run govc snapshot.create -vm "$vm" grand
assert_success
run govc snapshot.create -vm "$vm" child
assert_success
result=$(govc snapshot.tree -vm "$vm" -f | grep -c root/child/grand/child)
[ "$result" -eq 1 ]
run govc snapshot.revert -vm "$vm" root
assert_success
run govc snapshot.create -vm "$vm" child
assert_success
# 3 snapshots named "child"
result=$(govc snapshot.tree -vm "$vm" | grep -c child)
[ "$result" -eq 3 ]
run govc snapshot.remove -vm "$vm" child
assert_failure
# 2 snapshots with path "root/child"
result=$(govc snapshot.tree -vm "$vm" -f | egrep -c 'root/child$')
[ "$result" -eq 2 ]
run govc snapshot.remove -vm "$vm" root/child
assert_failure
# path is unique
run govc snapshot.remove -vm "$vm" root/child/grand/child
assert_success
# set current to grand
run govc snapshot.revert -vm "$vm" grand
# name is unique
run govc snapshot.remove -vm "$vm" grand
assert_success
result=$(govc snapshot.tree -vm "$vm" -f | grep root/child/grand/child | wc -l)
[ "$result" -eq 0 ]
# current given to parent of previous current
result=$(govc snapshot.tree -vm "$vm" -f | grep '\.' | wc -l)
[ "$result" -eq 1 ]
id=$(govc snapshot.tree -vm "$vm" -f -i | egrep 'root/child$' | head -n1 | awk '{print $1}' | tr -d '[]')
# moid is unique
run govc snapshot.remove -vm "$vm" "$id"
assert_success
# now root/child is unique
run govc snapshot.remove -vm "$vm" root/child
assert_success
run govc snapshot.remove -vm "$vm" root
assert_success
# current is removed
result=$(govc snapshot.tree -vm "$vm" -f | grep '\.' | wc -l)
[ "$result" -eq 0 ]
# new root
run govc snapshot.create -vm "$vm" 2ndroot
assert_success
# new snapshot 2ndroot is current
result=$(govc snapshot.tree -vm "$vm" -f | grep '\.' | wc -l)
[ "$result" -eq 1 ]
}
@test "vm.snapshot vcsim" {
vcsim_env
vm=$(new_empty_vm)
test_vm_snapshot $vm
}
@test "vm.snapshot" {
esx_env
vm=$(new_ttylinux_vm)
test_vm_snapshot $vm
}

View File

@@ -1,17 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "tasks" {
esx_env
run govc tasks
assert_success
}
@test "tasks host" {
esx_env
run govc tasks 'host/*'
assert_success
}

View File

@@ -1,282 +0,0 @@
# set the following variables only if they've not been set
export GOVC_DATASTORE=${GOVC_DATASTORE-datastore1}
export GOVC_NETWORK=${GOVC_NETWORK-"VM Network"}
export GOVC_INSECURE=true
export GOVC_PERSIST_SESSION=false
unset GOVC_URL
unset GOVC_DEBUG
unset GOVC_TLS_KNOWN_HOSTS
unset GOVC_TLS_HANDSHAKE_TIMEOUT
unset GOVC_DATACENTER
unset GOVC_HOST
unset GOVC_USERNAME
unset GOVC_PASSWORD
if [ -z "$BATS_TEST_DIRNAME" ]; then
BATS_TEST_DIRNAME=$(dirname ${BASH_SOURCE})
fi
# gnu core utils
readlink=$(type -p greadlink readlink | head -1)
xargs=$(type -p gxargs xargs | head -1)
mktemp=$(type -p gmktemp mktemp | head -1)
BATS_TEST_DIRNAME=$($readlink -nf $BATS_TEST_DIRNAME)
GOVC_IMAGES=$BATS_TEST_DIRNAME/images
TTYLINUX_NAME=ttylinux-pc_i486-16.1
GOVC_TEST_VMDK_SRC=$GOVC_IMAGES/${TTYLINUX_NAME}-disk1.vmdk
GOVC_TEST_VMDK=govc-images/$(basename $GOVC_TEST_VMDK_SRC)
GOVC_TEST_ISO_SRC=$GOVC_IMAGES/${TTYLINUX_NAME}.iso
GOVC_TEST_ISO=govc-images/$(basename $GOVC_TEST_ISO_SRC)
GOVC_TEST_IMG_SRC=$GOVC_IMAGES/floppybird.img
GOVC_TEST_IMG=govc-images/$(basename $GOVC_TEST_IMG_SRC)
PATH="$GOPATH/bin:$PATH"
vcsim_stop() {
kill "$GOVC_SIM_PID"
rm -f "$GOVC_SIM_ENV"
unset GOVC_SIM_PID
}
teardown() {
if [ -n "$GOVC_SIM_PID" ] ; then
vcsim_stop
else
govc ls vm | grep govc-test- | $xargs -r govc vm.destroy
govc datastore.ls | grep govc-test- | awk '{print ($NF)}' | $xargs -n1 -r govc datastore.rm
govc ls "host/*/Resources/govc-test-*" | $xargs -r govc pool.destroy
fi
}
new_id() {
echo "govc-test-$(vcsim uuidgen)"
}
import_ttylinux_vmdk() {
govc datastore.mkdir -p govc-images
govc datastore.ls "$GOVC_TEST_VMDK" >/dev/null 2>&1 || \
govc import.vmdk "$GOVC_TEST_VMDK_SRC" govc-images > /dev/null
}
datastore_upload() {
src=$1
dst=govc-images/$(basename $src)
govc datastore.mkdir -p govc-images
govc datastore.ls "$dst" >/dev/null 2>&1 || \
govc datastore.upload "$src" "$dst" > /dev/null
}
upload_img() {
datastore_upload $GOVC_TEST_IMG_SRC
}
upload_iso() {
datastore_upload $GOVC_TEST_ISO_SRC
}
new_ttylinux_vm() {
import_ttylinux_vmdk
id=$(new_id)
govc vm.create -m 32 -disk $GOVC_TEST_VMDK -disk.controller ide -on=false $id
echo $id
}
new_empty_vm() {
id=$(new_id)
govc vm.create -on=false $id
echo $id
}
vm_power_state() {
govc vm.info "$1" | grep "Power state:" | awk -F: '{print $2}' | collapse_ws
}
vm_mac() {
govc device.info -vm "$1" ethernet-0 | grep "MAC Address" | awk '{print $NF}'
}
esx_env() {
if [ -z "$GOVC_TEST_URL" ] ; then
skip "GOVC_TEST_URL not set"
fi
export GOVC_URL=$GOVC_TEST_URL
}
vcsim_env_todo() {
skip "not yet supported by vcsim"
}
# starts vcsim and exports the environment
vcsim_env() {
GOVC_SIM_ENV="$BATS_TMPDIR/$(new_id)"
export GOVC_SIM_ENV
mkfifo "$GOVC_SIM_ENV"
vcsim -httptest.serve=127.0.0.1:0 -E "$GOVC_SIM_ENV" "$@" &
eval "$(cat "$GOVC_SIM_ENV")"
export GOVC_DATASTORE=LocalDS_0
if [ "$1" != "-esx" ] && [ "$1" != "-esx=true" ]; then
export GOVC_DATACENTER=DC0 \
GOVC_HOST=/DC0/host/DC0_C0/DC0_C0_H0 \
GOVC_RESOURCE_POOL=/DC0/host/DC0_C0/Resources \
GOVC_NETWORK=/DC0/network/DC0_DVPG0
fi
}
# remove username/password from $GOVC_URL and set $GOVC_{USERNAME,PASSWORD}
govc_url_to_vars() {
GOVC_USERNAME="$(govc env GOVC_USERNAME)"
GOVC_PASSWORD="$(govc env GOVC_PASSWORD)"
GOVC_URL="$(govc env GOVC_URL)"
export GOVC_URL GOVC_USERNAME GOVC_PASSWORD
# double check that we removed user/pass
grep -q -v @ <<<"$GOVC_URL"
}
quit_vnc() {
if [ "$(uname)" = "Darwin" ]; then
osascript <<EOF
tell application "Screen Sharing"
quit
end tell
EOF
fi
}
open_vnc() {
url=$1
echo "open $url"
if [ "$(uname)" = "Darwin" ]; then
open $url
fi
}
# collapse spaces, for example testing against Go's tabwriter output
collapse_ws() {
local line
if [ $# -eq 0 ]; then line="$(cat -)"
else line="$@"
fi
echo "$line" | tr -s ' ' | sed -e 's/^ //'
}
# the following helpers are borrowed from the test_helper.bash in https://github.com/sstephenson/rbenv
flunk() {
{ if [ "$#" -eq 0 ]; then cat -
else echo "$@"
fi
} >&2
return 1
}
assert_success() {
if [ "$status" -ne 0 ]; then
flunk "command failed with exit status $status: $output"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_failure() {
if [ "$status" -ne 1 ]; then
flunk $(printf "expected failed exit status=1, got status=%d" $status)
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_equal() {
if [ "$1" != "$2" ]; then
{ echo "expected: $1"
echo "actual: $2"
} | flunk
fi
}
assert_output() {
local expected
if [ $# -eq 0 ]; then expected="$(cat -)"
else expected="$1"
fi
assert_equal "$expected" "$output"
}
assert_matches() {
local pattern="${1}"
local actual="${2}"
if [ $# -eq 1 ]; then
actual="$output"
fi
if ! grep -E -q "${pattern}" <<<"${actual}"; then
{ echo "pattern: ${pattern}"
echo "actual: ${actual}"
} | flunk
fi
}
assert_number() {
assert_matches "^-?[0-9]+$" "$output"
}
assert_empty() {
local actual="${1}"
if [ $# -eq 0 ]; then
actual="$(cat -)"
fi
if [ -n "${actual}" ]; then
{ echo "actual: ${actual}"
} | flunk
fi
}
assert_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
assert_equal "$2" "$(collapse_ws ${lines[$1]})"
else
local line
for line in "${lines[@]}"; do
if [ "$(collapse_ws $line)" = "$1" ]; then return 0; fi
done
flunk "expected line \`$1'"
fi
}
refute_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
local num_lines="${#lines[@]}"
if [ "$1" -lt "$num_lines" ]; then
flunk "output has $num_lines lines"
fi
else
local line
for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then
flunk "expected to not find line \`$line'"
fi
done
fi
}
assert() {
if ! "$@"; then
flunk "failed: $*"
fi
}

View File

@@ -1,42 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "vcsim rbvmomi" {
if ! ruby -e "require 'rbvmomi'" ; then
skip "requires rbvmomi"
fi
vcsim_env
ruby ./vcsim_test.rb "$(govc env -x GOVC_URL_PORT)"
}
@test "vcsim examples" {
vcsim_env
# compile + run examples against vcsim
for main in ../../examples/*/main.go ; do
run go run "$main" -insecure -url "$GOVC_URL"
assert_success
done
}
@test "vcsim about" {
vcsim_env -dc 2 -cluster 3 -vm 0 -ds 0
url="https://$(govc env GOVC_URL)"
run curl -skf "$url/about"
assert_matches "CurrentTime" # 1 param (without Context)
assert_matches "TerminateSession" # 2 params (with Context)
run curl -skf "$url/debug/vars"
assert_success
model=$(curl -sfk "$url/debug/vars" | jq .vcsim.Model)
[ "$(jq .Datacenter <<<"$model")" == "2" ]
[ "$(jq .Cluster <<<"$model")" == "6" ]
[ "$(jq .Machine <<<"$model")" == "0" ]
[ "$(jq .Datastore <<<"$model")" == "0" ]
}

View File

@@ -1,23 +0,0 @@
#!/usr/bin/env ruby
require 'rbvmomi'
VIM = RbVmomi::VIM
vim = VIM.connect :user => "user", :password => "pass", :insecure => true, :host => "localhost", :port => ARGV[0] || 8989
dc = vim.serviceInstance.content.rootFolder.traverse("DC0", VIM::Datacenter) or abort "datacenter not found"
vm = dc.vmFolder.traverse("DC0_H0_VM1", VIM::VirtualMachine) or abort "VM not found"
if vm.runtime.powerState == "poweredOn"
vm.PowerOffVM_Task.wait_for_completion
end
vm.PowerOnVM_Task.wait_for_completion
begin
vm.PowerOnVM_Task.wait_for_completion
raise "expected InvalidPowerState"
rescue VIM::InvalidPowerState
# ok
end

View File

@@ -1,737 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "vm.ip" {
esx_env
id=$(new_ttylinux_vm)
run govc vm.power -on $id
assert_success
run govc vm.ip $id
assert_success
run govc vm.ip -a -v4 $id
assert_success
run govc vm.ip -n $(vm_mac $id) $id
assert_success
run govc vm.ip -n ethernet-0 $id
assert_success
ip=$(govc vm.ip $id)
# add a second nic
run govc vm.network.add -vm $id "VM Network"
assert_success
res=$(govc vm.ip -n ethernet-0 $id)
assert_equal $ip $res
}
@test "vm.ip -esxcli" {
esx_env
ok=$(govc host.esxcli system settings advanced list -o /Net/GuestIPHack | grep ^IntValue: | awk '{print $2}')
if [ "$ok" != "1" ] ; then
skip "/Net/GuestIPHack=0"
fi
id=$(new_ttylinux_vm)
run govc vm.power -on $id
assert_success
run govc vm.ip -esxcli $id
assert_success
ip_esxcli=$output
run govc vm.ip $id
assert_success
ip_tools=$output
assert_equal $ip_esxcli $ip_tools
}
@test "vm.create" {
esx_env
id=$(new_ttylinux_vm)
run govc vm.power -on $id
assert_success
result=$(govc device.ls -vm $vm | grep disk- | wc -l)
[ $result -eq 0 ]
result=$(govc device.ls -vm $vm | grep cdrom- | wc -l)
[ $result -eq 0 ]
}
@test "vm.change" {
esx_env
id=$(new_ttylinux_vm)
run govc vm.change -g ubuntu64Guest -m 1024 -c 2 -vm $id
assert_success
run govc vm.info $id
assert_success
assert_line "Guest name: Ubuntu Linux (64-bit)"
assert_line "Memory: 1024MB"
assert_line "CPU: 2 vCPU(s)"
run govc vm.change -e "guestinfo.a=1" -e "guestinfo.b=2" -vm $id
assert_success
run govc vm.info -e $id
assert_success
assert_line "guestinfo.a: 1"
assert_line "guestinfo.b: 2"
run govc vm.change -sync-time-with-host=false -vm $id
assert_success
run govc vm.info -t $id
assert_success
assert_line "SyncTimeWithHost: false"
run govc vm.change -sync-time-with-host=true -vm $id
assert_success
run govc vm.info -t $id
assert_success
assert_line "SyncTimeWithHost: true"
run govc object.collect -s "vm/$id" config.memoryAllocation.reservation
assert_success 0
govc vm.change -vm "$id" -mem.reservation 1024
run govc object.collect -s "vm/$id" config.memoryAllocation.reservation
assert_success 1024
nid=$(new_id)
run govc vm.change -name $nid -vm $id
assert_success
run govc vm.info $id
[ ${#lines[@]} -eq 0 ]
run govc vm.info $nid
[ ${#lines[@]} -gt 0 ]
}
@test "vm.power" {
esx_env
vm=$(new_ttylinux_vm)
run vm_power_state $vm
assert_success "poweredOff"
run govc vm.power $vm
assert_failure
run govc vm.power -on -off $vm
assert_failure
run govc vm.power -on $vm
assert_success
run vm_power_state $vm
assert_success "poweredOn"
run govc vm.power -suspend $vm
assert_success
run vm_power_state $vm
assert_success "suspended"
run govc vm.power -on $vm
assert_success
run vm_power_state $vm
assert_success "poweredOn"
}
@test "vm.power -on -M" {
for esx in true false ; do
vcsim_env -esx=$esx -autostart=false
vms=($(govc find / -type m | sort))
# All VMs are off with -autostart=false
off=($(govc find / -type m -runtime.powerState poweredOff | sort))
assert_equal "${vms[*]}" "${off[*]}"
# Power on 1 VM to test that -M is idempotent
run govc vm.power -on "${vms[0]}"
assert_success
run govc vm.power -on -M "${vms[@]}"
assert_success
# All VMs should be powered on now
on=($(govc find / -type m -runtime.powerState poweredOn | sort))
assert_equal "${vms[*]}" "${on[*]}"
vcsim_stop
done
}
@test "vm.power -force" {
esx_env
vm=$(new_id)
govc vm.create $vm
run govc vm.power -r $vm
assert_failure
run govc vm.power -r -force $vm
assert_success
run govc vm.power -s $vm
assert_failure
run govc vm.power -s -force $vm
assert_success
run govc vm.power -off $vm
assert_failure
run govc vm.power -off -force $vm
assert_success
run govc vm.destroy $vm
assert_success
run govc vm.power -off $vm
assert_failure
run govc vm.power -off -force $vm
assert_failure
}
@test "vm.create pvscsi" {
esx_env
vm=$(new_id)
govc vm.create -on=false -disk.controller pvscsi $vm
result=$(govc device.ls -vm $vm | grep pvscsi- | wc -l)
[ $result -eq 1 ]
result=$(govc device.ls -vm $vm | grep lsilogic- | wc -l)
[ $result -eq 0 ]
vm=$(new_id)
govc vm.create -on=false -disk.controller pvscsi -disk=1GB $vm
}
@test "vm.create in cluster" {
vcsim_env
# using GOVC_HOST and its resource pool
run govc vm.create -on=false $(new_id)
assert_success
# using no -host and the default resource pool for DC0
unset GOVC_HOST
run govc vm.create -on=false $(new_id)
assert_success
}
@test "vm.info" {
vcsim_env -esx
local num=3
local prefix=$(new_id)
for x in $(seq $num)
do
local id="${prefix}-${x}"
# If VM is not found: No output, exit code==0
run govc vm.info $id
assert_success
[ ${#lines[@]} -eq 0 ]
# If VM is not found (using -json flag): Valid json output, exit code==0
run govc vm.info -json $id
assert_success
assert_line "{\"VirtualMachines\":null}"
run govc vm.info -dump $id
assert_success
run govc vm.create -on=false $id
assert_success
local info=$(govc vm.info -r $id)
local found=$(grep Name: <<<"$info" | wc -l)
[ "$found" -eq 1 ]
# test that mo names are printed
found=$(grep Host: <<<"$info" | awk '{print $2}')
[ -n "$found" ]
found=$(grep Storage: <<<"$info" | awk '{print $2}')
[ -n "$found" ]
found=$(grep Network: <<<"$info" | awk '{print $2}')
[ -n "$found" ]
done
# test find slice
local slice=$(govc vm.info ${prefix}-*)
local found=$(grep Name: <<<"$slice" | wc -l)
[ "$found" -eq $num ]
# test -r
found=$(grep Storage: <<<"$slice" | wc -l)
[ "$found" -eq 0 ]
found=$(grep Network: <<<"$slice" | wc -l)
[ "$found" -eq 0 ]
slice=$(govc vm.info -r ${prefix}-*)
found=$(grep Storage: <<<"$slice" | wc -l)
[ "$found" -eq $num ]
found=$(grep Network: <<<"$slice" | wc -l)
[ "$found" -eq $num ]
# test extraConfig
run govc vm.change -e "guestinfo.a=2" -vm $id
assert_success
run govc vm.info -e $id
assert_success
assert_line "guestinfo.a: 2"
run govc vm.change -e "guestinfo.a=" -vm $id
assert_success
refute_line "guestinfo.a: 2"
# test optional bool Config
run govc vm.change -nested-hv-enabled=true -vm "$id"
assert_success
hv=$(govc vm.info -json "$id" | jq '.[][0].Config.NestedHVEnabled')
assert_equal "$hv" "true"
}
@test "vm.create linked ide disk" {
esx_env
import_ttylinux_vmdk
vm=$(new_id)
run govc vm.create -disk $GOVC_TEST_VMDK -disk.controller ide -on=false $vm
assert_success
run govc device.info -vm $vm disk-200-0
assert_success
assert_line "Controller: ide-200"
}
@test "vm.create linked scsi disk" {
esx_env
import_ttylinux_vmdk
vm=$(new_id)
run govc vm.create -disk enoent -on=false $vm
assert_failure "govc: cannot stat '[${GOVC_DATASTORE##*/}] enoent': No such file"
run govc vm.create -disk $GOVC_TEST_VMDK -on=false $vm
assert_success
run govc device.info -vm $vm disk-1000-0
assert_success
assert_line "Controller: lsilogic-1000"
assert_line "Parent: [${GOVC_DATASTORE##*/}] $GOVC_TEST_VMDK"
assert_line "File: [${GOVC_DATASTORE##*/}] $vm/${vm}.vmdk"
}
@test "vm.create scsi disk" {
esx_env
import_ttylinux_vmdk
vm=$(new_id)
run govc vm.create -disk enoent -on=false $vm
assert_failure "govc: cannot stat '[${GOVC_DATASTORE##*/}] enoent': No such file"
run govc vm.create -disk $GOVC_TEST_VMDK -on=false -link=false $vm
assert_success
run govc device.info -vm $vm disk-1000-0
assert_success
assert_line "Controller: lsilogic-1000"
refute_line "Parent: [${GOVC_DATASTORE##*/}] $GOVC_TEST_VMDK"
assert_line "File: [${GOVC_DATASTORE##*/}] $GOVC_TEST_VMDK"
}
@test "vm.create scsi disk with datastore argument" {
esx_env
import_ttylinux_vmdk
vm=$(new_id)
run govc vm.create -disk="${GOVC_TEST_VMDK}" -disk-datastore="${GOVC_DATASTORE}" -on=false -link=false $vm
assert_success
run govc device.info -vm $vm disk-1000-0
assert_success
assert_line "File: [${GOVC_DATASTORE##*/}] $GOVC_TEST_VMDK"
}
@test "vm.create iso" {
esx_env
upload_iso
vm=$(new_id)
run govc vm.create -iso enoent -on=false $vm
assert_failure "govc: cannot stat '[${GOVC_DATASTORE##*/}] enoent': No such file"
run govc vm.create -iso $GOVC_TEST_ISO -on=false $vm
assert_success
run govc device.info -vm $vm cdrom-3000
assert_success
assert_line "Controller: ide-200"
assert_line "Summary: ISO [${GOVC_DATASTORE##*/}] $GOVC_TEST_ISO"
}
@test "vm.create iso with datastore argument" {
esx_env
upload_iso
vm=$(new_id)
run govc vm.create -iso="${GOVC_TEST_ISO}" -iso-datastore="${GOVC_DATASTORE}" -on=false $vm
assert_success
run govc device.info -vm $vm cdrom-3000
assert_success
assert_line "Summary: ISO [${GOVC_DATASTORE##*/}] $GOVC_TEST_ISO"
}
@test "vm.disk.create empty vm" {
esx_env
vm=$(new_empty_vm)
local name=$(new_id)
run govc vm.disk.create -vm $vm -name $name -size 1G
assert_success
result=$(govc device.ls -vm $vm | grep disk- | wc -l)
[ $result -eq 1 ]
name=$(new_id)
run govc vm.disk.create -vm $vm -name $name -controller lsilogic-1000 -size 2G
assert_success
result=$(govc device.ls -vm $vm | grep disk- | wc -l)
[ $result -eq 2 ]
}
@test "vm.disk.create" {
esx_env
import_ttylinux_vmdk
vm=$(new_id)
govc vm.create -disk $GOVC_TEST_VMDK -on=false $vm
result=$(govc device.ls -vm $vm | grep disk- | wc -l)
[ $result -eq 1 ]
local name=$(new_id)
run govc vm.disk.create -vm $vm -name $name -size 1G
assert_success
result=$(govc device.ls -vm $vm | grep disk- | wc -l)
[ $result -eq 2 ]
run govc vm.disk.create -vm $vm -name $name -size 1G
assert_success # TODO: should fail?
result=$(govc device.ls -vm $vm | grep disk- | wc -l)
[ $result -eq 2 ]
}
@test "vm.disk.attach" {
esx_env
import_ttylinux_vmdk
vm=$(new_id)
govc vm.create -disk $GOVC_TEST_VMDK -on=false $vm
result=$(govc device.ls -vm $vm | grep disk- | wc -l)
[ $result -eq 1 ]
id=$(new_id)
run govc import.vmdk $GOVC_TEST_VMDK_SRC $id
assert_success
run govc vm.disk.attach -vm $vm -link=false -disk enoent.vmdk
assert_failure "govc: File [${GOVC_DATASTORE##*/}] enoent.vmdk was not found"
run govc vm.disk.attach -vm $vm -disk enoent.vmdk
assert_failure "govc: Invalid configuration for device '0'."
run govc vm.disk.attach -vm $vm -disk $id/$(basename $GOVC_TEST_VMDK) -controller lsilogic-1000
assert_success
result=$(govc device.ls -vm $vm | grep disk- | wc -l)
[ $result -eq 2 ]
}
@test "vm.create new disk with datastore argument" {
esx_env
vm=$(new_id)
run govc vm.create -disk="1GiB" -ds="${GOVC_DATASTORE}" -on=false -link=false $vm
assert_success
run govc device.info -vm $vm disk-1000-0
assert_success
assert_line "File: [${GOVC_DATASTORE##*/}] ${vm}/${vm}.vmdk"
}
@test "vm.create new disk with datastore cluster argument" {
if [ -z "${GOVC_DATASTORE_CLUSTER}" ]; then
skip "requires datastore cluster"
fi
vm=$(new_id)
run govc vm.create -disk="1GiB" -datastore-cluster="${GOVC_DATASTORE_CLUSTER}" -on=false -link=false $vm
assert_success
run govc device.info -vm $vm disk-1000-0
assert_success
}
@test "vm.register" {
esx_env
run govc vm.unregister enoent
assert_failure
vm=$(new_empty_vm)
run govc vm.unregister "$vm"
assert_success
run govc vm.register "$vm/${vm}.vmx"
assert_success
}
@test "vm.register vcsim" {
vcsim_env -autostart=false
host=$GOVC_HOST
pool=$GOVC_RESOURCE_POOL
unset GOVC_HOST GOVC_RESOURCE_POOL
vm=DC0_H0_VM0
run govc vm.unregister $vm
assert_success
run govc vm.register "$vm/${vm}.vmx"
assert_failure # -pool is required
run govc vm.register -pool "$pool" "$vm/${vm}.vmx"
assert_success
run govc vm.unregister $vm
assert_success
run govc vm.register -template -pool "$pool" "$vm/${vm}.vmx"
assert_failure # -pool is not allowed w/ template
run govc vm.register -template -host "$host" "$vm/${vm}.vmx"
assert_success
}
@test "vm.clone" {
vcsim_env
vm=$(new_empty_vm)
clone=$(new_id)
run govc vm.clone -vm "$vm" "$clone"
assert_success
clone=$(new_id)
run govc vm.clone -vm "$vm" -snapshot X "$clone"
assert_failure
run govc snapshot.create -vm "$vm" X
assert_success
run govc vm.clone -vm "$vm" -snapshot X "$clone"
assert_success
}
@test "vm.clone change resources" {
vcsim_env
vm=$(new_empty_vm)
clone=$(new_id)
run govc vm.info -r "$vm"
assert_success
assert_line "Network: $(basename "$GOVC_NETWORK")" # DVPG0
run govc vm.clone -m 1024 -c 2 -net "VM Network" -vm "$vm" "$clone"
assert_success
run govc vm.info -r "$clone"
assert_success
assert_line "Memory: 1024MB"
assert_line "CPU: 2 vCPU(s)"
assert_line "Network: VM Network"
# Remove all NICs from source vm
run govc device.remove -vm "$vm" "$(govc device.ls -vm "$vm" | grep ethernet- | awk '{print $1}')"
assert_success
clone=$(new_id)
mac=00:00:0f:a7:a0:f1
run govc vm.clone -net "VM Network" -net.address $mac -vm "$vm" "$clone"
assert_success
run govc vm.info -r "$clone"
assert_success
assert_line "Network: VM Network"
run govc device.info -vm "$clone"
assert_success
assert_line "MAC Address: $mac"
}
@test "vm.clone usage" {
# validate we require -vm flag
run govc vm.clone enoent
assert_failure
}
@test "vm.migrate" {
vcsim_env -cluster 2
vm=$(new_empty_vm)
# migrate from H0 to H1
run govc vm.migrate -host DC0_C0/DC0_C0_H1 "$vm"
assert_success
# migrate from C0 to C1
run govc vm.migrate -pool DC0_C1/Resources "$vm"
assert_success
}
@test "object name with slash" {
esx_env
vm=$(new_empty_vm)
name="$vm/with-slash"
# rename VM to include a '/'
run govc vm.change -vm "$vm" -name "$name"
assert_success
path=$(govc ls "vm/$name")
run govc vm.info "$name"
assert_success
assert_line "Name: $name"
assert_line "Path: $path"
run govc vm.info "$path"
assert_success
assert_line "Name: $name"
assert_line "Path: $path"
run govc find vm -name "$name"
assert_success "vm/$name"
# create a portgroup where name includes a '/'
net=$(new_id)/with-slash
run govc host.portgroup.add -vswitch vSwitch0 "$net"
assert_success
run govc vm.network.change -vm "$name" -net "$net" ethernet-0
assert_success
# change VM eth0 to use network that includes a '/' in the name
run govc device.info -vm "$name" ethernet-0
assert_success
assert_line "Summary: $net"
run govc host.portgroup.remove "$net"
assert_success
}
@test "vm.console" {
esx_env
vm=$(new_empty_vm)
run govc vm.console "$vm"
assert_failure
run govc vm.power -on "$vm"
assert_success
run govc vm.console "$vm"
assert_success
run govc vm.console -capture - "$vm"
assert_success
}
@test "vm.upgrade" {
esx_env
vm=$(new_empty_vm)
govc vm.upgrade -vm "$vm"
assert_success
}
@test "vm.markastemplate" {
vcsim_env
id=$(new_id)
run govc vm.create -on=true "$id"
assert_success
run govc vm.markastemplate "$id"
assert_failure
run govc vm.power -off "$id"
assert_success
run govc vm.markastemplate "$id"
assert_success
run govc vm.power -on "$id"
assert_failure
}