]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/run-backend-api-tests.sh
import ceph pacific 16.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / run-backend-api-tests.sh
CommitLineData
11fdf7f2
TL
1#!/usr/bin/env bash
2
9f95a23c
TL
3# cross shell: Are we sourced?
4# Source: https://stackoverflow.com/a/28776166/3185053
5([[ -n $ZSH_EVAL_CONTEXT && $ZSH_EVAL_CONTEXT =~ :file$ ]] ||
6 [[ -n $KSH_VERSION && $(cd "$(dirname -- "$0")" &&
7 printf '%s' "${PWD%/}/")$(basename -- "$0") != "${.sh.file}" ]] ||
8 [[ -n $BASH_VERSION ]] && (return 0 2>/dev/null)) && sourced=1 || sourced=0
9
10if [ "$sourced" -eq 0 ] ; then
11 set -eo pipefail
12fi
eafe8130 13
11fdf7f2
TL
14if [[ "$1" = "-h" || "$1" = "--help" ]]; then
15 echo "Usage (run from ./):"
16 echo -e "\t./run-backend-api-tests.sh"
17 echo -e "\t./run-backend-api-tests.sh [tests]..."
18 echo
19 echo "Example:"
20 echo -e "\t./run-backend-api-tests.sh tasks.mgr.dashboard.test_pool.DashboardTest"
21 echo
22 echo "Or source this script. This allows to re-run tests faster:"
23 echo -e "\tsource run-backend-api-tests.sh"
24 echo -e "\trun_teuthology_tests [tests]..."
25 echo -e "\tcleanup_teuthology"
26 echo
27
28 exit 0
29fi
30
11fdf7f2
TL
31get_cmake_variable() {
32 local variable=$1
33 grep "$variable" CMakeCache.txt | cut -d "=" -f 2
34}
35
9f95a23c
TL
36[ -z "$BUILD_DIR" ] && BUILD_DIR=build
37CURR_DIR=`pwd`
f67539c2 38LOCAL_BUILD_DIR=$(cd "$CURR_DIR/../../../../$BUILD_DIR"; pwd)
11fdf7f2 39
eafe8130
TL
40setup_teuthology() {
41 TEMP_DIR=`mktemp -d`
eafe8130 42 cd $TEMP_DIR
9f95a23c 43
f6b5b4d7 44 virtualenv --python=${TEUTHOLOGY_PYTHON_BIN:-/usr/bin/python3} venv
eafe8130
TL
45 source venv/bin/activate
46 pip install 'setuptools >= 12'
9f95a23c
TL
47 pip install git+https://github.com/ceph/teuthology#egg=teuthology[test]
48 pushd $CURR_DIR
49 pip install -r requirements.txt -c constraints.txt
50 popd
eafe8130
TL
51
52 deactivate
53}
54
55setup_coverage() {
56 # In CI environment we cannot install coverage in system, so we install it in a dedicated venv
57 # so only coverage is available when adding this path.
58 cd $TEMP_DIR
9f95a23c 59 virtualenv --python=/usr/bin/python3 coverage-venv
eafe8130 60 source coverage-venv/bin/activate
11fdf7f2 61 cd $CURR_DIR
eafe8130 62 pip install coverage==4.5.2
9f95a23c 63 COVERAGE_PATH=$(python -c "import sysconfig; print(sysconfig.get_paths()['platlib'])")
eafe8130
TL
64 deactivate
65}
11fdf7f2 66
f67539c2
TL
67display_log() {
68 local daemon=$1
69 shift
70 local lines=$1
71 shift
72
73 local log_files=$(find "$CEPH_OUT_DIR" -iname "${daemon}.*.log" | tr '\n' ' ')
74 for log_file in ${log_files[@]}; do
75 printf "\n\nDisplaying last ${lines} lines of: ${log_file}\n\n"
76 tail -n ${lines} $log_file
77 printf "\n\nEnd of: ${log_file}\n\n"
78 done
79 printf "\n\nTEST FAILED.\n\n"
80}
81
eafe8130 82on_tests_error() {
f67539c2
TL
83 local ret=$?
84 if [[ -n "$JENKINS_HOME" && -z "$ON_TESTS_ERROR_RUN" ]]; then
9f95a23c 85 CEPH_OUT_DIR=${CEPH_OUT_DIR:-"$LOCAL_BUILD_DIR"/out}
f67539c2
TL
86 display_log "mgr" 1500
87 display_log "osd" 1000
88 ON_TESTS_ERROR_RUN=1
11fdf7f2 89 fi
f67539c2 90 return $ret
11fdf7f2
TL
91}
92
93run_teuthology_tests() {
eafe8130
TL
94 trap on_tests_error ERR
95
9f95a23c 96 cd "$LOCAL_BUILD_DIR"
11fdf7f2 97 find ../src/pybind/mgr/dashboard/ -name '*.pyc' -exec rm -f {} \;
11fdf7f2
TL
98
99 OPTIONS=''
100 TEST_CASES=''
101 if [[ "$@" == '' || "$@" == '--create-cluster-only' ]]; then
9f95a23c 102 TEST_CASES=`for i in \`ls $LOCAL_BUILD_DIR/../qa/tasks/mgr/dashboard/test_*\`; do F=$(basename $i); M="${F%.*}"; echo -n " tasks.mgr.dashboard.$M"; done`
eafe8130
TL
103 # Mgr selftest module tests have to be run at the end as they stress the mgr daemon.
104 TEST_CASES="tasks.mgr.test_dashboard $TEST_CASES tasks.mgr.test_module_selftest"
11fdf7f2
TL
105 if [[ "$@" == '--create-cluster-only' ]]; then
106 OPTIONS="$@"
107 fi
108 else
109 for t in "$@"; do
110 TEST_CASES="$TEST_CASES $t"
111 done
112 fi
113
9f95a23c 114 export PATH=$LOCAL_BUILD_DIR/bin:$PATH
eafe8130 115 source $TEMP_DIR/venv/bin/activate # Run after setting PATH as it does the last PATH export.
9f95a23c
TL
116 export LD_LIBRARY_PATH=$LOCAL_BUILD_DIR/lib/cython_modules/lib.3/:$LOCAL_BUILD_DIR/lib
117 local source_dir=$(dirname "$LOCAL_BUILD_DIR")
eafe8130
TL
118 local pybind_dir=$source_dir/src/pybind
119 local python_common_dir=$source_dir/src/python-common
120 # In CI environment we set python paths inside build (where you find the required frontend build: "dist" dir).
121 if [[ -n "$JENKINS_HOME" ]]; then
f67539c2 122 pybind_dir+=":$LOCAL_BUILD_DIR/src/pybind"
11fdf7f2 123 fi
9f95a23c 124 export PYTHONPATH=$source_dir/qa:$LOCAL_BUILD_DIR/lib/cython_modules/lib.3/:$pybind_dir:$python_common_dir:${COVERAGE_PATH}
b3b6e05e
TL
125 export DASHBOARD_SSL=1
126 export NFS=0
127 export RGW=1
11fdf7f2
TL
128
129 export COVERAGE_ENABLED=true
130 export COVERAGE_FILE=.coverage.mgr.dashboard
131 find . -iname "*${COVERAGE_FILE}*" -type f -delete
132
f67539c2
TL
133 python ../qa/tasks/vstart_runner.py --ignore-missing-binaries --no-verbose $OPTIONS $(echo $TEST_CASES) ||
134 on_tests_error
11fdf7f2
TL
135
136 deactivate
137 cd $CURR_DIR
138}
139
140cleanup_teuthology() {
9f95a23c 141 cd "$LOCAL_BUILD_DIR"
11fdf7f2
TL
142 killall ceph-mgr
143 sleep 10
144 if [[ "$COVERAGE_ENABLED" == 'true' ]]; then
eafe8130 145 source $TEMP_DIR/coverage-venv/bin/activate
11fdf7f2
TL
146 (coverage combine && coverage report) || true
147 deactivate
148 fi
149 ../src/stop.sh
150 sleep 5
151
152 cd $CURR_DIR
153 rm -rf $TEMP_DIR
154
155 unset TEMP_DIR
156 unset CURR_DIR
9f95a23c 157 unset LOCAL_BUILD_DIR
eafe8130 158 unset COVERAGE_PATH
11fdf7f2 159 unset setup_teuthology
eafe8130
TL
160 unset setup_coverage
161 unset on_tests_error
11fdf7f2
TL
162 unset run_teuthology_tests
163 unset cleanup_teuthology
164}
165
166setup_teuthology
eafe8130 167setup_coverage
11fdf7f2
TL
168run_teuthology_tests --create-cluster-only
169
eafe8130 170# End sourced section. Do not exit shell when the script has been sourced.
9f95a23c
TL
171if [ "$sourced" -eq 1 ] ; then
172 return
173fi
11fdf7f2
TL
174
175run_teuthology_tests "$@"
176cleanup_teuthology