Files
vagrant-libvirt/tests/runtests.bats
Richard Turc 225237b125 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
2021-05-08 17:04:10 +01:00

133 lines
3.0 KiB
Bash

SCRIPT_DIR="$( cd "$BATS_TEST_DIRNAME" &> /dev/null && pwd )"
export PATH=$(dirname ${SCRIPT_DIR})/bin:${PATH}
VAGRANT_CMD=vagrant
VAGRANT_OPT="--provider=libvirt"
TEMPDIR=
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() {
[ -n "${TEMPDIR:-}" ] && [ -d "${TEMPDIR:-}" ] && rm -rf ${TEMPDIR}
}
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 ]
cleanup
}
@test "bring up with two disks" {
export VAGRANT_CWD=tests/two_disks
cleanup
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
}
@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
}
@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
}