From: Iustin Pop <[email protected]> To allow _some_ testing of this code without Ganeti, let's add a simple test that exercises the create/export/import scripts.
There are a number of downsides to this script: - it needs real root (due to losetup/kpartx/chroot), so the script checks for this and exits if the requirement is not met; this means that during normal development this will not add usefulness - it does an actual install, so it needs network access - although I tried to be careful by disabling cache generation and cleanup, it might still touch the filesystem of the host machine, hence it's best to run it in a throwaway VM - it's not interactive: there's a single test, and it runs for a few minutes without any feedback; with automake's new test driver at least, there are (growing) log files in test/ which can be tail'ed However, when plugged in and tied to (e.g.) Debian's autopkgtest suite, it means that breakage such as https://bugs.launchpad.net/bugs/1577346 would have been detected automatically and much earlier. Additionally, I had to bump the minimum automake version, since 1.9 is no longer present in modern distributions; even wheezy (oldstable) has 1.11 as default. Tested with 1.11 and 1.15. Signed-off-by: Iustin Pop <[email protected]> --- .gitignore | 3 +++ Makefile.am | 6 ++++- configure.ac | 2 +- test/install-export-import | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 test/install-export-import diff --git a/.gitignore b/.gitignore index 86141c4..f9daa52 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ /config.log /config.status /configure +/test-suite.log +/test/*.log +/test/*.trs # built scripts /common.sh diff --git a/Makefile.am b/Makefile.am index 26da9a2..cfc9f0e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,7 +27,8 @@ dist_example_DATA = \ EXTRA_DIST = \ common.sh.in \ - defaults + defaults \ + $(TESTS) do_subst = sed \ -e 's,[@]sysconfdir[@],$(sysconfdir),g' \ @@ -36,6 +37,9 @@ do_subst = sed \ common.sh: common.sh.in Makefile $(do_subst) < $< > $@ +TESTS = \ + test/install-export-import + install-exec-local: @mkdir_p@ $(variantsdir) touch $(variantsdir)/default.conf diff --git a/configure.ac b/configure.ac index 39f40cc..085eb4c 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(ganeti-instance-debootstrap, 0.15, [email protected]) AC_CONFIG_AUX_DIR(autotools) AC_CONFIG_SRCDIR(configure) -AM_INIT_AUTOMAKE([1.9 foreign tar-ustar -Wall -Wno-portability]) +AM_INIT_AUTOMAKE([1.11 foreign tar-ustar -Wall -Wno-portability]) # --with-os-dir=... AC_ARG_WITH([os-dir], diff --git a/test/install-export-import b/test/install-export-import new file mode 100755 index 0000000..e3b7d55 --- /dev/null +++ b/test/install-export-import @@ -0,0 +1,67 @@ +#!/bin/bash + +set -eu + +if [ $(id -u) != 0 ]; then + echo "Testing requires root due to losetup/kpartx usage" 2>&1 + exit 77 +fi + +TEMPDIR=$(mktemp -d) +trap 'rm -rf "$TEMPDIR"' EXIT + +DISK0="$TEMPDIR/disk0" +dd if=/dev/zero of="$DISK0" bs=1024k count=512 + +DUMP="$TEMPDIR/dump" + +# check that we can actually run losetup, otherwise we might be under +# fakeroot, for example; include sbin* dirs in PATH to ensure we don't +# fail due to command not found. +PATH=$PATH:/sbin:/usr/sbin +LOOP=$(losetup --show -f "$DISK0") || \ + { echo "losetup doesn't work, skipping test" 2>&1 ; + exit 77; + } +losetup -d "$LOOP" + +echo "Installing instance..." +GENERATE_CACHE=no \ + CLEAN_CACHE="" \ + OS_API_VERSION=10 \ + INSTANCE_NAME=foo.example.com \ + HYPERVISOR=dont-care \ + DISK_COUNT=1 \ + DISK_0_PATH="$DISK0" \ + $srcdir/create + +echo "Exporting instance..." + +OS_API_VERSION=10 \ + INSTANCE_NAME=foo.example.com \ + HYPERVISOR=dont-care \ + DISK_COUNT=1 \ + DISK_0_PATH="$DISK0" \ + EXPORT_DISK_PATH="$DISK0" \ + EXPORT_DEVICE="$DISK0" \ + EXPORT_INDEX=0 \ + $srcdir/export > "$DUMP" + +echo "Importing instance..." + +# first wipe the disk. +dd if=/dev/zero of="$DISK0" bs=1024k count=512 + +OS_API_VERSION=10 \ + INSTANCE_NAME=foo.example.com \ + HYPERVISOR=dont-care \ + DISK_COUNT=1 \ + DISK_0_PATH="$DISK0" \ + IMPORT_DISK_PATH="$DISK0" \ + IMPORT_DEVICE="$DISK0" \ + IMPORT_INDEX=0 \ + $srcdir/import < "$DUMP" + +# Do a listing of the directory (to see the size of the dump, a proxy +# for the needed install space). +ls -l -h "$TEMPDIR" -- 2.8.1
