From: Tobias Brunner Date: Fri, 10 Oct 2014 16:37:13 +0000 (+0200) Subject: testing: Ensure no guest is running when modifying images X-Git-Tag: 5.2.1rc1~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=83efded3132735d5aaa5f8aca5eaaed1f8f99244;p=thirdparty%2Fstrongswan.git testing: Ensure no guest is running when modifying images Sometimes guests are not stopped properly. If images are then modified they will be corrupted. --- diff --git a/testing/scripts/build-baseimage b/testing/scripts/build-baseimage index 552e98c52f..075fd8e1e4 100755 --- a/testing/scripts/build-baseimage +++ b/testing/scripts/build-baseimage @@ -7,6 +7,7 @@ DIR=$(dirname `readlink -f $0`) . $DIR/function.sh [ `id -u` -eq 0 ] || die "You must be root to run $0" +running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0" check_commands debootstrap mkfs.ext3 partprobe qemu-img qemu-nbd sfdisk diff --git a/testing/scripts/build-guestimages b/testing/scripts/build-guestimages index 245fc25245..3e107c0620 100755 --- a/testing/scripts/build-guestimages +++ b/testing/scripts/build-guestimages @@ -25,6 +25,7 @@ HOSTSDIR=$DIR/../hosts [ `id -u` -eq 0 ] || die "You must be root to run $0" [ -f $ROOTIMG ] || die "Root image $ROOTIMG not found" [ -f $HOSTDIR ] || die "Hosts directory $HOSTSDIR not found" +running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0" check_commands partprobe qemu-img qemu-nbd diff --git a/testing/scripts/build-rootimage b/testing/scripts/build-rootimage index 8e10ce5f3a..a84104a901 100755 --- a/testing/scripts/build-rootimage +++ b/testing/scripts/build-rootimage @@ -22,6 +22,7 @@ DIR=$(dirname `readlink -f $0`) [ `id -u` -eq 0 ] || die "You must be root to run $0" [ -f "$BASEIMG" ] || die "Base image $BASEIMG not found" +running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0" check_commands partprobe qemu-img qemu-nbd diff --git a/testing/scripts/build-strongswan b/testing/scripts/build-strongswan index 69cb833cd3..c52dddda8d 100755 --- a/testing/scripts/build-strongswan +++ b/testing/scripts/build-strongswan @@ -12,6 +12,7 @@ SWANDIR=${1:+$(readlink -f $1)} [ `id -u` -eq 0 ] || die "You must be root to run $0" [ -f "$BASEIMG" ] || die "Base image $BASEIMG not found" [ -f "$ROOTIMG" ] || die "Root image $ROOTIMG not found" +running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0" [ -f $SWANDIR/src/libstrongswan/asn1/oid.txt ] || die "strongSwan not found in $SWANDIR" diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index c4769678c0..2dd465c859 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -156,6 +156,18 @@ check_commands() done } +# check if any of the given virtual guests are running +# $* - names of guests to check +running_any() +{ + command -v virsh >/dev/null || return 1 + for host in $* + do + virsh list --name | grep "^$host$" >/dev/null && return 0 + done + return 1 +} + ############################################# # search and replace strings throughout a # whole directory