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