Added support for testing in multipass vms back to basic_test

Script now takes a "-m" argument. This helps to test locally in a
fresh environment.

Change-Id: I7848070cfdf809f084a107f23112fcfc71e11bf4
This commit is contained in:
Pete Vander Giessen 2019-07-24 19:57:03 +00:00
parent 8ea5dc8679
commit 59551ca2cd
1 changed files with 52 additions and 20 deletions

View File

@ -9,6 +9,9 @@
# #
# -u <channel> # First installs a released snap from the named # -u <channel> # First installs a released snap from the named
# # channel, in order to test basic upgrade functionality. # # channel, in order to test basic upgrade functionality.
# -m # Run tests in a multipass machine.
# -d <distro> # Ubuntu distro of the multipass machine to run tests
# # within. Defaults to bionic.
# #
############################################################################## ##############################################################################
@ -19,13 +22,16 @@ export PATH=/snap/bin:$PATH
UPGRADE_FROM="none" UPGRADE_FROM="none"
FORCE_QEMU=false FORCE_QEMU=false
PREFIX=""
DISTRO="bionic"
while getopts u:d:q option while getopts u:d:mq option
do do
case "${option}" case "${option}"
in in
u) UPGRADE_FROM=${OPTARG};; u) UPGRADE_FROM=${OPTARG};;
q) FORCE_QEMU=true q) FORCE_QEMU=true;;
m) PREFIX="multipass";;
esac esac
done done
@ -41,10 +47,14 @@ dump_logs () {
if [ $(whoami) == 'zuul' ]; then if [ $(whoami) == 'zuul' ]; then
export DUMP_DIR="/home/zuul/zuul-output/logs"; export DUMP_DIR="/home/zuul/zuul-output/logs";
fi fi
sudo tar cvzf $DUMP_DIR/dump.tar.gz \ $PREFIX sudo journalctl -xe --no-pager > /tmp/journalctl.output
$PREFIX sudo tar cvzf $DUMP_DIR/dump.tar.gz \
/var/snap/microstack/common/log \ /var/snap/microstack/common/log \
/var/log/syslog /var/log/syslog \
sudo journalctl -xe --no-pager /tmp/journalctl.output
if [[ $PREFIX == *"multipass"* ]]; then
multipass copy-files $MACHINE:/tmp/dump.tar.gz .
fi
} }
# Setup # Setup
@ -53,22 +63,33 @@ echo "++ Starting tests on localhost ++"
echo "++ Upgrade from: $UPGRADE_FROM ++" echo "++ Upgrade from: $UPGRADE_FROM ++"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++" echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
# Possibly run in a multipass machine
if [ "$PREFIX" == "multipass" ]; then
sudo snap install --classic --edge multipass
which petname || sudo snap install petname
MACHINE=$(petname)
PREFIX="multipass exec $MACHINE --"
multipass launch --cpus 2 --mem 16G $DISTRO --name $MACHINE
multipass copy-files microstack_rocky_amd64.snap $MACHINE:
fi
# Possibly install a release of the snap before running a test. # Possibly install a release of the snap before running a test.
if [ "${UPGRADE_FROM}" != "none" ]; then if [ "${UPGRADE_FROM}" != "none" ]; then
sudo snap install --classic --${UPGRADE_FROM} microstack $PREFIX sudo snap install --classic --${UPGRADE_FROM} microstack
fi fi
# Install the snap under test # Install the snap under test
sudo snap install --classic --dangerous microstack*.snap $PREFIX sudo snap install --classic --dangerous microstack*.snap
# Comment out the above and uncomment below to install the version of # Comment out the above and uncomment below to install the version of
# the snap from the store. # the snap from the store.
# TODO: add this as a flag. # TODO: add this as a flag.
# sudo snap install --classic --edge microstack # $PREFIX sudo snap install --classic --edge microstack
# If kvm processor extensions not supported, switch to qemu # If kvm processor extensions not supported, switch to qemu
# TODO: just do this in the install step of the snap # TODO: just do this in the install step of the snap
if ! [ $(egrep "vmx|svm" /proc/cpuinfo | wc -l) -gt 0 ]; then if ! [ $($PREFIX egrep "vmx|svm" /proc/cpuinfo | wc -l) -gt 0 ]; then
FORCE_QEMU=true; FORCE_QEMU=true;
fi fi
if [ "$FORCE_QEMU" == "true" ]; then if [ "$FORCE_QEMU" == "true" ]; then
@ -83,34 +104,37 @@ disable_rootwrap = True
virt_type = qemu virt_type = qemu
cpu_mode = host-model cpu_mode = host-model
EOF EOF
sudo cp /tmp/hypervisor.conf \ if [[ $PREFIX == *"multipass"* ]]; then
multipass copy-files /tmp/hypervisor.conf $MACHINE:/tmp/hypervisor.conf
fi
$PREFIX sudo cp /tmp/hypervisor.conf \
/var/snap/microstack/common/etc/nova/nova.conf.d/hypervisor.conf /var/snap/microstack/common/etc/nova/nova.conf.d/hypervisor.conf
sudo snap restart microstack $PREFIX sudo snap restart microstack
fi fi
# Run microstack.launch # Run microstack.launch
/snap/bin/microstack.launch breakfast || (dump_logs && exit 1) $PREFIX /snap/bin/microstack.launch breakfast || (dump_logs && exit 1)
# Verify that endpoints are setup correctly # Verify that endpoints are setup correctly
# List of endpoints should contain 10.20.20.1 # List of endpoints should contain 10.20.20.1
if ! /snap/bin/microstack.openstack endpoint list | grep "10.20.20.1"; then if ! $PREFIX /snap/bin/microstack.openstack endpoint list | grep "10.20.20.1"; then
echo "Endpoints are not set to 10.20.20.1!"; echo "Endpoints are not set to 10.20.20.1!";
exit 1; exit 1;
fi fi
# List of endpoints should not contain localhost # List of endpoints should not contain localhost
if /snap/bin/microstack.openstack endpoint list | grep "localhost"; then if $PREFIX /snap/bin/microstack.openstack endpoint list | grep "localhost"; then
echo "Endpoints are not set to 10.20.20.1!"; echo "Endpoints are not set to 10.20.20.1!";
exit 1; exit 1;
fi fi
# Verify that microstack.launch completed # Verify that microstack.launch completed
IP=$(/snap/bin/microstack.openstack server list | grep breakfast | cut -d" " -f9) IP=$($PREFIX /snap/bin/microstack.openstack server list | grep breakfast | cut -d" " -f9)
echo "Waiting for ping..." echo "Waiting for ping..."
PINGS=1 PINGS=1
MAX_PINGS=40 # We might sometimes be testing qemu emulation, so we MAX_PINGS=40 # We might sometimes be testing qemu emulation, so we
# want to give this some time ... # want to give this some time ...
until ping -c 1 $IP &>/dev/null; do until $PREFIX ping -c 1 $IP &>/dev/null; do
PINGS=$(($PINGS + 1)); PINGS=$(($PINGS + 1));
if test $PINGS -gt $MAX_PINGS; then if test $PINGS -gt $MAX_PINGS; then
echo "Unable to ping machine!"; echo "Unable to ping machine!";
@ -120,8 +144,11 @@ done;
ATTEMPTS=1 ATTEMPTS=1
MAX_ATTEMPTS=40 # See above for note about qemu MAX_ATTEMPTS=40 # See above for note about qemu
until ssh -oStrictHostKeyChecking=no -i \ USERNAME=$($PREFIX whoami | tr -d '\r') # Possibly get username from
$HOME/.ssh/id_microstack cirros@$IP -- \ # remote host, for use in
# composing home dir below.
until $PREFIX ssh -oStrictHostKeyChecking=no -i \
/home/$USERNAME/.ssh/id_microstack cirros@$IP -- \
ping -c 1 91.189.94.250; do ping -c 1 91.189.94.250; do
ATTEMPTS=$(($ATTEMPTS + 1)); ATTEMPTS=$(($ATTEMPTS + 1));
if test $ATTEMPTS -gt $MAX_ATTEMPTS; then if test $ATTEMPTS -gt $MAX_ATTEMPTS; then
@ -134,6 +161,11 @@ done;
# Cleanup # Cleanup
unset IP unset IP
echo "++++++++++++++++++++++++++++++++++++++++++++++++++" echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "++ Completed tests. Uninstalling microstack ++" echo "++ Completed tests. Cleaning up ++"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++" echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
sudo snap remove microstack if [[ $PREFIX == *"multipass"* ]]; then
sudo multipass delete $MACHINE
sudo multipass purge
else
$PREFIX sudo snap remove microstack
fi