X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=csit%2Frun-csit.sh;h=9220ef9cbccc0ec331631594b49cd1a02e758321;hb=refs%2Fheads%2Fmaster;hp=52ec2186305390e3e4aa2649be80f6c351fa95b3;hpb=eaef84ed9d8dadadbe462d0d065c9bc802e84a74;p=cps.git diff --git a/csit/run-csit.sh b/csit/run-csit.sh index 52ec21863..0981fc6ed 100755 --- a/csit/run-csit.sh +++ b/csit/run-csit.sh @@ -20,10 +20,65 @@ # Branched from ccsdk/distribution to this repository Feb 23, 2021 +echo "---> run-csit.sh" + +WORKDIR=$(mktemp -d --suffix=-robot-workdir) + +# Version should match those used to setup robot-framework in other jobs/stages +# Use pyenv for selecting the python version +if [[ -d "/opt/pyenv" ]]; then + echo "Setup pyenv:" + export PYENV_ROOT="/opt/pyenv" + export PATH="$PYENV_ROOT/bin:$PATH" + pyenv versions + if command -v pyenv 1>/dev/null 2>&1; then + eval "$(pyenv init - --no-rehash)" + # Choose the latest numeric Python version from installed list + version=$(pyenv versions --bare | sed '/^[^0-9]/d' | sort -V | tail -n 1) + pyenv local "${version}" + fi +fi + # # functions # +# relax set options so the sourced file will not fail +# the responsibility is shifted to the sourced file... +function relax_set() { + set +e + set +o pipefail +} + +# load the saved set options +function load_set() { + _setopts="$-" + + # bash shellopts + for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do + set +o ${i} + done + for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do + set -o ${i} + done + + # other options + for i in $(echo "$_setopts" | sed 's/./& /g') ; do + set +${i} + done + set -${RUN_CSIT_SAVE_SET} +} + +# wrapper for sourcing a file +function source_safely() { + [ -z "$1" ] && return 1 + relax_set + . "$1" + load_set +} +# Activate the virtualenv containing all the required libraries installed by prepare-csit.sh +source_safely "${ROBOT3_VENV}/bin/activate" + function on_exit(){ rc=$? if [[ ${WORKSPACE} ]]; then @@ -75,44 +130,26 @@ function save_set() { RUN_CSIT_SHELLOPTS="$SHELLOPTS" } -# load the saved set options -function load_set() { - _setopts="$-" - - # bash shellopts - for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do - set +o ${i} - done - for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do - set -o ${i} - done - - # other options - for i in $(echo "$_setopts" | sed 's/./& /g') ; do - set +${i} - done - set -${RUN_CSIT_SAVE_SET} -} - # set options for quick bailout when error function harden_set() { set -xeo pipefail set +u # enabled it would probably fail too many often } -# relax set options so the sourced file will not fail -# the responsibility is shifted to the sourced file... -function relax_set() { - set +e - set +o pipefail -} +function run_test_plan() { + testplan=$1 -# wrapper for sourcing a file -function source_safely() { - [ -z "$1" ] && return 1 - relax_set - . "$1" + cd "$WORKDIR" + echo "Reading the testplan:" + cat "${TESTPLANDIR}/${testplan}.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > ${testplan}.txt + cat ${testplan}.txt + SUITES=$( xargs -a ${testplan}.txt ) + + python3 -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp --legacy-output ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES} + RESULT=$? load_set + echo "RESULT: $RESULT" + return $RESULT } # @@ -137,10 +174,10 @@ if [ -z "$WORKSPACE" ]; then export WORKSPACE=$(git rev-parse --show-toplevel) fi -if [ -f "${WORKSPACE}/${1}/testplan.txt" ]; then +if [ -f "${WORKSPACE}/${1}/testplanCps.txt" ]; then export TESTPLAN="${1}" else - echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt" + echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplanCps.txt or testplanNcmp.txt" exit 2 fi @@ -154,14 +191,11 @@ TESTPLANDIR="${WORKSPACE}/${TESTPLAN}" # Run installation of prerequired libraries source_safely "${WORKSPACE}/prepare-csit.sh" -# Activate the virtualenv containing all the required libraries installed by prepare-csit.sh -source_safely "${ROBOT_VENV}/bin/activate" - -WORKDIR=$(mktemp -d --suffix=-robot-workdir) +# Use robot framework working directory cd "${WORKDIR}" # Add csit scripts to PATH -export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin" +export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT3_VENV}/bin" export SCRIPTS="${WORKSPACE}/scripts" export ROBOT_VARIABLES= @@ -180,18 +214,27 @@ fi docker_stats | tee "$WORKSPACE/archives/$TESTPLAN/_sysinfo-1-after-setup.txt" # Run test plan -cd "$WORKDIR" -echo "Reading the testplan:" -cat "${TESTPLANDIR}/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt -cat testplan.txt -SUITES=$( xargs -a testplan.txt ) - echo ROBOT_VARIABLES="${ROBOT_VARIABLES}" echo "Starting Robot test suites ${SUITES} ..." relax_set -python3 -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES} -RESULT=$? -load_set -echo "RESULT: $RESULT" + +echo "Versioning information:" +python3 --version +pip freeze +python3 -m robot.run --version || : + +run_test_plan "testplanCps" +CPSRESULT="$?" + +cd "${TESTPLANDIR}" +checkandmount="${TESTPLANDIR}/sdnc/check_sdnc_mount_node.sh" +if [ -f "${checkandmount}" ]; then + echo "Running check_sdnc_mount_node script ${checkandmount}" + source_safely "${checkandmount}" +fi + +run_test_plan "testplanNcmp" +NCMPRESULT="$?" + # Note that the final steps are done in on_exit function after this exit! -exit $RESULT +exit $CPSRESULT || $NCMPRESULT