]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/run-backend-api-tests.sh
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / run-backend-api-tests.sh
1 #!/usr/bin/env bash
2
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
10 if [ "$sourced" -eq 0 ] ; then
11 set -eo pipefail
12 fi
13
14 if [[ "$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
29 fi
30
31 get_cmake_variable() {
32 local variable=$1
33 grep "$variable" CMakeCache.txt | cut -d "=" -f 2
34 }
35
36 [ -z "$BUILD_DIR" ] && BUILD_DIR=build
37 CURR_DIR=`pwd`
38 LOCAL_BUILD_DIR="$CURR_DIR/../../../../$BUILD_DIR"
39
40 setup_teuthology() {
41 TEMP_DIR=`mktemp -d`
42 cd $TEMP_DIR
43
44 virtualenv --python=${TEUTHOLOGY_PYTHON_BIN:-/usr/bin/python} venv
45 source venv/bin/activate
46 pip install 'setuptools >= 12'
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
51
52 deactivate
53 }
54
55 setup_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
59 virtualenv --python=/usr/bin/python3 coverage-venv
60 source coverage-venv/bin/activate
61 cd $CURR_DIR
62 pip install coverage==4.5.2
63 COVERAGE_PATH=$(python -c "import sysconfig; print(sysconfig.get_paths()['platlib'])")
64 deactivate
65 }
66
67 on_tests_error() {
68 if [[ -n "$JENKINS_HOME" ]]; then
69 CEPH_OUT_DIR=${CEPH_OUT_DIR:-"$LOCAL_BUILD_DIR"/out}
70 MGR_LOG_FILES=$(find "$CEPH_OUT_DIR" -iname "mgr.*.log" | tr '\n' ' ')
71 MGR_LOG_FILE_LAST_LINES=60000
72 for mgr_log_file in ${MGR_LOG_FILES[@]}; do
73 printf "\n\nDisplaying last ${MGR_LOG_FILE_LAST_LINES} lines of: $mgr_log_file\n\n"
74 tail -n ${MGR_LOG_FILE_LAST_LINES} $mgr_log_file
75 printf "\n\nEnd of: $mgr_log_file\n\n"
76 done
77 printf "\n\nTEST FAILED.\n\n"
78 fi
79 }
80
81 run_teuthology_tests() {
82 trap on_tests_error ERR
83
84 cd "$LOCAL_BUILD_DIR"
85 find ../src/pybind/mgr/dashboard/ -name '*.pyc' -exec rm -f {} \;
86
87 OPTIONS=''
88 TEST_CASES=''
89 if [[ "$@" == '' || "$@" == '--create-cluster-only' ]]; then
90 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`
91 # Mgr selftest module tests have to be run at the end as they stress the mgr daemon.
92 TEST_CASES="tasks.mgr.test_dashboard $TEST_CASES tasks.mgr.test_module_selftest"
93 if [[ "$@" == '--create-cluster-only' ]]; then
94 OPTIONS="$@"
95 fi
96 else
97 for t in "$@"; do
98 TEST_CASES="$TEST_CASES $t"
99 done
100 fi
101
102 export PATH=$LOCAL_BUILD_DIR/bin:$PATH
103 source $TEMP_DIR/venv/bin/activate # Run after setting PATH as it does the last PATH export.
104 export LD_LIBRARY_PATH=$LOCAL_BUILD_DIR/lib/cython_modules/lib.3/:$LOCAL_BUILD_DIR/lib
105 local source_dir=$(dirname "$LOCAL_BUILD_DIR")
106 local pybind_dir=$source_dir/src/pybind
107 local python_common_dir=$source_dir/src/python-common
108 # In CI environment we set python paths inside build (where you find the required frontend build: "dist" dir).
109 if [[ -n "$JENKINS_HOME" ]]; then
110 export PYBIND=$LOCAL_BUILD_DIR/src/pybind
111 pybind_dir=$PYBIND
112 fi
113 export PYTHONPATH=$source_dir/qa:$LOCAL_BUILD_DIR/lib/cython_modules/lib.3/:$pybind_dir:$python_common_dir:${COVERAGE_PATH}
114 export RGW=${RGW:-1}
115
116 export COVERAGE_ENABLED=true
117 export COVERAGE_FILE=.coverage.mgr.dashboard
118 find . -iname "*${COVERAGE_FILE}*" -type f -delete
119
120 python ../qa/tasks/vstart_runner.py --ignore-missing-binaries $OPTIONS $(echo $TEST_CASES)
121
122 deactivate
123 cd $CURR_DIR
124 }
125
126 cleanup_teuthology() {
127 cd "$LOCAL_BUILD_DIR"
128 killall ceph-mgr
129 sleep 10
130 if [[ "$COVERAGE_ENABLED" == 'true' ]]; then
131 source $TEMP_DIR/coverage-venv/bin/activate
132 (coverage combine && coverage report) || true
133 deactivate
134 fi
135 ../src/stop.sh
136 sleep 5
137
138 cd $CURR_DIR
139 rm -rf $TEMP_DIR
140
141 unset TEMP_DIR
142 unset CURR_DIR
143 unset LOCAL_BUILD_DIR
144 unset COVERAGE_PATH
145 unset setup_teuthology
146 unset setup_coverage
147 unset on_tests_error
148 unset run_teuthology_tests
149 unset cleanup_teuthology
150 }
151
152 setup_teuthology
153 setup_coverage
154 run_teuthology_tests --create-cluster-only
155
156 # End sourced section. Do not exit shell when the script has been sourced.
157 if [ "$sourced" -eq 1 ] ; then
158 return
159 fi
160
161 run_teuthology_tests "$@"
162 cleanup_teuthology