From c895782e91ee64c0b070f9ea3d7fa2b4ee9b05c0 Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Fri, 27 Sep 2024 13:13:32 +0100 Subject: [PATCH] Add openstack regression test runner Run the Openstack release tests from charmed-openstack-tests. --- .../openstack_regression_tests_runner.sh | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 openstack/tools/openstack_regression_tests_runner.sh diff --git a/openstack/tools/openstack_regression_tests_runner.sh b/openstack/tools/openstack_regression_tests_runner.sh new file mode 100755 index 00000000..eb748acf --- /dev/null +++ b/openstack/tools/openstack_regression_tests_runner.sh @@ -0,0 +1,116 @@ +#!/bin/bash -eu +# +# Run Openstack regression tests. +# +FUNC_TEST_TARGET= +IMAGES_PATH=$HOME/tmp + +usage () { + cat << EOF +USAGE: `basename $0` OPTIONS + +Run Openstack regression tests. + +OPTIONS: + --func-test-target TARGET_NAME + Provide the name of a specific test target to run. + --help + This help message. +EOF +} + +while (($# > 0)); do + case "$1" in + --debug) + set -x + ;; + --func-test-target) + FUNC_TEST_TARGET=$2 + shift + ;; + --help|-h) + usage + exit 0 + ;; + *) + echo "ERROR: invalid input '$1'" + usage + exit 1 + ;; + esac + shift +done + +if [[ -z $FUNC_TEST_TARGET ]]; then + echo "ERROR: must provide a target name with --func-test-target" + exit 1 +fi + +# This is required for magnum tests and zaza will look in swift if it is not cached so we need to cache it first. +mkdir -p $IMAGES_PATH +if ! [[ -e $IMAGES_PATH/fedora-coreos-35.qcow2 ]]; then + wget https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/35.20220424.3.0/x86_64/fedora-coreos-35.20220424.3.0-openstack.x86_64.qcow2.xz -O $IMAGES_PATH/fedora-coreos-35.qcow2.xz + (cd $IMAGES_PATH; xz -d fedora-coreos-35.qcow2.xz; ) +fi + +# Install dependencies +which yq &>/dev/null || sudo snap install yq + +TOOLS_PATH=$(realpath $(dirname $0))/func_test_tools +CHARM_PATH=$(pwd) + +echo "Running regression tests" + +source ~/novarc +export {,TEST_}CIDR_EXT=`openstack subnet show subnet_${OS_USERNAME}-psd-extra -c cidr -f value` +FIP_MAX=$(ipcalc $CIDR_EXT| awk '$1=="HostMax:" {print $2}') +FIP_MIN=$(ipcalc $CIDR_EXT| awk '$1=="HostMin:" {print $2}') +FIP_MIN_ABC=${FIP_MIN%.*} +FIP_MIN_D=${FIP_MIN##*.} +FIP_MIN=${FIP_MIN_ABC}.$(($FIP_MIN_D + 64)) + +CIDR_OAM=`openstack subnet show subnet_${OS_USERNAME}-psd -c cidr -f value` +OAM_MAX=$(ipcalc $CIDR_OAM| awk '$1=="HostMax:" {print $2}') +OAM_MIN=$(ipcalc $CIDR_OAM| awk '$1=="HostMin:" {print $2}') +OAM_MIN_ABC=${OAM_MIN%.*} +OAM_MAX_D=${OAM_MAX##*.} +# Picking last two addresses and hoping they dont get used by Neutron. +export {OS,TEST}_VIP00=${OAM_MIN_ABC}.$(($OAM_MAX_D - 1)) +export {OS,TEST}_VIP01=${OAM_MIN_ABC}.$(($OAM_MAX_D - 2)) + +# More information on config https://github.com/openstack-charmers/zaza/blob/master/doc/source/runningcharmtests.rst +export {,TEST_}NET_ID=$(openstack network show net_${OS_USERNAME}-psd-extra -f value -c id) +export {,TEST_}FIP_RANGE=$FIP_MIN:$FIP_MAX +export {,TEST_}GATEWAY=$(openstack subnet show subnet_${OS_USERNAME}-psd-extra -c gateway_ip -f value) +export {,TEST_}NAME_SERVER=91.189.91.131 +export {,TEST_}CIDR_PRIV=192.168.21.0/24 +export {,TEST_}SWIFT_IP=10.140.56.22 +export TEST_MODEL_SETTINGS="image-stream=released;default-series=jammy;test-mode=true;transmit-vendor-metrics=false" +# We need to set TEST_JUJU3 as well as the constraints file +# Ref: https://github.com/openstack-charmers/zaza/blob/e96ab098f00951079fccb34bc38d4ae6ebb38606/setup.py#L47 +export TEST_JUJU3=1 + +# NOTE: this should not be necessary for > juju 2.x but since we still have a need for it we add it in +export TEST_ZAZA_BUG_LP1987332=1 + +# Some charms point to an upstream constraints file that installs python-libjuju 2.x so we need to do this to ensure we get 3.x +export TEST_CONSTRAINTS_FILE=https://raw.githubusercontent.com/openstack-charmers/zaza/master/constraints-juju34.txt + +LOGFILE=$(mktemp --suffix=-charm-func-test-results) +( + # Ensure charmed-openstack-tester checked out and up-to-date + if [[ -d $HOME/charmed-openstack-tester ]]; then + cd $HOME/charmed-openstack-tester + git checkout master + git pull + else + cd $HOME + git clone https://github.com/openstack-charmers/charmed-openstack-tester + cd charmed-openstack-tester + fi + + fail=false + tox -e func-target -- $FUNC_TEST_TARGET || fail=true + model=`juju list-models| egrep -o "^zaza-\S+"|tr -d '*'` +) 2>&1 | tee $LOGFILE +echo -e "\nResults also saved to $LOGFILE"