Added automated testing via tox and zuul.

Tweaked tests/basic_test.sh functional test so that it no longer
requires multpass, and can run without kvm cpu extensions being
enabled (not all machines in the game have cpu extensions.)

Added tox.ini, wrapper script for building and installation, etc.

Change-Id: I968116dd7bec412a55813c896d60cfc86c7070db
This commit is contained in:
Pete Vander Giessen 2019-07-17 20:11:28 +00:00 committed by James Page
parent 96c94f0cf5
commit 8ea5dc8679
8 changed files with 113 additions and 40 deletions

4
.gitreview Normal file
View File

@ -0,0 +1,4 @@
[gerrit]
host=review.opendev.org
port=29418
project=x/microstack.git

13
.zuul.yaml Normal file
View File

@ -0,0 +1,13 @@
- job:
name: microstack-tox-snap-with-sudo
parent: openstack-tox-snap-with-sudo
timeout: 3600
nodeset: ubuntu-bionic
- project:
check:
jobs:
- microstack-tox-snap-with-sudo
gate:
jobs:
- microstack-tox-snap-with-sudo

View File

@ -59,8 +59,8 @@ while :; do
fi fi
if [[ $(openstack server list | grep $SERVER | grep ERROR) ]]; then if [[ $(openstack server list | grep $SERVER | grep ERROR) ]]; then
openstack server list openstack server list
echo "Uh-oh. There was an error. See /var/snap/microstack/common/logs for details." echo "Uh-oh. There was an error. See /var/snap/microstack/common/log for details."
break exit 1
fi fi
done done

View File

@ -551,6 +551,7 @@ parts:
- libcaca0 - libcaca0
- libfdt1 - libfdt1
- libflac8 - libflac8
- libglu1-mesa
- libiscsi7 - libiscsi7
- libjpeg-turbo8 - libjpeg-turbo8
- libnspr4 - libnspr4
@ -562,6 +563,7 @@ parts:
- librados2 - librados2
- librbd1 - librbd1
- libsdl1.2debian - libsdl1.2debian
- libslang2
- libsndfile1 - libsndfile1
- libusb-1.0-0 - libusb-1.0-0
- libusbredirparser1 - libusbredirparser1
@ -573,6 +575,7 @@ parts:
- libxdmcp6 - libxdmcp6
- libxen-dev - libxen-dev
- libxext6 - libxext6
- libpng16-16
build-packages: build-packages:
- acpica-tools - acpica-tools
- libaio-dev - libaio-dev

1
test-requirements.txt Normal file
View File

@ -0,0 +1 @@
petname

View File

@ -5,91 +5,112 @@
# microstack snap, spin up a test instance, and verify that the test # microstack snap, spin up a test instance, and verify that the test
# instance is accessible, and can access the Internet. # instance is accessible, and can access the Internet.
# #
# The multipass snap and the petname debian package must be installed
# on the host system in order to run this test.
#
# The basic test accepts two command line arguments: # The basic test accepts two command line arguments:
# #
# -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.
# #
# -d <distro> # Specifies the distro of the multipass vm.
#
############################################################################## ##############################################################################
# Configuration and checks # Configuration and checks
set -ex set -ex
UPGRADE_FROM="none" export PATH=/snap/bin:$PATH
DISTRO=18.04
while getopts u:d: option UPGRADE_FROM="none"
FORCE_QEMU=false
while getopts u:d:q option
do do
case "${option}" case "${option}"
in in
u) UPGRADE_FROM=${OPTARG};; u) UPGRADE_FROM=${OPTARG};;
d) DISTRO=${OPTARG};; q) FORCE_QEMU=true
esac esac
done done
command -v multipass > /dev/null || (echo "Please install multipass."; exit 1);
command -v petname > /dev/null || (echo "Please install petname."; exit 1);
if [ ! -f microstack_rocky_amd64.snap ]; then if [ ! -f microstack_rocky_amd64.snap ]; then
echo "microstack_rocky_amd64.snap not found." echo "microstack_rocky_amd64.snap not found."
echo "Please run snapcraft before executing the tests." echo "Please run snapcraft before executing the tests."
exit 1 exit 1
fi fi
MACHINE=$(petname) # Functions
dump_logs () {
export DUMP_DIR=/tmp
if [ $(whoami) == 'zuul' ]; then
export DUMP_DIR="/home/zuul/zuul-output/logs";
fi
sudo tar cvzf $DUMP_DIR/dump.tar.gz \
/var/snap/microstack/common/log \
/var/log/syslog
sudo journalctl -xe --no-pager
}
# Setup # Setup
echo "++++++++++++++++++++++++++++++++++++++++++++++++++" echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "++ Starting tests on $MACHINE. ++" echo "++ Starting tests on localhost ++"
echo "++ Distro: $DISTRO ++"
echo "++ Upgrade from: $UPGRADE_FROM ++" echo "++ Upgrade from: $UPGRADE_FROM ++"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++" echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
# Launch a machine and copy the snap to it.
multipass launch --cpus 2 --mem 16G $DISTRO --name $MACHINE
multipass copy-files microstack_rocky_amd64.snap $MACHINE:
# 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
multipass exec $MACHINE -- sudo snap install --classic \ sudo snap install --classic --${UPGRADE_FROM} microstack
--${UPGRADE_FROM} microstack
fi fi
# Install the snap under test # Install the snap under test
multipass exec $MACHINE -- \ sudo snap install --classic --dangerous microstack*.snap
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.
#multipass exec $MACHINE -- \ # sudo snap install --classic --edge microstack
# sudo snap install --classic --edge microstack
# If kvm processor extensions not supported, switch to qemu
# TODO: just do this in the install step of the snap
if ! [ $(egrep "vmx|svm" /proc/cpuinfo | wc -l) -gt 0 ]; then
FORCE_QEMU=true;
fi
if [ "$FORCE_QEMU" == "true" ]; then
cat<<EOF > /tmp/hypervisor.conf
[DEFAULT]
compute_driver = libvirt.LibvirtDriver
[workarounds]
disable_rootwrap = True
[libvirt]
virt_type = qemu
cpu_mode = host-model
EOF
sudo cp /tmp/hypervisor.conf \
/var/snap/microstack/common/etc/nova/nova.conf.d/hypervisor.conf
sudo snap restart microstack
fi
# Run microstack.launch # Run microstack.launch
multipass exec $MACHINE -- /snap/bin/microstack.launch breakfast /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 ! multipass exec $MACHINE -- /snap/bin/microstack.openstack endpoint list | grep "10.20.20.1"; then if ! /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 multipass exec $MACHINE -- /snap/bin/microstack.openstack endpoint list | grep "localhost"; then if /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=$(multipass exec $MACHINE -- /snap/bin/microstack.openstack server list | grep breakfast | cut -d" " -f9) IP=$(/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=20 MAX_PINGS=40 # We might sometimes be testing qemu emulation, so we
until multipass exec $MACHINE -- ping -c 1 $IP &>/dev/null; do # want to give this some time ...
until 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!";
@ -98,9 +119,9 @@ until multipass exec $MACHINE -- ping -c 1 $IP &>/dev/null; do
done; done;
ATTEMPTS=1 ATTEMPTS=1
MAX_ATTEMPTS=20 MAX_ATTEMPTS=40 # See above for note about qemu
until multipass exec $MACHINE -- \ until ssh -oStrictHostKeyChecking=no -i \
ssh -oStrictHostKeyChecking=no -i .ssh/id_microstack cirros@$IP -- \ $HOME/.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
@ -113,9 +134,6 @@ done;
# Cleanup # Cleanup
unset IP unset IP
echo "++++++++++++++++++++++++++++++++++++++++++++++++++" echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "++ Completed tests. Tearing down $MACHINE. ++" echo "++ Completed tests. Uninstalling microstack ++"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++" echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
multipass stop $MACHINE sudo snap remove microstack
multipass delete $MACHINE
multipass purge # This is a little bit rude to do, but we assume that
# we can beat up on the test machine a bit.

16
tools/install_and_build.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
set -ex
export PATH=/snap/bin:$PATH
which nc || sudo apt install -y netcat
sudo apt update
sudo apt install -y snapd
sudo snap install --classic snapcraft
sudo snap install --classic lxd
sudo lxd init --auto
sudo snapcraft --use-lxd

18
tox.ini Normal file
View File

@ -0,0 +1,18 @@
[tox]
envlist = snap
skipsdist = True
[testenv]
install_command = pip install {opts} {packages}
setenv =
PATH = {env:PATH}:/snap/bin
passenv = HOME TERM
whitelist_externals =
sudo
/snap/bin/snapcraft
[testenv:snap]
deps = -r{toxinidir}/test-requirements.txt
commands =
{toxinidir}/tools/install_and_build.sh
{toxinidir}/tests/basic-test.sh