2021-03-21 13:06:52 +01:00
|
|
|
SCRIPT_DIR="$( cd "$BATS_TEST_DIRNAME" &> /dev/null && pwd )"
|
|
|
|
|
export PATH=$(dirname ${SCRIPT_DIR})/bin:${PATH}
|
|
|
|
|
|
2021-06-09 22:16:15 +02:00
|
|
|
VAGRANT_CMD="vagrant"
|
2021-03-21 13:06:52 +01:00
|
|
|
VAGRANT_OPT="--provider=libvirt"
|
|
|
|
|
|
|
|
|
|
TEMPDIR=
|
|
|
|
|
|
Allow to use many disks in vagrant box for libvirt provider
Adds support for a new multi disk box format and handling to upload the
multiple disks to the storage pool.
New format is:
{
'disks': [
{
'name': 'disk1.img',
'virtual_size': 10,
'format': 'qcow2'
},
{
'name': 'disk2.img',
'virtual_size': 15,
'format': 'qcow2'
},
{
'name': 'disk3.img',
}
],
'provider': 'libvirt',
'format': 'qcow2'
}
It is expected to remove format from being set at the top level when
using the new format, with the assuming that qcow2 should be the default
format, and other formats should be permitted to be specified as needed.
Includes tests for handling the box images and creation of domain
volumes. Additionally includes an integration test to ensure a box with
2 disks will work as expected.
Partially fixes: #602
2020-09-10 10:03:00 +02:00
|
|
|
|
2021-03-21 13:06:52 +01:00
|
|
|
setup_file() {
|
|
|
|
|
# set VAGRANT_HOME to something else to reuse for tests to avoid clashes with
|
|
|
|
|
# user installed plugins when running tests locally.
|
|
|
|
|
if [ -z "${VAGRANT_HOME:-}" ]
|
|
|
|
|
then
|
|
|
|
|
TEMPDIR=$(mktemp -d 2>/dev/null)
|
|
|
|
|
|
|
|
|
|
export VAGRANT_HOME=${TEMPDIR}/.vagrant.d
|
|
|
|
|
echo "# Using ${VAGRANT_HOME} for VAGRANT_HOME" >&3
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
teardown_file() {
|
2021-05-14 19:11:33 +01:00
|
|
|
if [ -n "${TEMPDIR:-}" ] && [ -d "${TEMPDIR:-}" ]
|
|
|
|
|
then
|
|
|
|
|
rm -rf ${TEMPDIR:-}
|
|
|
|
|
fi
|
2021-03-21 13:06:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
|
${VAGRANT_CMD} destroy -f
|
|
|
|
|
if [ $? == "0" ]; then
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "destroy simple vm" {
|
|
|
|
|
export VAGRANT_LOG=debug
|
|
|
|
|
export VAGRANT_CWD=tests/simple
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
cleanup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "simple vm provision via shell" {
|
|
|
|
|
export VAGRANT_CWD=tests/simple_provision_shell
|
|
|
|
|
cleanup
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
echo "${output}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
[ $(expr "$output" : ".*Hello.*") -ne 0 ]
|
|
|
|
|
echo "${output}"
|
|
|
|
|
cleanup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "bring up with custom default prefix" {
|
|
|
|
|
export VAGRANT_CWD=tests/default_prefix
|
|
|
|
|
cleanup
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ $(expr "$output" : ".*changed_default_prefixdefault.*") -ne 0 ]
|
|
|
|
|
echo "${output}"
|
|
|
|
|
cleanup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "bring up with second disk" {
|
|
|
|
|
export VAGRANT_CWD=tests/second_disk
|
|
|
|
|
cleanup
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
echo "${output}"
|
|
|
|
|
[ $(expr "$output" : ".*second_disk_default-vdb.*") -ne 0 ]
|
2022-06-02 19:09:18 +01:00
|
|
|
run ${VAGRANT_CMD} halt
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
2021-03-21 13:06:52 +01:00
|
|
|
cleanup
|
|
|
|
|
}
|
|
|
|
|
|
Allow to use many disks in vagrant box for libvirt provider
Adds support for a new multi disk box format and handling to upload the
multiple disks to the storage pool.
New format is:
{
'disks': [
{
'name': 'disk1.img',
'virtual_size': 10,
'format': 'qcow2'
},
{
'name': 'disk2.img',
'virtual_size': 15,
'format': 'qcow2'
},
{
'name': 'disk3.img',
}
],
'provider': 'libvirt',
'format': 'qcow2'
}
It is expected to remove format from being set at the top level when
using the new format, with the assuming that qcow2 should be the default
format, and other formats should be permitted to be specified as needed.
Includes tests for handling the box images and creation of domain
volumes. Additionally includes an integration test to ensure a box with
2 disks will work as expected.
Partially fixes: #602
2020-09-10 10:03:00 +02:00
|
|
|
@test "bring up with two disks" {
|
|
|
|
|
export VAGRANT_CWD=tests/two_disks
|
|
|
|
|
cleanup
|
2021-05-14 19:11:33 +01:00
|
|
|
tools/create_box_with_two_disks.sh ${VAGRANT_HOME} ${VAGRANT_CMD}
|
Allow to use many disks in vagrant box for libvirt provider
Adds support for a new multi disk box format and handling to upload the
multiple disks to the storage pool.
New format is:
{
'disks': [
{
'name': 'disk1.img',
'virtual_size': 10,
'format': 'qcow2'
},
{
'name': 'disk2.img',
'virtual_size': 15,
'format': 'qcow2'
},
{
'name': 'disk3.img',
}
],
'provider': 'libvirt',
'format': 'qcow2'
}
It is expected to remove format from being set at the top level when
using the new format, with the assuming that qcow2 should be the default
format, and other formats should be permitted to be specified as needed.
Includes tests for handling the box images and creation of domain
volumes. Additionally includes an integration test to ensure a box with
2 disks will work as expected.
Partially fixes: #602
2020-09-10 10:03:00 +02:00
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
echo "${output}"
|
|
|
|
|
[ $(expr "$output" : ".*Image.*2G") -ne 0 ]
|
|
|
|
|
[ $(expr "$output" : ".*Image.*10G") -ne 0 ]
|
|
|
|
|
cleanup
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 13:06:52 +01:00
|
|
|
@test "bring up with adjusted memory settings" {
|
|
|
|
|
export VAGRANT_CWD=tests/memory
|
|
|
|
|
cleanup
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
echo "${output}"
|
|
|
|
|
[ $(expr "$output" : ".*Memory.*1000M.*") -ne 0 ]
|
|
|
|
|
cleanup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "bring up with adjusted cpu settings" {
|
|
|
|
|
export VAGRANT_CWD=tests/cpus
|
|
|
|
|
cleanup
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
echo "${output}"
|
|
|
|
|
[ $(expr "$output" : ".*Cpus.*2.*") -ne 0 ]
|
|
|
|
|
cleanup
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 11:41:19 +02:00
|
|
|
@test "bring up and use qemu agent for connectivity" {
|
|
|
|
|
export VAGRANT_CWD=tests/qemu_agent
|
|
|
|
|
cleanup
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
echo "${output}"
|
|
|
|
|
cleanup
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 13:06:52 +01:00
|
|
|
@test "ip is reachable with private network" {
|
|
|
|
|
export VAGRANT_CWD=tests/private_network
|
|
|
|
|
cleanup
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
echo "${output}"
|
|
|
|
|
[ $(expr "$output" : ".*Cpus.*2.*") -ne 0 ]
|
|
|
|
|
run fping 10.20.30.40
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
echo "${output}"
|
|
|
|
|
[ $(expr "$output" : ".*alive.*") -ne 0 ]
|
|
|
|
|
cleanup
|
|
|
|
|
}
|
2021-06-01 17:45:02 +01:00
|
|
|
|
|
|
|
|
@test "package simple domain" {
|
|
|
|
|
export VAGRANT_CWD=tests/package_simple
|
|
|
|
|
cleanup
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
2021-06-25 20:01:02 +01:00
|
|
|
rm -f package.box
|
|
|
|
|
run ${VAGRANT_CMD} package
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} destroy -f
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} box add --force package.box --name test-package-simple-domain
|
2021-06-01 17:45:02 +01:00
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
2021-06-25 20:01:02 +01:00
|
|
|
VAGRANT_VAGRANTFILE=Vagrantfile.testbox run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} box remove --force test-package-simple-domain
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
rm -f package.box
|
|
|
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "package complex example" {
|
|
|
|
|
export VAGRANT_CWD=tests/package_complex_example
|
|
|
|
|
# this will allow the host keys to be removed, and part of the sysprep script
|
|
|
|
|
# adds a step to trigger the regeneration.
|
|
|
|
|
export VAGRANT_LIBVIRT_VIRT_SYSPREP_OPERATIONS='defaults,-ssh-userdir,customize'
|
|
|
|
|
export VAGRANT_LIBVIRT_VIRT_SYSPREP_OPTIONS="--run $(pwd)/tests/package_complex_example/scripts/sysprep.sh"
|
|
|
|
|
cleanup
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
rm -f package.box
|
2021-06-01 17:45:02 +01:00
|
|
|
run ${VAGRANT_CMD} package
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
2021-06-25 20:01:02 +01:00
|
|
|
run ${VAGRANT_CMD} destroy -f
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} box add --force package.box --name test-package-complex-example
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
VAGRANT_VAGRANTFILE=Vagrantfile.testbox run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
2021-06-01 17:45:02 +01:00
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
2021-06-25 20:01:02 +01:00
|
|
|
run ${VAGRANT_CMD} box remove --force test-package-complex-example
|
2021-06-01 17:45:02 +01:00
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
rm -f package.box
|
|
|
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
}
|
2022-06-03 05:34:35 -04:00
|
|
|
|
|
|
|
|
@test "bring up and save a snapshot and restore it" {
|
|
|
|
|
export VAGRANT_CWD=tests/snapshot
|
|
|
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} ssh -- -t 'touch a.txt'
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} snapshot save default test
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} ssh -- -t 'rm a.txt'
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} ssh -- -t 'ls a.txt'
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
# This means that the file does not exist on the box.
|
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
|
run ${VAGRANT_CMD} ssh -- -t 'touch b.txt'
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} snapshot restore default test
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} ssh -- -t 'ls b.txt'
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
# This means that the file does not exist on the box.
|
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
|
run ${VAGRANT_CMD} ssh -- -t 'ls a.txt'
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
run ${VAGRANT_CMD} snapshot delete default test
|
|
|
|
|
echo "${output}"
|
|
|
|
|
echo "status = ${status}"
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
}
|