mirror of
https://github.com/Oxalide/vsphere-influxdb-go.git
synced 2023-10-10 11:36:51 +00:00
add vendoring with go dep
This commit is contained in:
2
vendor/github.com/vmware/govmomi/govc/test/.gitignore
generated
vendored
Normal file
2
vendor/github.com/vmware/govmomi/govc/test/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.vagrant
|
||||
govc_ca.*
|
75
vendor/github.com/vmware/govmomi/govc/test/README.md
generated
vendored
Normal file
75
vendor/github.com/vmware/govmomi/govc/test/README.md
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
# Functional tests for govc
|
||||
|
||||
## Bats
|
||||
|
||||
Install [Bats](https://github.com/sstephenson/bats/)
|
||||
|
||||
## coreutils
|
||||
|
||||
Install gxargs, greadlink and gmktemp on Darwin
|
||||
|
||||
```
|
||||
brew install coreutils
|
||||
brew install findutils
|
||||
```
|
||||
|
||||
## Download test images
|
||||
|
||||
Some tests depend on ttylinux images, these can be downloaded by running:
|
||||
|
||||
```
|
||||
./images/update.sh
|
||||
```
|
||||
|
||||
These images are uploaded to the esxbox as needed by tests and can be
|
||||
removed with the following command:
|
||||
|
||||
```
|
||||
./clean.sh
|
||||
```
|
||||
|
||||
## GOVC_TEST_URL
|
||||
|
||||
The govc tests need an ESX instance to run against. The default
|
||||
`GOVC_TEST_URL` is that of the vagrant box in the *esxbox* directory:
|
||||
|
||||
```
|
||||
(cd esxbox && vagrant up)
|
||||
```
|
||||
|
||||
Any other ESX box can be used by exporting the following variable:
|
||||
|
||||
```
|
||||
export GOVC_TEST_URL=user:pass@hostname
|
||||
```
|
||||
|
||||
## vCenter Simulator
|
||||
|
||||
Some tests require vCenter and depend on the Vagrant box in the
|
||||
*vcsim* directory. These tests are skipped if the vcsim box is not
|
||||
running. To enable these tests:
|
||||
|
||||
```
|
||||
(cd vcsim && vagrant up)
|
||||
```
|
||||
|
||||
## Running tests
|
||||
|
||||
The test helper prepends ../govc to `PATH`.
|
||||
|
||||
The tests can be run from any directory, as *govc* is found related to
|
||||
`PATH` and *images* are found relative to `$BATS_TEST_DIRNAME`.
|
||||
|
||||
The entire suite can be run with the following command:
|
||||
|
||||
```
|
||||
cd $GOPATH/github.com/vmware/govmomi/govc
|
||||
go build -v .
|
||||
bats test
|
||||
```
|
||||
|
||||
Or individually, for example:
|
||||
|
||||
```
|
||||
./test/cli.bats
|
||||
```
|
74
vendor/github.com/vmware/govmomi/govc/test/boot_order_test.sh
generated
vendored
Executable file
74
vendor/github.com/vmware/govmomi/govc/test/boot_order_test.sh
generated
vendored
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/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
|
25
vendor/github.com/vmware/govmomi/govc/test/clean.sh
generated
vendored
Executable file
25
vendor/github.com/vmware/govmomi/govc/test/clean.sh
generated
vendored
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/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
|
120
vendor/github.com/vmware/govmomi/govc/test/cli.bats
generated
vendored
Executable file
120
vendor/github.com/vmware/govmomi/govc/test/cli.bats
generated
vendored
Executable file
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "about" {
|
||||
run govc about
|
||||
assert_success
|
||||
assert_line "Vendor: VMware, Inc."
|
||||
|
||||
run govc about -json
|
||||
assert_success
|
||||
|
||||
run govc about -json -l
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "about.cert" {
|
||||
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" {
|
||||
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" {
|
||||
host=$(govc env -x GOVC_URL_HOST)
|
||||
run govc about -u "enoent@$host"
|
||||
assert_failure "govc: ServerFaultCode: Cannot complete login due to an incorrect user name or password."
|
||||
}
|
||||
|
||||
@test "login attempt with GOVC_URL, GOVC_USERNAME, and GOVC_PASSWORD" {
|
||||
govc_url_to_vars
|
||||
run govc about
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "connect to an endpoint with a non-supported API version" {
|
||||
run env GOVC_MIN_API_VERSION=24.4 govc about
|
||||
assert grep -q "^govc: Require API version 24.4," <<<${output}
|
||||
}
|
||||
|
||||
@test "connect to an endpoint with user provided Vim namespace and Vim version" {
|
||||
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
|
||||
}
|
81
vendor/github.com/vmware/govmomi/govc/test/datacenter.bats
generated
vendored
Executable file
81
vendor/github.com/vmware/govmomi/govc/test/datacenter.bats
generated
vendored
Executable file
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "datacenter.info" {
|
||||
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 "create and destroy datacenters" {
|
||||
vcsim_env
|
||||
|
||||
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 "${dcs[@]}"
|
||||
assert_success
|
||||
|
||||
for dc in ${dcs[*]}; do
|
||||
run govc ls "/$dc"
|
||||
assert_success
|
||||
[ ${#lines[@]} -eq 0 ]
|
||||
done
|
||||
}
|
||||
|
||||
@test "destroy datacenter using glob" {
|
||||
vcsim_env
|
||||
unset GOVC_DATACENTER GOVC_DATASTORE
|
||||
|
||||
folder=$(new_id)
|
||||
dcs=($(new_id) $(new_id))
|
||||
|
||||
run govc folder.create "$folder"
|
||||
assert_success
|
||||
|
||||
run govc datacenter.create -folder "$folder" "${dcs[@]}"
|
||||
assert_success
|
||||
|
||||
run govc object.destroy "$folder/*"
|
||||
assert_success
|
||||
|
||||
for dc in ${dcs[*]}; do
|
||||
run govc ls "/$dc"
|
||||
assert_success
|
||||
[ ${#lines[@]} -eq 0 ]
|
||||
done
|
||||
|
||||
run govc folder.destroy "$folder"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "fails when datacenter name not specified" {
|
||||
run govc datacenter.create
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "datacenter commands fail against ESX" {
|
||||
run govc datacenter.create something
|
||||
assert_failure "govc: ServerFaultCode: The operation is not supported on the object."
|
||||
|
||||
run govc object.destroy /ha-datacenter
|
||||
assert_failure
|
||||
}
|
272
vendor/github.com/vmware/govmomi/govc/test/datastore.bats
generated
vendored
Executable file
272
vendor/github.com/vmware/govmomi/govc/test/datastore.bats
generated
vendored
Executable file
@@ -0,0 +1,272 @@
|
||||
#!/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" {
|
||||
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" {
|
||||
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" {
|
||||
name=$(upload_file)
|
||||
|
||||
# Not found is a failure
|
||||
run govc datastore.rm "${name}.notfound"
|
||||
assert_failure
|
||||
assert_matches "govc: File .* was not found" "${output}"
|
||||
|
||||
# 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" {
|
||||
run govc datastore.info enoent
|
||||
assert_failure
|
||||
|
||||
run govc datastore.info
|
||||
assert_success
|
||||
[ ${#lines[@]} -gt 1 ]
|
||||
}
|
||||
|
||||
|
||||
@test "datastore.mkdir" {
|
||||
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" {
|
||||
name=$(upload_file)
|
||||
run govc datastore.download "$name" -
|
||||
assert_success
|
||||
assert_output "Hello world"
|
||||
|
||||
run govc datastore.download "$name" "$TMPDIR/$name"
|
||||
assert_success
|
||||
run cat "$TMPDIR/$name"
|
||||
assert_output "Hello world"
|
||||
rm "$TMPDIR/$name"
|
||||
}
|
||||
|
||||
@test "datastore.upload" {
|
||||
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" {
|
||||
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" {
|
||||
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.disk.info" {
|
||||
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
|
||||
}
|
102
vendor/github.com/vmware/govmomi/govc/test/datastore_file_manager_test.sh
generated
vendored
Executable file
102
vendor/github.com/vmware/govmomi/govc/test/datastore_file_manager_test.sh
generated
vendored
Executable file
@@ -0,0 +1,102 @@
|
||||
#!/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
|
26
vendor/github.com/vmware/govmomi/govc/test/datastore_tail_test.sh
generated
vendored
Executable file
26
vendor/github.com/vmware/govmomi/govc/test/datastore_tail_test.sh
generated
vendored
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/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
|
288
vendor/github.com/vmware/govmomi/govc/test/device.bats
generated
vendored
Executable file
288
vendor/github.com/vmware/govmomi/govc/test/device.bats
generated
vendored
Executable file
@@ -0,0 +1,288 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "device.ls" {
|
||||
vm=$(new_empty_vm)
|
||||
|
||||
result=$(govc device.ls -vm $vm | grep ethernet-0 | wc -l)
|
||||
[ $result -eq 1 ]
|
||||
}
|
||||
|
||||
@test "device.info" {
|
||||
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 ]
|
||||
}
|
||||
|
||||
@test "device.boot" {
|
||||
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 ]
|
||||
}
|
||||
|
||||
@test "device.cdrom" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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
|
||||
}
|
27
vendor/github.com/vmware/govmomi/govc/test/esxbox/Vagrantfile
generated
vendored
Normal file
27
vendor/github.com/vmware/govmomi/govc/test/esxbox/Vagrantfile
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.ssh.insert_key = false
|
||||
config.ssh.default.username = "root"
|
||||
config.ssh.shell = "sh"
|
||||
config.vm.hostname = "esxbox"
|
||||
|
||||
config.vm.box = "esxi55"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
config.vm.network "forwarded_port", guest: 443, host: 18443
|
||||
|
||||
[:vmware_fusion, :vmware_workstation].each do |name|
|
||||
config.vm.provider name do |v,override|
|
||||
v.vmx["memsize"] = "4096"
|
||||
end
|
||||
end
|
||||
|
||||
config.vm.provision "shell", privileged: false, :inline => <<EOS
|
||||
# Turn off the firewall
|
||||
esxcli network firewall set --enabled false
|
||||
|
||||
# Enable option so we can get VM ip address w/o vmware-tools
|
||||
esxcli system settings advanced set -o /Net/GuestIPHack -i 1
|
||||
EOS
|
||||
end
|
43
vendor/github.com/vmware/govmomi/govc/test/esxcli.bats
generated
vendored
Executable file
43
vendor/github.com/vmware/govmomi/govc/test/esxcli.bats
generated
vendored
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "network vm list" {
|
||||
# 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" {
|
||||
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" {
|
||||
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
|
||||
}
|
51
vendor/github.com/vmware/govmomi/govc/test/events.bats
generated
vendored
Executable file
51
vendor/github.com/vmware/govmomi/govc/test/events.bats
generated
vendored
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "events dc" {
|
||||
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" {
|
||||
run govc events 'host/*'
|
||||
assert_success
|
||||
[ ${#lines[@]} -ge 1 ]
|
||||
}
|
||||
|
||||
@test "events vm" {
|
||||
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 ]
|
||||
}
|
75
vendor/github.com/vmware/govmomi/govc/test/extension.bats
generated
vendored
Executable file
75
vendor/github.com/vmware/govmomi/govc/test/extension.bats
generated
vendored
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "extension" {
|
||||
vcsim_env
|
||||
|
||||
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
|
||||
# vagrant port forwards to VC's port 80
|
||||
export GOVC_TUNNEL_PROXY_PORT=16080
|
||||
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 ]
|
||||
}
|
48
vendor/github.com/vmware/govmomi/govc/test/fields.bats
generated
vendored
Executable file
48
vendor/github.com/vmware/govmomi/govc/test/fields.bats
generated
vendored
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/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 ]
|
||||
}
|
20
vendor/github.com/vmware/govmomi/govc/test/firewall.bats
generated
vendored
Executable file
20
vendor/github.com/vmware/govmomi/govc/test/firewall.bats
generated
vendored
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "firewall.ruleset.find" {
|
||||
# Assumes sshServer ruleset is enabled
|
||||
run govc firewall.ruleset.find -direction inbound -port 22
|
||||
assert_success
|
||||
|
||||
run govc firewall.ruleset.find -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 -direction outbound -port 22 -enabled=false
|
||||
assert_success
|
||||
|
||||
# find disabled should include sshClient ruleset in output
|
||||
result=$(govc firewall.ruleset.find -direction outbound -port 22 -enabled=false | grep sshClient | wc -l)
|
||||
[ $result -eq 1 ]
|
||||
fi
|
||||
}
|
74
vendor/github.com/vmware/govmomi/govc/test/folder.bats
generated
vendored
Executable file
74
vendor/github.com/vmware/govmomi/govc/test/folder.bats
generated
vendored
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "folder.info" {
|
||||
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 Name: | wc -l)
|
||||
[ $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
|
||||
}
|
7
vendor/github.com/vmware/govmomi/govc/test/govc-sim
generated
vendored
Executable file
7
vendor/github.com/vmware/govmomi/govc/test/govc-sim
generated
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
. $(dirname $0)/test_helper.bash
|
||||
|
||||
vcsim_env
|
||||
|
||||
govc "$@"
|
117
vendor/github.com/vmware/govmomi/govc/test/guest_operations_test.sh
generated
vendored
Executable file
117
vendor/github.com/vmware/govmomi/govc/test/guest_operations_test.sh
generated
vendored
Executable file
@@ -0,0 +1,117 @@
|
||||
#!/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
|
||||
|
||||
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
|
189
vendor/github.com/vmware/govmomi/govc/test/host.bats
generated
vendored
Executable file
189
vendor/github.com/vmware/govmomi/govc/test/host.bats
generated
vendored
Executable file
@@ -0,0 +1,189 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "host info esx" {
|
||||
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 dns ip ipath uuid
|
||||
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_success
|
||||
|
||||
uuid=$(govc host.info -host $name -json | jq -r .HostSystems[].Hardware.SystemInfo.Uuid)
|
||||
run govc host.info -host.uuid $uuid
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "host.vnic.info" {
|
||||
run govc host.vnic.info
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "host.vswitch.info" {
|
||||
run govc host.vswitch.info
|
||||
assert_success
|
||||
|
||||
run govc host.vswitch.info -json
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "host.portgroup.info" {
|
||||
run govc host.portgroup.info
|
||||
assert_success
|
||||
|
||||
run govc host.portgroup.info -json
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "host.options" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
# 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" {
|
||||
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" {
|
||||
run govc host.date.info
|
||||
assert_success
|
||||
|
||||
run govc host.date.info -json
|
||||
assert_success
|
||||
}
|
30
vendor/github.com/vmware/govmomi/govc/test/host_cert_sign.sh
generated
vendored
Executable file
30
vendor/github.com/vmware/govmomi/govc/test/host_cert_sign.sh
generated
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/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
|
3
vendor/github.com/vmware/govmomi/govc/test/images/.gitignore
generated
vendored
Normal file
3
vendor/github.com/vmware/govmomi/govc/test/images/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
ttylinux-*
|
||||
floppybird.img
|
||||
|
20
vendor/github.com/vmware/govmomi/govc/test/images/update.sh
generated
vendored
Executable file
20
vendor/github.com/vmware/govmomi/govc/test/images/update.sh
generated
vendored
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/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
|
60
vendor/github.com/vmware/govmomi/govc/test/import.bats
generated
vendored
Executable file
60
vendor/github.com/vmware/govmomi/govc/test/import.bats
generated
vendored
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "import.ova" {
|
||||
run govc import.ova $GOVC_IMAGES/${TTYLINUX_NAME}.ova
|
||||
assert_success
|
||||
|
||||
run govc vm.destroy ${TTYLINUX_NAME}
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "import.ova with iso" {
|
||||
run govc import.ova $GOVC_IMAGES/${TTYLINUX_NAME}-live.ova
|
||||
assert_success
|
||||
|
||||
run govc vm.destroy ${TTYLINUX_NAME}-live
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "import.ovf" {
|
||||
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" {
|
||||
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 name as argument" {
|
||||
name=$(new_id)
|
||||
|
||||
run govc import.ova -name="${name}" $GOVC_IMAGES/${TTYLINUX_NAME}.ova
|
||||
assert_success
|
||||
|
||||
run govc vm.destroy "${name}"
|
||||
assert_success
|
||||
}
|
53
vendor/github.com/vmware/govmomi/govc/test/license.bats
generated
vendored
Executable file
53
vendor/github.com/vmware/govmomi/govc/test/license.bats
generated
vendored
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
# These tests should only run against a server running an evaluation license.
|
||||
verify_evaluation() {
|
||||
if [ "$(govc license.ls -json | jq -r .[0].EditionKey)" != "eval" ]; then
|
||||
skip "requires evaluation license"
|
||||
fi
|
||||
}
|
||||
|
||||
get_key() {
|
||||
jq ".[] | select(.LicenseKey == \"$1\")"
|
||||
}
|
||||
|
||||
get_property() {
|
||||
jq -r ".Properties[] | select(.Key == \"$1\") | .Value"
|
||||
}
|
||||
|
||||
@test "license.add" {
|
||||
verify_evaluation
|
||||
|
||||
run govc license.add -json 00000-00000-00000-00000-00001 00000-00000-00000-00000-00002
|
||||
assert_success
|
||||
|
||||
# Expect to see an entry for both the first and the second key
|
||||
assert_equal "License is not valid for this product" $(get_key 00000-00000-00000-00000-00001 <<<${output} | get_property diagnostic)
|
||||
assert_equal "License is not valid for this product" $(get_key 00000-00000-00000-00000-00002 <<<${output} | get_property diagnostic)
|
||||
}
|
||||
|
||||
@test "license.remove" {
|
||||
verify_evaluation
|
||||
|
||||
run govc license.remove -json 00000-00000-00000-00000-00001
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "license.ls" {
|
||||
verify_evaluation
|
||||
|
||||
run govc license.ls -json
|
||||
assert_success
|
||||
|
||||
# Expect the test instance to run in evaluation mode
|
||||
assert_equal "Evaluation Mode" $(get_key 00000-00000-00000-00000-00000 <<<$output | jq -r ".Name")
|
||||
}
|
||||
|
||||
@test "license.decode" {
|
||||
verify_evaluation
|
||||
|
||||
key=00000-00000-00000-00000-00000
|
||||
assert_equal "eval" $(govc license.decode $key | grep $key | awk '{print $2}')
|
||||
}
|
42
vendor/github.com/vmware/govmomi/govc/test/logs.bats
generated
vendored
Executable file
42
vendor/github.com/vmware/govmomi/govc/test/logs.bats
generated
vendored
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "logs" {
|
||||
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" {
|
||||
run govc logs.ls
|
||||
assert_success
|
||||
|
||||
# -host ignored against ESX
|
||||
run govc logs.ls -host enoent
|
||||
assert_success
|
||||
}
|
166
vendor/github.com/vmware/govmomi/govc/test/ls.bats
generated
vendored
Executable file
166
vendor/github.com/vmware/govmomi/govc/test/ls.bats
generated
vendored
Executable file
@@ -0,0 +1,166 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "ls" {
|
||||
run govc ls
|
||||
assert_success
|
||||
# /dc/{vm,network,host,datastore}
|
||||
n=${#lines[@]}
|
||||
[ $n -ge 4 ]
|
||||
|
||||
# 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" {
|
||||
# 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" {
|
||||
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" {
|
||||
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
|
||||
|
||||
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" {
|
||||
# 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"
|
||||
}
|
85
vendor/github.com/vmware/govmomi/govc/test/metric.bats
generated
vendored
Executable file
85
vendor/github.com/vmware/govmomi/govc/test/metric.bats
generated
vendored
Executable file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "metric.ls" {
|
||||
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" {
|
||||
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" {
|
||||
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.sample "$host" "${metrics[@]}"
|
||||
assert_success
|
||||
|
||||
run govc metric.info "$host" "${metrics[@]}"
|
||||
assert_success
|
||||
|
||||
run govc metric.info - "${metrics[@]}"
|
||||
assert_success
|
||||
}
|
20
vendor/github.com/vmware/govmomi/govc/test/metric_info_test.sh
generated
vendored
Executable file
20
vendor/github.com/vmware/govmomi/govc/test/metric_info_test.sh
generated
vendored
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/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
|
170
vendor/github.com/vmware/govmomi/govc/test/network.bats
generated
vendored
Executable file
170
vendor/github.com/vmware/govmomi/govc/test/network.bats
generated
vendored
Executable file
@@ -0,0 +1,170 @@
|
||||
#!/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" {
|
||||
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" {
|
||||
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" {
|
||||
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
|
||||
|
||||
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" ]
|
||||
|
||||
run govc object.destroy "network/${id}-ExternalNetwork" "network/${id}-InternalNetwork" "network/${id}"
|
||||
assert_success
|
||||
}
|
237
vendor/github.com/vmware/govmomi/govc/test/object.bats
generated
vendored
Executable file
237
vendor/github.com/vmware/govmomi/govc/test/object.bats
generated
vendored
Executable file
@@ -0,0 +1,237 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "object.destroy" {
|
||||
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" {
|
||||
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" {
|
||||
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.find" {
|
||||
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
|
||||
|
||||
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"
|
||||
}
|
301
vendor/github.com/vmware/govmomi/govc/test/pool.bats
generated
vendored
Executable file
301
vendor/github.com/vmware/govmomi/govc/test/pool.bats
generated
vendored
Executable file
@@ -0,0 +1,301 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "pool.create" {
|
||||
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" {
|
||||
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" {
|
||||
id=$(new_id)
|
||||
path="*/Resources/$id"
|
||||
govc pool.create $path
|
||||
|
||||
run govc pool.change -mem.shares high $path
|
||||
assert_success
|
||||
run govc pool.info $path
|
||||
assert_success
|
||||
assert_line "Mem Shares: high"
|
||||
assert_line "CPU Shares: normal"
|
||||
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
# 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" {
|
||||
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
|
||||
}
|
96
vendor/github.com/vmware/govmomi/govc/test/role.bats
generated
vendored
Executable file
96
vendor/github.com/vmware/govmomi/govc/test/role.bats
generated
vendored
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "permissions.ls" {
|
||||
run govc permissions.ls
|
||||
assert_success
|
||||
|
||||
run govc permissions.ls -json
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "role.ls" {
|
||||
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" {
|
||||
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" {
|
||||
id=$(new_id)
|
||||
run govc role.create "$id"
|
||||
assert_success
|
||||
|
||||
run govc role.ls "$id"
|
||||
assert_success
|
||||
|
||||
priv=$(govc role.ls "$id" | wc -l)
|
||||
vm_priv=($(govc role.ls Admin | grep VirtualMachine.))
|
||||
|
||||
# Test set
|
||||
run govc role.update "$id" "${vm_priv[@]}"
|
||||
assert_success
|
||||
|
||||
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
|
||||
}
|
36
vendor/github.com/vmware/govmomi/govc/test/session.bats
generated
vendored
Executable file
36
vendor/github.com/vmware/govmomi/govc/test/session.bats
generated
vendored
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "session.ls" {
|
||||
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" {
|
||||
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
|
||||
}
|
254
vendor/github.com/vmware/govmomi/govc/test/test_helper.bash
generated
vendored
Normal file
254
vendor/github.com/vmware/govmomi/govc/test/test_helper.bash
generated
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
# set the following variables only if they've not been set
|
||||
GOVC_TEST_URL=${GOVC_TEST_URL-"https://root:vagrant@localhost:18443/sdk"}
|
||||
export GOVC_URL=$GOVC_TEST_URL
|
||||
export GOVC_DATASTORE=${GOVC_DATASTORE-datastore1}
|
||||
export GOVC_NETWORK=${GOVC_NETWORK-"VM Network"}
|
||||
|
||||
export GOVC_INSECURE=true
|
||||
export GOVC_PERSIST_SESSION=false
|
||||
unset GOVC_DEBUG
|
||||
unset GOVC_TLS_KNOWN_HOSTS
|
||||
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="$(dirname $BATS_TEST_DIRNAME):$PATH"
|
||||
|
||||
teardown() {
|
||||
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
|
||||
}
|
||||
|
||||
new_id() {
|
||||
echo "govc-test-$(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 # TODO: make this part of vagrant provision
|
||||
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}'
|
||||
}
|
||||
|
||||
# exports an environment for using vcsim if running, otherwise skips the calling test.
|
||||
vcsim_env() {
|
||||
if [ "$(uname)" == "Darwin" ]; then
|
||||
PATH="/Applications/VMware Fusion.app/Contents/Library:$PATH"
|
||||
fi
|
||||
|
||||
if [ "$(vmrun list | grep $BATS_TEST_DIRNAME/vcsim | wc -l)" -eq 1 ]; then
|
||||
export GOVC_URL=https://root:vmware@localhost:16443/sdk \
|
||||
GOVC_DATACENTER=DC0 \
|
||||
GOVC_DATASTORE=GlobalDS_0 \
|
||||
GOVC_HOST=/DC0/host/DC0_C0/DC0_C0_H0 \
|
||||
GOVC_RESOURCE_POOL=/DC0/host/DC0_C0/Resources \
|
||||
GOVC_NETWORK=/DC0/network/DC0_DVPG0
|
||||
else
|
||||
skip "requires vcsim"
|
||||
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="$(cat -)"
|
||||
fi
|
||||
|
||||
if ! grep -q "${pattern}" <<<"${actual}"; then
|
||||
{ echo "pattern: ${pattern}"
|
||||
echo "actual: ${actual}"
|
||||
} | flunk
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
}
|
24
vendor/github.com/vmware/govmomi/govc/test/vcsim/Vagrantfile
generated
vendored
Normal file
24
vendor/github.com/vmware/govmomi/govc/test/vcsim/Vagrantfile
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# VCSA with VC simulator enabled.
|
||||
# 'vagrant provision' will erase any existing inventory and
|
||||
# populate with the config in ./provision.sh
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.hostname = "vcsim"
|
||||
|
||||
config.vm.box = "vcsa"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
|
||||
config.vm.provision "shell", path: "provision.sh"
|
||||
|
||||
config.vm.network "forwarded_port", guest: 443, host: 16443
|
||||
config.vm.network "forwarded_port", guest: 80, host: 16080
|
||||
|
||||
[:vmware_fusion, :vmware_workstation].each do |name|
|
||||
config.vm.provider name do |v,override|
|
||||
v.vmx["memsize"] = "4096"
|
||||
end
|
||||
end
|
||||
end
|
30
vendor/github.com/vmware/govmomi/govc/test/vcsim/provision.sh
generated
vendored
Normal file
30
vendor/github.com/vmware/govmomi/govc/test/vcsim/provision.sh
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
|
||||
|
||||
echo "Creating vcsim model..."
|
||||
cat > /etc/vmware-vpx/vcsim/model/initInventory-govc.cfg <<EOF
|
||||
<config>
|
||||
<inventory>
|
||||
<dc>2</dc>
|
||||
<host-per-dc>3</host-per-dc>
|
||||
<vm-per-host>3</vm-per-host>
|
||||
<poweron-vm-per-host>2</poweron-vm-per-host>
|
||||
<cluster-per-dc>2</cluster-per-dc>
|
||||
<host-per-cluster>3</host-per-cluster>
|
||||
<rp-per-cluster>3</rp-per-cluster>
|
||||
<vm-per-rp>4</vm-per-rp>
|
||||
<poweron-vm-per-rp>3</poweron-vm-per-rp>
|
||||
<dv-portgroups>2</dv-portgroups>
|
||||
</inventory>
|
||||
</config>
|
||||
EOF
|
||||
|
||||
cat > /etc/vmware-vpx/vcsim/model/vcsim-default.cfg <<EOF
|
||||
<simulator>
|
||||
<enabled>true</enabled>
|
||||
<initInventory>vcsim/model/initInventory-govc.cfg</initInventory>
|
||||
</simulator>
|
||||
EOF
|
||||
|
||||
echo "Starting VC simulator..."
|
||||
vmware-vcsim-stop
|
||||
vmware-vcsim-start default
|
594
vendor/github.com/vmware/govmomi/govc/test/vm.bats
generated
vendored
Executable file
594
vendor/github.com/vmware/govmomi/govc/test/vm.bats
generated
vendored
Executable file
@@ -0,0 +1,594 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "vm.ip" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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"
|
||||
|
||||
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" {
|
||||
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 -force" {
|
||||
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" {
|
||||
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" {
|
||||
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.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 "vm.create linked ide disk" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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" {
|
||||
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 ]
|
||||
|
||||
run govc import.vmdk $GOVC_TEST_VMDK_SRC $vm
|
||||
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 $vm/$(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" {
|
||||
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" {
|
||||
run govc vm.unregister enoent
|
||||
assert_failure
|
||||
|
||||
vm=$(new_empty_vm)
|
||||
|
||||
run govc vm.change -vm "$vm" -e foo=bar
|
||||
assert_success
|
||||
|
||||
run govc vm.unregister "$vm"
|
||||
assert_success
|
||||
|
||||
run govc vm.change -vm "$vm" -e foo=bar
|
||||
assert_failure
|
||||
|
||||
run govc vm.register "$vm/${vm}.vmx"
|
||||
assert_success
|
||||
|
||||
run govc vm.change -vm "$vm" -e foo=bar
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "vm.clone" {
|
||||
vcsim_env
|
||||
vm=$(new_empty_vm)
|
||||
clone=$(new_id)
|
||||
|
||||
run govc vm.clone -vm $vm $clone
|
||||
assert_success
|
||||
|
||||
result=$(govc device.ls -vm $clone | grep disk- | wc -l)
|
||||
[ $result -eq 0 ]
|
||||
|
||||
result=$(govc device.ls -vm $clone | grep cdrom- | wc -l)
|
||||
[ $result -eq 0 ]
|
||||
}
|
||||
|
||||
@test "vm.clone change resources" {
|
||||
vcsim_env
|
||||
vm=$(new_ttylinux_vm)
|
||||
clone=$(new_id)
|
||||
|
||||
run govc vm.clone -m 1024 -c 2 -vm $vm $clone
|
||||
assert_success
|
||||
|
||||
run govc vm.info $clone
|
||||
assert_success
|
||||
assert_line "Memory: 1024MB"
|
||||
assert_line "CPU: 2 vCPU(s)"
|
||||
}
|
||||
|
||||
@test "vm.clone usage" {
|
||||
# validate we require -vm flag
|
||||
run govc vm.clone enoent
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "vm.migrate" {
|
||||
vcsim_env
|
||||
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 "vm.snapshot" {
|
||||
vm=$(new_ttylinux_vm)
|
||||
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.create -vm "$vm" child
|
||||
assert_success
|
||||
|
||||
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
|
||||
|
||||
# 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 ]
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user