Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions st2common/bin/st2-run-pack-tests
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ VIRTUALENV_ACTIVATED=false
STACKSTORM_VIRTUALENV_BIN="/opt/stackstorm/st2/bin"
STACKSTORM_VIRTUALENV_PYTHON_BINARY="${STACKSTORM_VIRTUALENV_BIN}/python"

PYTHON_3=false

####################
# Script beings here
####################
Expand All @@ -78,10 +80,11 @@ function usage() {
echo " and virtualenv, if any, for subsequent test runs." >&2
echo " -t : Run tests with timing enabled" >&2
echo " -v : Verbose mode (log debug messages to stdout)." >&2
echo " -3 : use python3" >&2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a flag that takes an argument rather than hard coding 3 (hint: use $OPTARG to get the version).

3 doesn't give any meaning to the purpose of the flag, using P would be better so there is an association with P for Python. It would be useful to be able to specify a version rather than just the major version. E.g. accept 3.6, 3.7, 3.8 to give pack developers the flexibility to test against a specific minor version.

Remember to document the flag in the Usage: $0 section of the output too.

echo " -x : Do not create virtualenv for test for tests, e.g. when running in existing one." >&2
}

while getopts ":p:f:xjvct" o; do
while getopts ":p:f:xjvct3" o; do
case "${o}" in
p)
PACK_PATH=${OPTARG}
Expand All @@ -104,6 +107,14 @@ while getopts ":p:f:xjvct" o; do
t)
ENABLE_TIMING=true
;;
3)
PYTHON_3=true
if [ -z "$ST2_REPO_PATH" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the python 3 flag short circuit the ST2_REPO_PATH logic which handles the case of its absence later in the script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most important part. This script will look for st2 libs in \opt\stsckstorm if i dont set this. On centos7 those are python 2.7. Maybe what we do here is check the system python version vs. The version passed in this flag. If they doffer then force this env var to be set.

echo "must set ST2_REPO_PATH variable"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A clearer error message explaining what the ST2_REPO_PATH variable is used for will help people set the correct value. e.g. Environment variable ST2_REPO_PATH must be set to your st2 installation or st2 git repository for pack tests to function correctly.

exit 1
fi
;;

\?)
echo "Invalid option: -$OPTARG" >&2
usage
Expand Down Expand Up @@ -192,8 +203,11 @@ if [ "${CREATE_VIRTUALENV}" = true ]; then
if [ "${JUST_TESTS}" = false ]; then
echo "Creating virtualenv in ${VIRTUALENV_DIR}..."
mkdir -p ${VIRTUALENVS_DIR}
virtualenv --no-download --system-site-packages ${VIRTUALENV_DIR}

if [ "${PYTHON_3}" = false ]; then
virtualenv --no-download --system-site-packages ${VIRTUALENV_DIR}
else
virtualenv --no-download --system-site-packages ${VIRTUALENV_DIR} -p python3
fi
# Activate the virtualenv
activate_virtualenv

Expand Down Expand Up @@ -279,9 +293,12 @@ TESTS_PYTHON_PATH=()
# 1. Add PYTHONPATH from StackStorm packages virtualenv (only applies when running on server when
# StackStorm is installed using packages)
if [ -f "${STACKSTORM_VIRTUALENV_PYTHON_BINARY}" ]; then
ST2_PYTHONPATH=$(${STACKSTORM_VIRTUALENV_PYTHON_BINARY} -c "import sys;print(':'.join([x for x in sys.path if x.strip()]))")
verbose_log "Adding entries from StackStorm virtualenv to PYTHONPATH: ${ST2_PYTHONPATH}"

if [ "${PYTHON_3}" = false ]; then
ST2_PYTHONPATH=$(${STACKSTORM_VIRTUALENV_PYTHON_BINARY} -c "import sys;print(':'.join([x for x in sys.path if x.strip()]))")
verbose_log "Adding entries from StackStorm virtualenv to PYTHONPATH: ${ST2_PYTHONPATH}"
else
verbose_log "skip Adding entries from StackStorm virtualenv to PYTHONPATH: ${ST2_PYTHONPATH}"
fi
TESTS_PYTHON_PATH+=("${ST2_PYTHONPATH}")
fi

Expand Down Expand Up @@ -314,7 +331,11 @@ fi
echo "Running tests..."
# Note: We run nosetests with "--exe" option so it also runs test files which are executable
# (pack install command automatically makes all the files, including test files executable)
NOSE_OPTS=(-s -v --exe --rednose --immediate)
if [ "${PYTHON_3}" = false ]; then
NOSE_OPTS=(-s -v --exe --rednose --immediate )
else
NOSE_OPTS=(-s -v --exe )
fi

# Is test coverage reporting enabled?
if [ "${ENABLE_COVERAGE}" = true ]; then
Expand Down