Skip to content

Commit

Permalink
Support external tempest plugins
Browse files Browse the repository at this point in the history
This patch adds support for the tempest container to be able to install
external plugins that are not part of the .rpms the container is
built with.

When a user defines the TEMPEST_EXTERNAL_PLUGIN_GIT_URLS then plugin(s)
defined by this variable will be downloaded and executed. The user
can also define TEMPEST_EXTERNAL_PLUGIN_CHANGE_URLS and
TEMPEST_EXTERNAL_PLUGIN_REFSPEC variable to download a change(s) for a
given plugin. This can be used for testing tests under developoment.

TEMPEST_EXTERNAL_PLUGIN_GIT_URLS
    - URL of a git repository that holds the plugin

TEMPEST_EXTERNAL_PLUGIN_CHANGE_URLS
    - URL from which a change should be downloaded for a given plugin

TEMPEST_EXTERNAL_PLUGIN_REFSPEC
    - A change that should be downloaded for a given plugin
  • Loading branch information
lpiwowar committed Nov 23, 2023
1 parent 1339555 commit 41f7c9d
Showing 1 changed file with 94 additions and 25 deletions.
119 changes: 94 additions & 25 deletions container-images/tcib/base/os/tempest/run_tempest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -x

HOMEDIR=/var/lib/tempest
TEMPEST_PATH=$HOMEDIR/
TEMPEST_DIR=$HOMEDIR/openshift
CONCURRENCY="${CONCURRENCY:-}"
TEMPESTCONF_ARGS=""
Expand Down Expand Up @@ -31,7 +32,22 @@ TEMPEST_ARGS=""
[[ ! -z ${TEMPESTCONF_FLAVOR_MIN_DISK} ]] && TEMPESTCONF_ARGS+="--flavor-min-disk ${TEMPESTCONF_FLAVOR_MIN_DISK} "
[[ ! -z ${TEMPESTCONF_NETWORK_ID} ]] && TEMPESTCONF_ARGS+="--network-id ${TEMPESTCONF_NETWORK_ID} "

TEMPESTCONF_OVERRIDES="$(echo ${TEMPESTCONF_OVERRIDES} | tr '\n' ' ') identity.v3_endpoint_type public"

# Tempest arguments
TEMPEST_EXTERNAL_PLUGIN_GIT_URLS="${TEMPEST_EXTERNAL_PLUGIN_GIT_URLS:-}"
TEMPEST_EXTERNAL_PLUGIN_CHANGE_URLS="${TEMPEST_EXTERNAL_PLUGIN_CHANGE_URLS:-}"
TEMPEST_EXTERNAL_PLUGIN_REFSPEC="${TEMPEST_EXTERNAL_PLUGIN_REFSPEC:-}"
TEMPEST_EXTERNAL_PLUGIN_DIR=/var/lib/tempest/external-plugins

# Convert comma separated lists to arrays
OLD_IFS=$IFS
IFS=","
read -ra TEMPEST_EXTERNAL_PLUGIN_GIT_URLS <<< $TEMPEST_EXTERNAL_PLUGIN_GIT_URLS
read -ra TEMPEST_EXTERNAL_PLUGIN_CHANGE_URLS <<< $TEMPEST_EXTERNAL_PLUGIN_CHANGE_URLS
read -ra TEMPEST_EXTERNAL_PLUGIN_REFSPEC <<< $TEMPEST_EXTERNAL_PLUGIN_REFSPEC
IFS=$OLD_IFS

[[ ${TEMPEST_SMOKE} == true ]] && TEMPEST_ARGS+="--smoke "
[[ ${TEMPEST_PARALLEL:=true} == true ]] && TEMPEST_ARGS+="--parallel "
[[ ${TEMPEST_SERIAL} == true ]] && TEMPEST_ARGS+="--serial "
Expand All @@ -55,17 +71,86 @@ if [[ ! -z ${TEMPESTCONF_REMOVE} ]]; then
done <<< "$TEMPESTCONF_REMOVE"
fi

TEMPESTCONF_OVERRIDES="$(echo ${TEMPESTCONF_OVERRIDES} | tr '\n' ' ') identity.v3_endpoint_type public"

if [ -n "$CONCURRENCY" ] && [ -z ${TEMPEST_CONCURRENCY} ]; then
TEMPEST_ARGS+="--concurrency ${CONCURRENCY} "
fi

pushd $HOMEDIR
function run_git_tempest() {
mkdir -p $TEMPEST_EXTERNAL_PLUGIN_DIR
pushd $TEMPEST_EXTERNAL_PLUGIN_DIR

python3 -m venv .venv
source ./.venv/bin/activate

for plugin_index in "${!TEMPEST_EXTERNAL_PLUGIN_GIT_URLS[@]}"
do
git_url=${TEMPEST_EXTERNAL_PLUGIN_GIT_URLS[plugin_index]}
change_url=${TEMPEST_EXTERNAL_PLUGIN_CHANGE_URLS[plugin_index]}
refspec=${TEMPEST_EXTERNAL_PLUGIN_REFSPEC[plugin_index]}
plugin_name=$(basename -s .git $git_url)

git clone $git_url

if [[ ! -z $change_url ]] || [[ ! -z $refspec ]] || \
[[ $change_url = "-" ]] || [[ $refspec = "-" ]]; then
pushd $plugin_name
git fetch $change_url $refspec
git checkout FETCH_HEAD
popd
fi

pip install ./$plugin_name
done

pushd $HOMEDIR
tempest init openshift
pushd $TEMPEST_DIR

discover-tempest-config ${TEMPESTCONF_ARGS} ${TEMPESTCONF_OVERRIDES}
tempest run ${TEMPEST_ARGS}
RETURN_VALUE=$?

deactivate

popd
popd
popd
}

function run_rpm_tempest() {
pushd $HOMEDIR
tempest init openshift
pushd $TEMPEST_DIR

discover-tempest-config ${TEMPESTCONF_ARGS} ${TEMPESTCONF_OVERRIDES}
tempest run ${TEMPEST_ARGS}
RETURN_VALUE=$?

popd
popd
}

function generate_test_results() {
pushd $TEMPEST_DIR

echo "Generate subunit"
stestr last --subunit > ${TEMPEST_PATH}testrepository.subunit || true

echo "Generate subunit xml file"
subunit2junitxml ${TEMPEST_PATH}testrepository.subunit > ${TEMPEST_PATH}tempest_results.xml || true

echo "Generate html result"
subunit2html ${TEMPEST_PATH}testrepository.subunit ${TEMPEST_PATH}stestr_results.html || true

echo Copying logs file
cp -rf ${TEMPEST_DIR}/* ${TEMPEST_PATH}

popd
}

export OS_CLOUD=default

TEMPEST_PATH=$HOMEDIR/
if [ ! -z ${USE_EXTERNAL_FILES} ]; then
TEMPEST_PATH=$HOMEDIR/external_files/
mkdir -p $HOME/.config/openstack
Expand All @@ -84,28 +169,12 @@ if [ ! -f ${TEMPEST_PATH}exclude.txt ] && [ -z ${TEMPEST_EXCLUDE_LIST} ]; then
touch ${TEMPEST_PATH}exclude.txt
fi

tempest init openshift

pushd $TEMPEST_DIR
discover-tempest-config ${TEMPESTCONF_ARGS} ${TEMPESTCONF_OVERRIDES}

tempest run ${TEMPEST_ARGS}

RETURN_VALUE=$?

echo "Generate subunit"
stestr last --subunit > ${TEMPEST_PATH}testrepository.subunit || true

echo "Generate subunit xml file"
subunit2junitxml ${TEMPEST_PATH}testrepository.subunit > ${TEMPEST_PATH}tempest_results.xml || true

echo "Generate html result"
subunit2html ${TEMPEST_PATH}testrepository.subunit ${TEMPEST_PATH}stestr_results.html || true
if [ -z $TEMPEST_EXTERNAL_PLUGIN_GIT_URLS ]; then
run_rpm_tempest
else
run_git_tempest
fi

echo Copying logs file
cp -rf ${TEMPEST_DIR}/* ${TEMPEST_PATH}
generate_test_results

exit ${RETURN_VALUE}

popd
popd

0 comments on commit 41f7c9d

Please sign in to comment.