18874: Merge commit '6f8dcb2b13f3058db656908fb26b09e23b527f08' into 18874-merge-wb2
[arvados.git] / build / run-tests.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 COLUMNS=80
7 . `dirname "$(readlink -f "$0")"`/run-library.sh
8
9 read -rd "\000" helpmessage <<EOF
10 $(basename $0): Install and test Arvados components.
11
12 Exit non-zero if any tests fail.
13
14 Syntax:
15         $(basename $0) WORKSPACE=/path/to/arvados [options]
16
17 Options:
18
19 --skip FOO     Do not test the FOO component.
20 --skip sanity  Skip initial dev environment sanity checks.
21 --skip install Do not run any install steps. Just run tests.
22                You should provide GOPATH, GEMHOME, and VENVDIR options
23                from a previous invocation if you use this option.
24 --only FOO     Do not test anything except the FOO component.
25 --temp DIR     Install components and dependencies under DIR instead of
26                making a new temporary directory. Implies --leave-temp.
27 --leave-temp   Do not remove GOPATH, virtualenv, and other temp dirs at exit.
28                Instead, show the path to give as --temp to reuse them in
29                subsequent invocations.
30 --repeat N     Repeat each install/test step until it succeeds N times.
31 --retry        Prompt to retry if an install or test suite fails.
32 --only-install Run specific install step
33 --short        Skip (or scale down) some slow tests.
34 --interactive  Set up, then prompt for test/install steps to perform.
35 WORKSPACE=path Arvados source tree to test.
36 CONFIGSRC=path Dir with config.yml file containing PostgreSQL section for use by tests.
37 services/api_test="TEST=test/functional/arvados/v1/collections_controller_test.rb"
38                Restrict apiserver tests to the given file
39 sdk/python_test="--test-suite tests.test_keep_locator"
40                Restrict Python SDK tests to the given class
41 apps/workbench_test="TEST=test/integration/pipeline_instances_test.rb"
42                Restrict Workbench tests to the given file
43 services/githttpd_test="-check.vv"
44                Show all log messages, even when tests pass (also works
45                with services/keepstore_test etc.)
46 ARVADOS_DEBUG=1
47                Print more debug messages
48 envvar=value   Set \$envvar to value. Primarily useful for WORKSPACE,
49                *_test, and other examples shown above.
50
51 Assuming "--skip install" is not given, all components are installed
52 into \$GOPATH, \$VENDIR, and \$GEMHOME before running any tests. Many
53 test suites depend on other components being installed, and installing
54 everything tends to be quicker than debugging dependencies.
55
56 As a special concession to the current CI server config, CONFIGSRC
57 defaults to $HOME/arvados-api-server if that directory exists.
58
59 More information and background:
60
61 https://dev.arvados.org/projects/arvados/wiki/Running_tests
62
63 Available tests:
64
65 apps/workbench (*)
66 apps/workbench_units (*)
67 apps/workbench_functionals (*)
68 apps/workbench_integration (*)
69 apps/workbench_benchmark
70 apps/workbench_profile
71 cmd/arvados-client
72 cmd/arvados-package
73 cmd/arvados-server
74 doc
75 lib/cli
76 lib/cmd
77 lib/controller
78 lib/controller/federation
79 lib/controller/railsproxy
80 lib/controller/router
81 lib/controller/rpc
82 lib/crunchstat
83 lib/crunch-run
84 lib/cloud
85 lib/cloud/azure
86 lib/cloud/cloudtest
87 lib/dispatchcloud
88 lib/dispatchcloud/container
89 lib/dispatchcloud/scheduler
90 lib/dispatchcloud/sshexecutor
91 lib/dispatchcloud/worker
92 lib/mount
93 lib/pam
94 lib/service
95 services/api
96 services/githttpd
97 services/dockercleaner
98 services/fuse
99 services/fuse:py3
100 services/health
101 services/keep-web
102 services/keepproxy
103 services/keepstore
104 services/keep-balance
105 services/login-sync
106 services/crunch-dispatch-local
107 services/crunch-dispatch-slurm
108 services/workbench2_units
109 services/workbench2_integration
110 services/ws
111 sdk/cli
112 sdk/python
113 sdk/python:py3
114 sdk/ruby
115 sdk/go/arvados
116 sdk/go/arvadosclient
117 sdk/go/auth
118 sdk/go/dispatch
119 sdk/go/keepclient
120 sdk/go/health
121 sdk/go/httpserver
122 sdk/go/manifest
123 sdk/go/blockdigest
124 sdk/go/asyncbuf
125 sdk/go/stats
126 sdk/go/crunchrunner
127 sdk/cwl:py3
128 sdk/R
129 sdk/java-v2
130 tools/sync-groups
131 tools/crunchstat-summary
132 tools/crunchstat-summary:py3
133 tools/keep-exercise
134 tools/keep-rsync
135 tools/keep-block-check
136
137 (*) apps/workbench is shorthand for apps/workbench_units +
138     apps/workbench_functionals + apps/workbench_integration
139
140 EOF
141
142 # First make sure to remove any ARVADOS_ variables from the calling
143 # environment that could interfere with the tests.
144 unset $(env | cut -d= -f1 | grep \^ARVADOS_)
145
146 # Reset other variables that could affect our [tests'] behavior by
147 # accident.
148 GITDIR=
149 GOPATH=
150 VENVDIR=
151 VENV3DIR=
152 PYTHONPATH=
153 GEMHOME=
154 R_LIBS=
155 export LANG=en_US.UTF-8
156
157 short=
158 only_install=
159 temp=
160 temp_preserve=
161
162 ignore_sigint=
163
164 clear_temp() {
165     if [[ -z "$temp" ]]; then
166         # we did not even get as far as making a temp dir
167         :
168     elif [[ -z "$temp_preserve" ]]; then
169         # Go creates readonly dirs in the module cache, which cause
170         # "rm -rf" to fail unless we chmod first.
171         chmod -R u+w "$temp"
172         rm -rf "$temp"
173     else
174         echo "Leaving behind temp dirs in $temp"
175     fi
176 }
177
178 fatal() {
179     clear_temp
180     echo >&2 "Fatal: $* (encountered in ${FUNCNAME[1]} at ${BASH_SOURCE[1]} line ${BASH_LINENO[0]})"
181     exit 1
182 }
183
184 exit_cleanly() {
185     trap - INT
186     if which create-plot-data-from-log.sh >/dev/null; then
187         create-plot-data-from-log.sh $BUILD_NUMBER "$WORKSPACE/apps/workbench/log/test.log" "$WORKSPACE/apps/workbench/log/"
188     fi
189     rotate_logfile "$WORKSPACE/apps/workbench/log/" "test.log"
190     stop_services
191     rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
192     report_outcomes
193     clear_temp
194     exit ${#failures}
195 }
196
197 sanity_checks() {
198     [[ -n "${skip[sanity]}" ]] && return 0
199     ( [[ -n "$WORKSPACE" ]] && [[ -d "$WORKSPACE/services" ]] ) \
200         || fatal "WORKSPACE environment variable not set to a source directory (see: $0 --help)"
201     [[ -z "$CONFIGSRC" ]] || [[ -s "$CONFIGSRC/config.yml" ]] \
202         || fatal "CONFIGSRC is $CONFIGSRC but '$CONFIGSRC/config.yml' is empty or not found (see: $0 --help)"
203     echo Checking dependencies:
204     echo "locale: ${LANG}"
205     [[ "$(locale charmap)" = "UTF-8" ]] \
206         || fatal "Locale '${LANG}' is broken/missing. Try: echo ${LANG} | sudo tee -a /etc/locale.gen && sudo locale-gen"
207     echo -n 'ruby: '
208     ruby -v \
209         || fatal "No ruby. Install >=2.1.9 (using rbenv, rvm, or source)"
210     echo -n 'go: '
211     go version \
212         || fatal "No go binary. See http://golang.org/doc/install"
213     [[ $(go version) =~ go1.([0-9]+) ]] && [[ ${BASH_REMATCH[1]} -ge 12 ]] \
214         || fatal "Go >= 1.12 required. See http://golang.org/doc/install"
215     echo -n 'gcc: '
216     gcc --version | egrep ^gcc \
217         || fatal "No gcc. Try: apt-get install build-essential"
218     echo -n 'fuse.h: '
219     find /usr/include -path '*fuse/fuse.h' | egrep --max-count=1 . \
220         || fatal "No fuse/fuse.h. Try: apt-get install libfuse-dev"
221     echo -n 'gnutls.h: '
222     find /usr/include -path '*gnutls/gnutls.h' | egrep --max-count=1 . \
223         || fatal "No gnutls/gnutls.h. Try: apt-get install libgnutls28-dev"
224     echo -n 'virtualenv: '
225     python3 -m venv -h | egrep --max-count=1 . \
226         || fatal "No virtualenv. Try: apt-get install python3-venv"
227     echo -n 'Python3 pyconfig.h: '
228     find /usr/include -path '*/python3*/pyconfig.h' | egrep --max-count=1 . \
229         || fatal "No Python3 pyconfig.h. Try: apt-get install python3-dev"
230     which netstat \
231         || fatal "No netstat. Try: apt-get install net-tools"
232     echo -n 'nginx: '
233     PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin" nginx -v \
234         || fatal "No nginx. Try: apt-get install nginx"
235     echo -n 'gitolite: '
236     which gitolite \
237         || fatal "No gitolite. Try: apt-get install gitolite3"
238     echo -n 'npm: '
239     npm --version \
240         || fatal "No npm. Try: wget -O- https://nodejs.org/dist/v10.23.1/node-v10.23.1-linux-x64.tar.xz | sudo tar -C /usr/local -xJf - && sudo ln -s ../node-v10.23.1-linux-x64/bin/{node,npm} /usr/local/bin/"
241     echo -n 'cadaver: '
242     cadaver --version | grep -w cadaver \
243           || fatal "No cadaver. Try: apt-get install cadaver"
244     echo -n 'libattr1 xattr.h: '
245     find /usr/include -path '*/attr/xattr.h' | egrep --max-count=1 . \
246         || fatal "No libattr1 xattr.h. Try: apt-get install libattr1-dev"
247     echo -n 'libcurl curl.h: '
248     find /usr/include -path '*/curl/curl.h' | egrep --max-count=1 . \
249         || fatal "No libcurl curl.h. Try: apt-get install libcurl4-gnutls-dev"
250     echo -n 'libpq libpq-fe.h: '
251     find /usr/include -path '*/postgresql/libpq-fe.h' | egrep --max-count=1 . \
252         || fatal "No libpq libpq-fe.h. Try: apt-get install libpq-dev"
253     echo -n 'libpam pam_appl.h: '
254     find /usr/include -path '*/security/pam_appl.h' | egrep --max-count=1 . \
255         || fatal "No libpam pam_appl.h. Try: apt-get install libpam0g-dev"
256     echo -n 'postgresql: '
257     psql --version || fatal "No postgresql. Try: apt-get install postgresql postgresql-client-common"
258     echo -n 'phantomjs: '
259     phantomjs --version || fatal "No phantomjs. Try: apt-get install phantomjs"
260     echo -n 'xvfb: '
261     which Xvfb || fatal "No xvfb. Try: apt-get install xvfb"
262     echo -n 'graphviz: '
263     dot -V || fatal "No graphviz. Try: apt-get install graphviz"
264     echo -n 'geckodriver: '
265     geckodriver --version | grep ^geckodriver || echo "No geckodriver. Try: arvados-server install"
266     echo -n 'singularity: '
267     singularity --version || fatal "No singularity. Try: arvados-server install"
268     echo -n 'docker client: '
269     docker --version || echo "No docker client. Try: arvados-server install"
270     echo -n 'docker server: '
271     docker info --format='{{.ServerVersion}}' || echo "No docker server. Try: arvados-server install"
272
273     if [[ "$NEED_SDK_R" = true ]]; then
274       # R SDK stuff
275       echo -n 'R: '
276       which Rscript || fatal "No Rscript. Try: apt-get install r-base"
277       echo -n 'testthat: '
278       Rscript -e "library('testthat')" || fatal "No testthat. Try: apt-get install r-cran-testthat"
279       # needed for roxygen2, needed for devtools, needed for R sdk
280       pkg-config --exists libxml-2.0 || fatal "No libxml2. Try: apt-get install libxml2-dev"
281       # needed for pkgdown, builds R SDK doc pages
282       which pandoc || fatal "No pandoc. Try: apt-get install pandoc"
283     fi
284     echo 'procs with /dev/fuse open:'
285     find /proc/*/fd -lname /dev/fuse 2>/dev/null | cut -d/ -f3 | xargs --no-run-if-empty ps -lywww
286     echo 'grep fuse /proc/self/mountinfo:'
287     grep fuse /proc/self/mountinfo
288 }
289
290 rotate_logfile() {
291   # i.e.  rotate_logfile "$WORKSPACE/apps/workbench/log/" "test.log"
292   # $BUILD_NUMBER is set by Jenkins if this script is being called as part of a Jenkins run
293   if [[ -f "$1/$2" ]]; then
294     THEDATE=`date +%Y%m%d%H%M%S`
295     mv "$1/$2" "$1/$THEDATE-$BUILD_NUMBER-$2"
296     gzip "$1/$THEDATE-$BUILD_NUMBER-$2"
297   fi
298 }
299
300 declare -a failures
301 declare -A skip
302 declare -A only
303 declare -A testargs
304 skip[apps/workbench_profile]=1
305
306 while [[ -n "$1" ]]
307 do
308     arg="$1"; shift
309     case "$arg" in
310         --help)
311             echo >&2 "$helpmessage"
312             echo >&2
313             exit 1
314             ;;
315         --skip)
316             skip[$1]=1; shift
317             ;;
318         --only)
319             only[$1]=1; skip[$1]=""; shift
320             ;;
321         --short)
322             short=1
323             ;;
324         --interactive)
325             interactive=1
326             ;;
327         --skip-install)
328             skip[install]=1
329             ;;
330         --only-install)
331             only_install="$1"; shift
332             ;;
333         --temp)
334             temp="$1"; shift
335             temp_preserve=1
336             ;;
337         --leave-temp)
338             temp_preserve=1
339             ;;
340         --repeat)
341             repeat=$((${1}+0)); shift
342             ;;
343         --retry)
344             retry=1
345             ;;
346         *_test=*)
347             suite="${arg%%_test=*}"
348             args="${arg#*=}"
349             testargs["$suite"]="$args"
350             ;;
351         *=*)
352             eval export $(echo $arg | cut -d= -f1)=\"$(echo $arg | cut -d= -f2-)\"
353             ;;
354         *)
355             echo >&2 "$0: Unrecognized option: '$arg'. Try: $0 --help"
356             exit 1
357             ;;
358     esac
359 done
360
361 # R SDK installation is very slow (~360s in a clean environment) and only
362 # required when testing it. Skip that step if it is not needed.
363 NEED_SDK_R=true
364
365 if [[ ${#only[@]} -ne 0 ]] &&
366    [[ -z "${only['sdk/R']}" && -z "${only['doc']}" ]]; then
367   NEED_SDK_R=false
368 fi
369
370 if [[ ${skip["sdk/R"]} == 1 && ${skip["doc"]} == 1 ]]; then
371   NEED_SDK_R=false
372 fi
373
374 if [[ $NEED_SDK_R == false ]]; then
375         echo "R SDK not needed, it will not be installed."
376 fi
377
378 checkpidfile() {
379     svc="$1"
380     pid="$(cat "$WORKSPACE/tmp/${svc}.pid")"
381     if [[ -z "$pid" ]] || ! kill -0 "$pid"; then
382         tail $WORKSPACE/tmp/${1}*.log
383         echo "${svc} pid ${pid} not running"
384         return 1
385     fi
386     echo "${svc} pid ${pid} ok"
387 }
388
389 checkhealth() {
390     svc="$1"
391     base=$("${VENV3DIR}/bin/python3" -c "import yaml; print(list(yaml.safe_load(open('$ARVADOS_CONFIG','r'))['Clusters']['zzzzz']['Services']['$1']['InternalURLs'].keys())[0])")
392     url="$base/_health/ping"
393     if ! curl -Ss -H "Authorization: Bearer e687950a23c3a9bceec28c6223a06c79" "${url}" | tee -a /dev/stderr | grep '"OK"'; then
394         echo "${url} failed"
395         return 1
396     fi
397 }
398
399 checkdiscoverydoc() {
400     dd="https://${1}/discovery/v1/apis/arvados/v1/rest"
401     if ! (set -o pipefail; curl -fsk "$dd" | grep -q ^{ ); then
402         echo >&2 "ERROR: could not retrieve discovery doc from RailsAPI at $dd"
403         tail -v $WORKSPACE/tmp/railsapi.log
404         return 1
405     fi
406     echo "${dd} ok"
407 }
408
409 start_services() {
410     if [[ -n "$ARVADOS_TEST_API_HOST" ]]; then
411         return 0
412     fi
413     . "$VENV3DIR/bin/activate"
414     echo 'Starting API, controller, keepproxy, keep-web, githttpd, ws, and nginx ssl proxy...'
415     if [[ ! -d "$WORKSPACE/services/api/log" ]]; then
416         mkdir -p "$WORKSPACE/services/api/log"
417     fi
418     # Remove empty api.pid file if it exists
419     if [[ -f "$WORKSPACE/tmp/api.pid" && ! -s "$WORKSPACE/tmp/api.pid" ]]; then
420         rm -f "$WORKSPACE/tmp/api.pid"
421     fi
422     all_services_stopped=
423     fail=1
424
425     cd "$WORKSPACE" \
426         && eval $(python3 sdk/python/tests/run_test_server.py start --auth admin) \
427         && export ARVADOS_TEST_API_HOST="$ARVADOS_API_HOST" \
428         && export ARVADOS_TEST_API_INSTALLED="$$" \
429         && checkpidfile api \
430         && checkdiscoverydoc $ARVADOS_API_HOST \
431         && eval $(python3 sdk/python/tests/run_test_server.py start_nginx) \
432         && checkpidfile nginx \
433         && python3 sdk/python/tests/run_test_server.py start_controller \
434         && checkpidfile controller \
435         && checkhealth Controller \
436         && checkdiscoverydoc $ARVADOS_API_HOST \
437         && python3 sdk/python/tests/run_test_server.py start_keep_proxy \
438         && checkpidfile keepproxy \
439         && python3 sdk/python/tests/run_test_server.py start_keep-web \
440         && checkpidfile keep-web \
441         && checkhealth WebDAV \
442         && python3 sdk/python/tests/run_test_server.py start_githttpd \
443         && checkpidfile githttpd \
444         && checkhealth GitHTTP \
445         && python3 sdk/python/tests/run_test_server.py start_ws \
446         && checkpidfile ws \
447         && export ARVADOS_TEST_PROXY_SERVICES=1 \
448         && (env | egrep ^ARVADOS) \
449         && fail=0
450     deactivate
451     if [[ $fail != 0 ]]; then
452         unset ARVADOS_TEST_API_HOST
453     fi
454     return $fail
455 }
456
457 stop_services() {
458     if [[ -n "$all_services_stopped" ]]; then
459         return
460     fi
461     unset ARVADOS_TEST_API_HOST ARVADOS_TEST_PROXY_SERVICES
462     . "$VENV3DIR/bin/activate" || return
463     cd "$WORKSPACE" \
464         && python3 sdk/python/tests/run_test_server.py stop_nginx \
465         && python3 sdk/python/tests/run_test_server.py stop_githttpd \
466         && python3 sdk/python/tests/run_test_server.py stop_ws \
467         && python3 sdk/python/tests/run_test_server.py stop_keep-web \
468         && python3 sdk/python/tests/run_test_server.py stop_keep_proxy \
469         && python3 sdk/python/tests/run_test_server.py stop_controller \
470         && python3 sdk/python/tests/run_test_server.py stop \
471         && all_services_stopped=1
472     deactivate
473     unset ARVADOS_CONFIG
474 }
475
476 interrupt() {
477     if [[ -n "$ignore_sigint" ]]; then
478         echo >&2 "ignored SIGINT"
479         return
480     fi
481     failures+=("($(basename $0) interrupted)")
482     exit_cleanly
483 }
484 trap interrupt INT
485
486 setup_ruby_environment() {
487     if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
488         source "$HOME/.rvm/scripts/rvm"
489         using_rvm=true
490     elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
491         source "/usr/local/rvm/scripts/rvm"
492         using_rvm=true
493     else
494         using_rvm=false
495     fi
496
497     if [[ "$using_rvm" == true ]]; then
498         # If rvm is in use, we can't just put separate "dependencies"
499         # and "gems-under-test" paths to GEM_PATH: passenger resets
500         # the environment to the "current gemset", which would lose
501         # our GEM_PATH and prevent our test suites from running ruby
502         # programs (for example, the Workbench test suite could not
503         # boot an API server or run arv). Instead, we have to make an
504         # rvm gemset and use it for everything.
505
506         [[ `type rvm | head -n1` == "rvm is a function" ]] \
507             || fatal 'rvm check'
508
509         # Put rvm's favorite path back in first place (overriding
510         # virtualenv, which just put itself there). Ignore rvm's
511         # complaint about not being in first place already.
512         rvm use @default 2>/dev/null
513
514         # Create (if needed) and switch to an @arvados-tests-* gemset,
515         # salting the gemset name so it doesn't interfere with
516         # concurrent builds in other workspaces. Leave the choice of
517         # ruby to the caller.
518         gemset="arvados-tests-$(echo -n "${WORKSPACE}" | md5sum | head -c16)"
519         rvm use "@${gemset}" --create \
520             || fatal 'rvm gemset setup'
521
522         rvm env
523         (bundle version | grep -q 2.2.19) || gem install --no-document bundler -v 2.2.19
524         bundle="$(which bundle)"
525         echo "$bundle"
526         "$bundle" version | grep 2.2.19 || fatal 'install bundler'
527     else
528         # When our "bundle install"s need to install new gems to
529         # satisfy dependencies, we want them to go where "gem install
530         # --user-install" would put them. (However, if the caller has
531         # already set GEM_HOME, we assume that's where dependencies
532         # should be installed, and we should leave it alone.)
533
534         if [ -z "$GEM_HOME" ]; then
535             user_gempath="$(gem env gempath)"
536             export GEM_HOME="${user_gempath%%:*}"
537         fi
538         PATH="$(gem env gemdir)/bin:$PATH"
539
540         # When we build and install our own gems, we install them in our
541         # $GEMHOME tmpdir, and we want them to be at the front of GEM_PATH and
542         # PATH so integration tests prefer them over other versions that
543         # happen to be installed in $user_gempath, system dirs, etc.
544
545         tmpdir_gem_home="$(env - PATH="$PATH" HOME="$GEMHOME" gem env gempath | cut -f1 -d:)"
546         PATH="$tmpdir_gem_home/bin:$PATH"
547         export GEM_PATH="$tmpdir_gem_home:$(gem env gempath)"
548
549         echo "Will install dependencies to $(gem env gemdir)"
550         echo "Will install bundler and arvados gems to $tmpdir_gem_home"
551         echo "Gem search path is GEM_PATH=$GEM_PATH"
552         bundle="bundle"
553         (
554             export HOME=$GEMHOME
555             versions=(2.2.19)
556             for v in ${versions[@]}; do
557                 if ! gem list --installed --version "${v}" bundler >/dev/null; then
558                     gem install --no-document --user $(for v in ${versions[@]}; do echo bundler:${v}; done)
559                     break
560                 fi
561             done
562             "$bundle" version | tee /dev/stderr | grep -q 'version 2'
563         ) || fatal 'install bundler'
564         if test -d /var/lib/arvados-arvbox/ ; then
565             # Inside arvbox, use bundler-installed binstubs.  The
566             # system bundler and rail's own bin/bundle refuse to work.
567             # I don't know why.
568             bundle=binstubs/bundle
569         fi
570     fi
571 }
572
573 with_test_gemset() {
574     if [[ "$using_rvm" == true ]]; then
575         "$@"
576     else
577         GEM_HOME="$tmpdir_gem_home" GEM_PATH="$tmpdir_gem_home" "$@"
578     fi
579 }
580
581 gem_uninstall_if_exists() {
582     if gem list "$1\$" | egrep '^\w'; then
583         gem uninstall --force --all --executables "$1"
584     fi
585 }
586
587 setup_virtualenv() {
588     local venvdest="$1"; shift
589     if ! [[ -e "$venvdest/bin/activate" ]] || ! [[ -e "$venvdest/bin/pip3" ]]; then
590         python3 -m venv "$@" "$venvdest" || fatal "virtualenv $venvdest failed"
591     elif [[ -n "$short" ]]; then
592         return
593     fi
594     "$venvdest/bin/pip3" install --no-cache-dir 'setuptools>=18.5' 'pip>=7'
595 }
596
597 initialize() {
598     # If dependencies like ruby, go, etc. are installed in
599     # /var/lib/arvados -- presumably by "arvados-server install" --
600     # then we want to use those versions, instead of whatever happens
601     # to be installed in /usr.
602     PATH="/var/lib/arvados/bin:${PATH}"
603     sanity_checks
604
605     echo "WORKSPACE=$WORKSPACE"
606
607     # Clean up .pyc files that may exist in the workspace
608     cd "$WORKSPACE"
609     find -name '*.pyc' -delete
610
611     if [[ -z "$temp" ]]; then
612         temp="$(mktemp -d)"
613     fi
614
615     # Set up temporary install dirs (unless existing dirs were supplied)
616     for tmpdir in VENV3DIR GOPATH GEMHOME R_LIBS
617     do
618         if [[ -z "${!tmpdir}" ]]; then
619             eval "$tmpdir"="$temp/$tmpdir"
620         fi
621         if ! [[ -d "${!tmpdir}" ]]; then
622             mkdir "${!tmpdir}" || fatal "can't create ${!tmpdir} (does $temp exist?)"
623         fi
624     done
625
626     rm -vf "${WORKSPACE}/tmp/*.log"
627
628     export R_LIBS
629
630     export GOPATH
631     # Make sure our compiled binaries under test override anything
632     # else that might be in the environment.
633     export PATH=$GOPATH/bin:$PATH
634
635     # Jenkins config requires that glob tmp/*.log match something. Ensure
636     # that happens even if we don't end up running services that set up
637     # logging.
638     mkdir -p "${WORKSPACE}/tmp/" || fatal "could not mkdir ${WORKSPACE}/tmp"
639     touch "${WORKSPACE}/tmp/controller.log" || fatal "could not touch ${WORKSPACE}/tmp/controller.log"
640
641     unset http_proxy https_proxy no_proxy
642
643     # Note: this must be the last time we change PATH, otherwise rvm will
644     # whine a lot.
645     setup_ruby_environment
646
647     echo "PATH is $PATH"
648 }
649
650 install_env() {
651     go mod download || fatal "Go deps failed"
652     which goimports >/dev/null || go install golang.org/x/tools/cmd/goimports@latest || fatal "Go setup failed"
653
654     setup_virtualenv "$VENV3DIR"
655     . "$VENV3DIR/bin/activate"
656
657     # Needed for run_test_server.py which is used by certain (non-Python) tests.
658     # pdoc needed to generate the Python SDK documentation.
659     (
660         set -e
661         "${VENV3DIR}/bin/pip3" install wheel
662         "${VENV3DIR}/bin/pip3" install PyYAML
663         "${VENV3DIR}/bin/pip3" install httplib2
664         "${VENV3DIR}/bin/pip3" install future
665         "${VENV3DIR}/bin/pip3" install google-api-python-client
666         "${VENV3DIR}/bin/pip3" install ciso8601
667         "${VENV3DIR}/bin/pip3" install pycurl
668         "${VENV3DIR}/bin/pip3" install ws4py
669         "${VENV3DIR}/bin/pip3" install pdoc
670         cd "$WORKSPACE/sdk/python"
671         python3 setup.py install
672     ) || fatal "installing PyYAML and sdk/python failed"
673 }
674
675 retry() {
676     remain="${repeat}"
677     while :
678     do
679         if ${@}; then
680             if [[ "$remain" -gt 1 ]]; then
681                 remain=$((${remain}-1))
682                 title "(repeating ${remain} more times)"
683             else
684                 break
685             fi
686         elif [[ "$retry" == 1 ]]; then
687             read -p 'Try again? [Y/n] ' x
688             if [[ "$x" != "y" ]] && [[ "$x" != "" ]]
689             then
690                 break
691             fi
692         else
693             break
694         fi
695     done
696 }
697
698 do_test() {
699     case "${1}" in
700         apps/workbench_units | apps/workbench_functionals | apps/workbench_integration)
701             suite=apps/workbench
702             ;;
703         services/workbench2_units | services/workbench2_integration)
704             suite=services/workbench2
705             ;;
706         *)
707             suite="${1}"
708             ;;
709     esac
710     if [[ -n "${skip[$suite]}" || \
711               -n "${skip[$1]}" || \
712               (${#only[@]} -ne 0 && ${only[$suite]} -eq 0 && ${only[$1]} -eq 0) ]]; then
713         return 0
714     fi
715     case "${1}" in
716         services/api)
717             stop_services
718             check_arvados_config "$1"
719             ;;
720         gofmt | doc | lib/cli | lib/cloud/azure | lib/cloud/ec2 | lib/cloud/cloudtest | lib/cmd | lib/dispatchcloud/sshexecutor | lib/dispatchcloud/worker | services/workbench2_units | services/workbench2_integration)
721             check_arvados_config "$1"
722             # don't care whether services are running
723             ;;
724         *)
725             check_arvados_config "$1"
726             if ! start_services; then
727                 checkexit 1 "$1 tests"
728                 title "test $1 -- failed to start services"
729                 return 1
730             fi
731             ;;
732     esac
733     retry do_test_once ${@}
734 }
735
736 go_ldflags() {
737     version=${ARVADOS_VERSION:-$(git log -n1 --format=%H)-dev}
738     echo "-X git.arvados.org/arvados.git/lib/cmd.version=${version} -X main.version=${version} -s -w"
739 }
740
741 do_test_once() {
742     unset result
743
744     title "test $1"
745     timer_reset
746
747     result=
748     if which deactivate >/dev/null; then deactivate; fi
749     if ! . "$VENV3DIR/bin/activate"
750     then
751         result=1
752     elif [[ "$2" == "go" ]]
753     then
754         covername="coverage-$(echo "$1" | sed -e 's/\//_/g')"
755         coverflags=("-covermode=count" "-coverprofile=$WORKSPACE/tmp/.$covername.tmp")
756         testflags=()
757         if [[ "$1" == "cmd/arvados-package" ]]; then
758             testflags+=("-timeout" "20m")
759         fi
760         # We do "go install" here to catch compilation errors
761         # before trying "go test". Otherwise, coverage-reporting
762         # mode makes Go show the wrong line numbers when reporting
763         # compilation errors.
764         go install -ldflags "$(go_ldflags)" "$WORKSPACE/$1" && \
765             cd "$WORKSPACE/$1" && \
766             if [[ -n "${testargs[$1]}" ]]
767         then
768             # "go test -check.vv giturl" doesn't work, but this
769             # does:
770             go test ${short:+-short} ${testflags[@]} ${testargs[$1]}
771         else
772             # The above form gets verbose even when testargs is
773             # empty, so use this form in such cases:
774             go test ${short:+-short} ${testflags[@]} ${coverflags[@]} "git.arvados.org/arvados.git/$1"
775         fi
776         result=${result:-$?}
777         if [[ -f "$WORKSPACE/tmp/.$covername.tmp" ]]
778         then
779             go tool cover -html="$WORKSPACE/tmp/.$covername.tmp" -o "$WORKSPACE/tmp/$covername.html"
780             rm "$WORKSPACE/tmp/.$covername.tmp"
781         fi
782         [[ $result = 0 ]] && gofmt -e -d *.go
783     elif [[ "$2" == "pip" ]]
784     then
785         tries=0
786         cd "$WORKSPACE/$1" && while :
787         do
788             tries=$((${tries}+1))
789             # $3 can name a path directory for us to use, including trailing
790             # slash; e.g., the bin/ subdirectory of a virtualenv.
791             if [[ -e "${3}activate" ]]; then
792                 . "${3}activate"
793             fi
794             python setup.py ${short:+--short-tests-only} test ${testargs[$1]}
795             result=$?
796             if [[ ${tries} < 3 && ${result} == 137 ]]
797             then
798                 printf '\n*****\n%s tests killed -- retrying\n*****\n\n' "$1"
799                 continue
800             else
801                 break
802             fi
803         done
804     elif [[ "$2" != "" ]]
805     then
806         "test_$2"
807     else
808         "test_$1"
809     fi
810     result=${result:-$?}
811     checkexit $result "$1 tests"
812     title "test $1 -- `timer`"
813     return $result
814 }
815
816 check_arvados_config() {
817     if [[ "$1" = "env" ]] ; then
818         return
819     fi
820     if [[ -z "$ARVADOS_CONFIG" ]] ; then
821         # Create config file.  The run_test_server script requires PyYAML,
822         # so virtualenv needs to be active.  Downstream steps like
823         # workbench install which require a valid config.yml.
824         if [[ ! -s "$VENV3DIR/bin/activate" ]] ; then
825             install_env
826         fi
827         . "$VENV3DIR/bin/activate"
828         cd "$WORKSPACE"
829         eval $(python3 sdk/python/tests/run_test_server.py setup_config)
830         deactivate
831     fi
832 }
833
834 do_install() {
835     if [[ -n "${skip[install]}" || ( -n "${only_install}" && "${only_install}" != "${1}" && "${only_install}" != "${2}" ) ]]; then
836         return 0
837     fi
838     check_arvados_config "$1"
839     retry do_install_once ${@}
840 }
841
842 do_install_once() {
843     title "install $1"
844     timer_reset
845
846     result=
847     if which deactivate >/dev/null; then deactivate; fi
848     if [[ "$1" != "env" ]] && ! . "$VENV3DIR/bin/activate"; then
849         result=1
850     elif [[ "$2" == "go" ]]
851     then
852         go install -ldflags "$(go_ldflags)" "$WORKSPACE/$1"
853     elif [[ "$2" == "pip" ]]
854     then
855         # $3 can name a path directory for us to use, including trailing
856         # slash; e.g., the bin/ subdirectory of a virtualenv.
857
858         # Need to change to a different directory after creating
859         # the source dist package to avoid a pip bug.
860         # see https://arvados.org/issues/5766 for details.
861
862         # Also need to install twice, because if it believes the package is
863         # already installed, pip it won't install it.  So the first "pip
864         # install" ensures that the dependencies are met, the second "pip
865         # install" ensures that we've actually installed the local package
866         # we just built.
867         cd "$WORKSPACE/$1" \
868             && "${3}python3" setup.py sdist rotate --keep=1 --match .tar.gz \
869             && cd "$WORKSPACE" \
870             && "${3}pip3" install --no-cache-dir "$WORKSPACE/$1/dist"/*.tar.gz \
871             && "${3}pip3" install --no-cache-dir --no-deps --ignore-installed "$WORKSPACE/$1/dist"/*.tar.gz
872     elif [[ "$2" != "" ]]
873     then
874         "install_$2"
875     else
876         "install_$1"
877     fi
878     result=${result:-$?}
879     checkexit $result "$1 install"
880     title "install $1 -- `timer`"
881     return $result
882 }
883
884 bundle_install_trylocal() {
885     (
886         set -e
887         echo "(Running bundle install --local. 'could not find package' messages are OK.)"
888         if ! "$bundle" install --local --no-deployment; then
889             echo "(Running bundle install again, without --local.)"
890             "$bundle" install --no-deployment
891         fi
892         "$bundle" package
893     )
894 }
895
896 install_doc() {
897     cd "$WORKSPACE/doc" \
898         && bundle_install_trylocal \
899         && rm -rf .site
900 }
901
902 install_gem() {
903     gemname=$1
904     srcpath=$2
905     with_test_gemset gem_uninstall_if_exists "$gemname" \
906         && cd "$WORKSPACE/$srcpath" \
907         && bundle_install_trylocal \
908         && gem build "$gemname.gemspec" \
909         && with_test_gemset gem install --no-document $(ls -t "$gemname"-*.gem|head -n1)
910 }
911
912 install_sdk/ruby() {
913     install_gem arvados sdk/ruby
914 }
915
916 install_sdk/R() {
917   if [[ "$NEED_SDK_R" = true ]]; then
918     cd "$WORKSPACE/sdk/R" \
919        && Rscript --vanilla install_deps.R
920   fi
921 }
922
923 install_sdk/cli() {
924     install_gem arvados-cli sdk/cli
925 }
926
927 install_services/login-sync() {
928     install_gem arvados sdk/ruby
929     install_gem arvados-login-sync services/login-sync
930 }
931
932 install_services/api() {
933     stop_services
934     check_arvados_config "services/api"
935     cd "$WORKSPACE/services/api" \
936         && RAILS_ENV=test bundle_install_trylocal \
937             || return 1
938
939     rm -f config/environments/test.rb
940     cp config/environments/test.rb.example config/environments/test.rb
941
942     # Clear out any lingering postgresql connections to the test
943     # database, so that we can drop it. This assumes the current user
944     # is a postgresql superuser.
945     cd "$WORKSPACE/services/api" \
946         && test_database=$("${VENV3DIR}/bin/python3" -c "import yaml; print(yaml.safe_load(open('$ARVADOS_CONFIG','r'))['Clusters']['zzzzz']['PostgreSQL']['Connection']['dbname'])") \
947         && psql "$test_database" -c "SELECT pg_terminate_backend (pg_stat_activity.pid::int) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$test_database';" 2>/dev/null
948
949     mkdir -p "$WORKSPACE/services/api/tmp/pids"
950
951     cert="$WORKSPACE/services/api/tmp/self-signed"
952     if [[ ! -e "$cert.pem" || "$(date -r "$cert.pem" +%s)" -lt 1512659226 ]]; then
953         (
954             dir="$WORKSPACE/services/api/tmp"
955             set -e
956             openssl req -newkey rsa:2048 -nodes -subj '/C=US/ST=State/L=City/CN=localhost' -out "$cert.csr" -keyout "$cert.key" </dev/null
957             openssl x509 -req -in "$cert.csr" -signkey "$cert.key" -out "$cert.pem" -days 3650 -extfile <(printf 'subjectAltName=DNS:localhost,DNS:::1,DNS:0.0.0.0,DNS:127.0.0.1,IP:::1,IP:0.0.0.0,IP:127.0.0.1')
958         ) || return 1
959     fi
960
961     cd "$WORKSPACE/services/api" \
962         && rm -rf tmp/git \
963         && mkdir -p tmp/git \
964         && cd tmp/git \
965         && tar xf ../../test/test.git.tar \
966         && mkdir -p internal.git \
967         && git --git-dir internal.git init \
968             || return 1
969
970     (
971         set -ex
972         cd "$WORKSPACE/services/api"
973         export RAILS_ENV=test
974         if bin/rails db:environment:set ; then
975             bin/rake db:drop
976         fi
977         bin/rake db:setup
978         bin/rake db:fixtures:load
979     ) || return 1
980 }
981
982 declare -a pythonstuff
983 pythonstuff=(
984     sdk/python:py3
985     sdk/cwl:py3
986     services/dockercleaner:py3
987     services/fuse:py3
988     tools/crunchstat-summary:py3
989 )
990
991 declare -a gostuff
992 gostuff=($(cd "$WORKSPACE" && git ls-files | grep '\.go$' | sed -e 's/\/[^\/]*$//' | sort -u))
993
994 install_apps/workbench() {
995     cd "$WORKSPACE/apps/workbench" \
996         && mkdir -p tmp/cache \
997         && RAILS_ENV=test bundle_install_trylocal \
998         && RAILS_ENV=test RAILS_GROUPS=assets "$bundle" exec rake npm:install
999 }
1000
1001 install_services/workbench2() {
1002     cd "$WORKSPACE/services/workbench2" \
1003         && make yarn-install ARVADOS_DIRECTORY="${WORKSPACE}"
1004 }
1005
1006 test_doc() {
1007     (
1008         set -e
1009         cd "$WORKSPACE/doc"
1010         ARVADOS_API_HOST=pirca.arvadosapi.com
1011         # Make sure python-epydoc is installed or the next line won't
1012         # do much good!
1013         PYTHONPATH=$WORKSPACE/sdk/python/ "$bundle" exec rake linkchecker baseurl=file://$WORKSPACE/doc/.site/ arvados_workbench_host=https://workbench.$ARVADOS_API_HOST arvados_api_host=$ARVADOS_API_HOST
1014     )
1015 }
1016
1017 test_gofmt() {
1018     cd "$WORKSPACE" || return 1
1019     dirs=$(ls -d */ | egrep -v 'vendor|tmp')
1020     [[ -z "$(gofmt -e -d $dirs | tee -a /dev/stderr)" ]]
1021 }
1022
1023 test_services/api() {
1024     rm -f "$WORKSPACE/services/api/git-commit.version"
1025     cd "$WORKSPACE/services/api" \
1026         && eval env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} "$bundle" exec rake test TESTOPTS=\'-v -d\' ${testargs[services/api]}
1027 }
1028
1029 test_sdk/ruby() {
1030     cd "$WORKSPACE/sdk/ruby" \
1031         && "$bundle" exec rake test TESTOPTS=-v ${testargs[sdk/ruby]}
1032 }
1033
1034 test_sdk/R() {
1035   if [[ "$NEED_SDK_R" = true ]]; then
1036     cd "$WORKSPACE/sdk/R" \
1037         && Rscript --vanilla run_test.R
1038   fi
1039 }
1040
1041 test_sdk/cli() {
1042     cd "$WORKSPACE/sdk/cli" \
1043         && mkdir -p /tmp/keep \
1044         && KEEP_LOCAL_STORE=/tmp/keep "$bundle" exec rake test TESTOPTS=-v ${testargs[sdk/cli]}
1045 }
1046
1047 test_sdk/java-v2() {
1048     cd "$WORKSPACE/sdk/java-v2" && gradle test ${testargs[sdk/java-v2]}
1049 }
1050
1051 test_services/login-sync() {
1052     cd "$WORKSPACE/services/login-sync" \
1053         && "$bundle" exec rake test TESTOPTS=-v ${testargs[services/login-sync]}
1054 }
1055
1056 test_services/workbench2_units() {
1057     cd "$WORKSPACE/services/workbench2" && make unit-tests ARVADOS_DIRECTORY="${WORKSPACE}" WORKSPACE="$(pwd)" ${testargs[services/workbench2]}
1058 }
1059
1060 test_services/workbench2_integration() {
1061     cd "$WORKSPACE/services/workbench2" && make integration-tests ARVADOS_DIRECTORY="${WORKSPACE}" WORKSPACE="$(pwd)" ${testargs[services/workbench2]}
1062 }
1063
1064 test_apps/workbench_units() {
1065     local TASK="test:units"
1066     cd "$WORKSPACE/apps/workbench" \
1067         && eval env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} "$bundle" exec rake ${TASK} TESTOPTS=\'-v -d\' ${testargs[apps/workbench]} ${testargs[apps/workbench_units]}
1068 }
1069
1070 test_apps/workbench_functionals() {
1071     local TASK="test:functionals"
1072     cd "$WORKSPACE/apps/workbench" \
1073         && eval env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} "$bundle" exec rake ${TASK} TESTOPTS=\'-v -d\' ${testargs[apps/workbench]} ${testargs[apps/workbench_functionals]}
1074 }
1075
1076 test_apps/workbench_integration() {
1077     local TASK="test:integration"
1078     cd "$WORKSPACE/apps/workbench" \
1079         && eval env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} "$bundle" exec rake ${TASK} TESTOPTS=\'-v -d\' ${testargs[apps/workbench]} ${testargs[apps/workbench_integration]}
1080 }
1081
1082 test_apps/workbench_benchmark() {
1083     local TASK="test:benchmark"
1084     cd "$WORKSPACE/apps/workbench" \
1085         && eval env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} "$bundle" exec rake ${TASK} ${testargs[apps/workbench_benchmark]}
1086 }
1087
1088 test_apps/workbench_profile() {
1089     local TASK="test:profile"
1090     cd "$WORKSPACE/apps/workbench" \
1091         && eval env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} "$bundle" exec rake ${TASK} ${testargs[apps/workbench_profile]}
1092 }
1093
1094 install_deps() {
1095     # Install parts needed by test suites
1096     do_install env
1097     do_install cmd/arvados-server go
1098     do_install sdk/cli
1099     do_install sdk/python pip "${VENV3DIR}/bin/"
1100     do_install sdk/ruby
1101     do_install services/api
1102     do_install services/keepproxy go
1103     do_install services/keep-web go
1104 }
1105
1106 install_all() {
1107     do_install env
1108     do_install doc
1109     do_install sdk/ruby
1110     do_install sdk/R
1111     do_install sdk/cli
1112     do_install services/login-sync
1113     for p in "${pythonstuff[@]}"
1114     do
1115        dir=${p%:py3}
1116        if [[ -z ${skip[python3]} ]]; then
1117            do_install ${dir} pip "$VENV3DIR/bin/"
1118        fi
1119     done
1120     for g in "${gostuff[@]}"
1121     do
1122         do_install "$g" go
1123     done
1124     do_install services/api
1125     do_install apps/workbench
1126     do_install services/workbench2
1127 }
1128
1129 test_all() {
1130     stop_services
1131     do_test services/api
1132
1133     # Shortcut for when we're only running apiserver tests. This saves a bit of time,
1134     # because we don't need to start up the api server for subsequent tests.
1135     if [ ! -z "$only" ] && [ "$only" == "services/api" ]; then
1136         rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
1137         exit_cleanly
1138     fi
1139
1140     do_test gofmt
1141     do_test doc
1142     do_test sdk/ruby
1143     do_test sdk/R
1144     do_test sdk/cli
1145     do_test services/login-sync
1146     do_test sdk/java-v2
1147     for p in "${pythonstuff[@]}"
1148     do
1149         dir=${p%:py3}
1150         if [[ -z ${skip[python3]} ]]; then
1151             do_test ${dir} pip "$VENV3DIR/bin/"
1152         fi
1153     done
1154
1155     for g in "${gostuff[@]}"
1156     do
1157         do_test "$g" go
1158     done
1159     do_test apps/workbench_units
1160     do_test apps/workbench_functionals
1161     do_test apps/workbench_integration
1162     do_test apps/workbench_benchmark
1163     do_test apps/workbench_profile
1164     do_test services/workbench2_units
1165     do_test services/workbench2_integration
1166 }
1167
1168 test_go() {
1169     do_test gofmt
1170     for g in "${gostuff[@]}"
1171     do
1172         do_test "$g" go
1173     done
1174 }
1175
1176 help_interactive() {
1177     echo "== Interactive commands:"
1178     echo "TARGET                 (short for 'test DIR')"
1179     echo "test TARGET"
1180     echo "10 test TARGET         (run test 10 times)"
1181     echo "test TARGET:py3        (test with python3)"
1182     echo "test TARGET -check.vv  (pass arguments to test)"
1183     echo "install TARGET"
1184     echo "install env            (go/python libs)"
1185     echo "install deps           (go/python libs + arvados components needed for integration tests)"
1186     echo "reset                  (...services used by integration tests)"
1187     echo "exit"
1188     echo "== Test targets:"
1189     echo "${!testfuncargs[@]}" | tr ' ' '\n' | sort | column
1190 }
1191
1192 initialize
1193
1194 declare -A testfuncargs=()
1195 for g in "${gostuff[@]}"; do
1196     testfuncargs[$g]="$g go"
1197 done
1198 for p in "${pythonstuff[@]}"; do
1199     dir=${p%:py3}
1200     testfuncargs[$dir:py3]="$dir pip $VENV3DIR/bin/"
1201 done
1202
1203 testfuncargs["sdk/cli"]="sdk/cli"
1204 testfuncargs["sdk/R"]="sdk/R"
1205 testfuncargs["sdk/java-v2"]="sdk/java-v2"
1206 testfuncargs["apps/workbench_units"]="apps/workbench_units"
1207 testfuncargs["apps/workbench_functionals"]="apps/workbench_functionals"
1208 testfuncargs["apps/workbench_integration"]="apps/workbench_integration"
1209 testfuncargs["apps/workbench_benchmark"]="apps/workbench_benchmark"
1210 testfuncargs["apps/workbench_profile"]="apps/workbench_profile"
1211
1212 if [[ -z ${interactive} ]]; then
1213     install_all
1214     test_all
1215 else
1216     skip=()
1217     only=()
1218     only_install=()
1219     if [[ -e "$VENV3DIR/bin/activate" ]]; then stop_services; fi
1220     setnextcmd() {
1221         if [[ "$TERM" = dumb ]]; then
1222             # assume emacs, or something, is offering a history buffer
1223             # and pre-populating the command will only cause trouble
1224             nextcmd=
1225         elif [[ ! -e "$VENV3DIR/bin/activate" ]]; then
1226             nextcmd="install deps"
1227         else
1228             nextcmd=""
1229         fi
1230     }
1231     echo
1232     help_interactive
1233     nextcmd="install deps"
1234     setnextcmd
1235     HISTFILE="$WORKSPACE/tmp/.history"
1236     history -r
1237     ignore_sigint=1
1238     while read -p 'What next? ' -e -i "$nextcmd" nextcmd; do
1239         history -s "$nextcmd"
1240         history -w
1241         count=1
1242         if [[ "${nextcmd}" =~ ^[0-9] ]]; then
1243           read count nextcmd <<<"${nextcmd}"
1244         fi
1245         read verb target opts <<<"${nextcmd}"
1246         target="${target%/}"
1247         target="${target/\/:/:}"
1248         case "${verb}" in
1249             "exit" | "quit")
1250                 exit_cleanly
1251                 ;;
1252             "reset")
1253                 stop_services
1254                 ;;
1255             "test" | "install")
1256                 case "$target" in
1257                     "")
1258                         help_interactive
1259                         ;;
1260                     all | deps)
1261                         ${verb}_${target}
1262                         ;;
1263                     *)
1264                         argstarget=${target%:py3}
1265                         testargs["$argstarget"]="${opts}"
1266                         tt="${testfuncargs[${target}]}"
1267                         tt="${tt:-$target}"
1268                         while [ $count -gt 0 ]; do
1269                           do_$verb $tt
1270                           let "count=count-1"
1271                         done
1272                         ;;
1273                 esac
1274                 ;;
1275             "" | "help" | *)
1276                 help_interactive
1277                 ;;
1278         esac
1279         if [[ ${#successes[@]} -gt 0 || ${#failures[@]} -gt 0 ]]; then
1280             report_outcomes
1281             successes=()
1282             failures=()
1283         fi
1284         cd "$WORKSPACE"
1285         setnextcmd
1286     done
1287     echo
1288 fi
1289 exit_cleanly