2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
7 . `dirname "$(readlink -f "$0")"`/run-library.sh
9 read -rd "\000" helpmessage <<EOF
10 $(basename $0): Install and test Arvados components.
12 Exit non-zero if any tests fail.
15 $(basename $0) WORKSPACE=/path/to/arvados [options]
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. If given
25 more than once, all specified test suites are run.
26 --temp DIR Install components and dependencies under DIR instead of
27 making a new temporary directory. Implies --leave-temp.
28 --leave-temp Do not remove GOPATH, virtualenv, and other temp dirs at exit.
29 Instead, show the path to give as --temp to reuse them in
30 subsequent invocations.
31 --repeat N Repeat each install/test step until it succeeds N times.
32 --retry Prompt to retry if an install or test suite fails.
33 --only-install Run specific install step. If given more than once,
34 all but the last are ignored.
35 --short Skip (or scale down) some slow tests.
36 --interactive Set up, then prompt for test/install steps to perform.
37 WORKSPACE=path Arvados source tree to test.
38 CONFIGSRC=path Dir with config.yml file containing PostgreSQL section for use by tests.
39 services/api_test="TEST=test/functional/arvados/v1/collections_controller_test.rb"
40 Restrict apiserver tests to the given file
41 sdk/python_test="tests/test_api.py::ArvadosApiTest"
42 Restrict Python SDK tests to the given class
43 lib/dispatchcloud_test="-check.vv"
44 Show all log messages, even when tests pass (also works
45 with services/keepstore_test etc.)
47 Print more debug messages
48 envvar=value Set \$envvar to value. Primarily useful for WORKSPACE,
49 *_test, and other examples shown above.
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.
56 As a special concession to the current CI server config, CONFIGSRC
57 defaults to $HOME/arvados-api-server if that directory exists.
59 More information and background:
61 https://dev.arvados.org/projects/arvados/wiki/Running_tests
72 lib/controller/federation
73 lib/controller/railsproxy
82 lib/dispatchcloud/container
83 lib/dispatchcloud/scheduler
84 lib/dispatchcloud/sshexecutor
85 lib/dispatchcloud/worker
90 services/dockercleaner
98 services/crunch-dispatch-local
99 services/crunch-dispatch-slurm
100 services/workbench2_units
101 services/workbench2_integration
106 sdk/ruby-google-api-client
122 tools/crunchstat-summary
125 tools/keep-block-check
126 tools/cluster-activity
130 # First make sure to remove any ARVADOS_ variables from the calling
131 # environment that could interfere with the tests.
132 unset $(env | cut -d= -f1 | grep \^ARVADOS_)
134 # Reset other variables that could affect our [tests'] behavior by
142 export LANG=en_US.UTF-8
152 if [[ -z "$temp" ]]; then
153 # we did not even get as far as making a temp dir
155 elif [[ -z "$temp_preserve" ]]; then
156 # Go creates readonly dirs in the module cache, which cause
157 # "rm -rf" to fail unless we chmod first.
161 echo "Leaving behind temp dirs in $temp"
167 echo >&2 "Fatal: $* (encountered in ${FUNCNAME[1]} at ${BASH_SOURCE[1]} line ${BASH_LINENO[0]})"
174 rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
181 [[ -n "${skip[sanity]}" ]] && return 0
182 ( [[ -n "$WORKSPACE" ]] && [[ -d "$WORKSPACE/services" ]] ) \
183 || fatal "WORKSPACE environment variable not set to a source directory (see: $0 --help)"
184 [[ -z "$CONFIGSRC" ]] || [[ -s "$CONFIGSRC/config.yml" ]] \
185 || fatal "CONFIGSRC is $CONFIGSRC but '$CONFIGSRC/config.yml' is empty or not found (see: $0 --help)"
186 echo Checking dependencies:
187 echo "locale: ${LANG}"
188 [[ "$(locale charmap)" = "UTF-8" ]] \
189 || fatal "Locale '${LANG}' is broken/missing. Try: echo ${LANG} | sudo tee -a /etc/locale.gen && sudo locale-gen"
192 || fatal "No ruby. Install >=2.7 from package or source"
195 || fatal "No go binary. See http://golang.org/doc/install"
196 [[ $(go version) =~ go1.([0-9]+) ]] && [[ ${BASH_REMATCH[1]} -ge 12 ]] \
197 || fatal "Go >= 1.12 required. See http://golang.org/doc/install"
199 gcc --version | egrep ^gcc \
200 || fatal "No gcc. Try: apt-get install build-essential"
202 find /usr/include -path '*fuse/fuse.h' | egrep --max-count=1 . \
203 || fatal "No fuse/fuse.h. Try: apt-get install libfuse-dev"
205 find /usr/include -path '*gnutls/gnutls.h' | egrep --max-count=1 . \
206 || fatal "No gnutls/gnutls.h. Try: apt-get install libgnutls28-dev"
207 echo -n 'virtualenv: '
208 python3 -m venv --help | grep -q '^usage: venv ' \
209 && echo "venv module found" \
210 || fatal "No virtualenv. Try: apt-get install python3-venv"
211 echo -n 'Python3 pyconfig.h: '
212 find /usr/include -path '*/python3*/pyconfig.h' | egrep --max-count=1 . \
213 || fatal "No Python3 pyconfig.h. Try: apt-get install python3-dev"
215 || fatal "No netstat. Try: apt-get install net-tools"
217 PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin" nginx -v \
218 || fatal "No nginx. Try: apt-get install nginx"
221 || fatal "No npm. Try: wget -O- https://nodejs.org/dist/v12.22.12/node-v12.22.12-linux-x64.tar.xz | sudo tar -C /usr/local -xJf - && sudo ln -s ../node-v12.22.12-linux-x64/bin/{node,npm} /usr/local/bin/"
223 cadaver --version | grep -w cadaver \
224 || fatal "No cadaver. Try: apt-get install cadaver"
225 echo -n 'libattr1 xattr.h: '
226 find /usr/include -path '*/attr/xattr.h' | egrep --max-count=1 . \
227 || fatal "No libattr1 xattr.h. Try: apt-get install libattr1-dev"
228 echo -n 'libcurl curl.h: '
229 find /usr/include -path '*/curl/curl.h' | egrep --max-count=1 . \
230 || fatal "No libcurl curl.h. Try: apt-get install libcurl4-gnutls-dev"
231 echo -n 'libpq libpq-fe.h: '
232 find /usr/include -path '*/postgresql/libpq-fe.h' | egrep --max-count=1 . \
233 || fatal "No libpq libpq-fe.h. Try: apt-get install libpq-dev"
234 echo -n 'libpam pam_appl.h: '
235 find /usr/include -path '*/security/pam_appl.h' | egrep --max-count=1 . \
236 || fatal "No libpam pam_appl.h. Try: apt-get install libpam0g-dev"
237 echo -n 'postgresql: '
238 psql --version || fatal "No postgresql. Try: apt-get install postgresql postgresql-client-common"
240 which Xvfb || fatal "No xvfb. Try: apt-get install xvfb"
242 dot -V || fatal "No graphviz. Try: apt-get install graphviz"
243 echo -n 'singularity: '
244 singularity --version || fatal "No singularity. Try: arvados-server install"
245 echo -n 'docker client: '
246 docker --version || echo "No docker client. Try: arvados-server install"
247 echo -n 'docker server: '
248 docker info --format='{{.ServerVersion}}' || echo "No docker server. Try: arvados-server install"
250 s3cmd --version || echo "No s3cmd. Try: apt-get install s3cmd"
252 if [[ "$NEED_SDK_R" = true ]]; then
255 which Rscript || fatal "No Rscript. Try: apt-get install r-base"
257 Rscript -e "library('testthat')" || fatal "No testthat. Try: apt-get install r-cran-testthat"
258 # needed for roxygen2, needed for devtools, needed for R sdk
259 pkg-config --exists libxml-2.0 || fatal "No libxml2. Try: apt-get install libxml2-dev"
260 # needed for pkgdown, builds R SDK doc pages
261 which pandoc || fatal "No pandoc. Try: apt-get install pandoc"
263 echo 'procs with /dev/fuse open:'
264 find /proc/*/fd -lname /dev/fuse 2>/dev/null | cut -d/ -f3 | xargs --no-run-if-empty ps -lywww
265 echo 'grep fuse /proc/self/mountinfo:'
266 grep fuse /proc/self/mountinfo
270 # i.e. rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
271 # $BUILD_NUMBER is set by Jenkins if this script is being called as part of a Jenkins run
272 if [[ -f "$1/$2" ]]; then
273 THEDATE=`date +%Y%m%d%H%M%S`
274 mv "$1/$2" "$1/$THEDATE-$BUILD_NUMBER-$2"
275 gzip "$1/$THEDATE-$BUILD_NUMBER-$2"
289 echo >&2 "$helpmessage"
294 skip["${1%:py3}"]=1; shift
297 only["${1%:py3}"]=1; skip["${1%:py3}"]=""; shift
309 only_install="$1"; shift
319 repeat=$((${1}+0)); shift
325 suite="${arg%%_test=*}"
327 testargs["${suite%:py3}"]="$args"
330 eval export $(echo $arg | cut -d= -f1)=\"$(echo $arg | cut -d= -f2-)\"
333 echo >&2 "$0: Unrecognized option: '$arg'. Try: $0 --help"
339 # R SDK installation is very slow (~360s in a clean environment) and only
340 # required when testing it. Skip that step if it is not needed.
343 if [[ ${#only[@]} -ne 0 ]] &&
344 [[ -z "${only['sdk/R']}" && -z "${only['doc']}" ]]; then
348 if [[ ${skip["sdk/R"]} == 1 && ${skip["doc"]} == 1 ]]; then
352 if [[ $NEED_SDK_R == false ]]; then
353 echo "R SDK not needed, it will not be installed."
358 pid="$(cat "$WORKSPACE/tmp/${svc}.pid")"
359 if [[ -z "$pid" ]] || ! kill -0 "$pid"; then
360 tail $WORKSPACE/tmp/${1}*.log
361 echo "${svc} pid ${pid} not running"
364 echo "${svc} pid ${pid} ok"
369 base=$("${VENV3DIR}/bin/python3" -c "import yaml; print(list(yaml.safe_load(open('$ARVADOS_CONFIG','r'))['Clusters']['zzzzz']['Services']['$1']['InternalURLs'].keys())[0])")
370 url="$base/_health/ping"
371 if ! curl -Ss -H "Authorization: Bearer e687950a23c3a9bceec28c6223a06c79" "${url}" | tee -a /dev/stderr | grep '"OK"'; then
377 checkdiscoverydoc() {
378 dd="https://${1}/discovery/v1/apis/arvados/v1/rest"
379 if ! (set -o pipefail; curl -fsk "$dd" | grep -q ^{ ); then
380 echo >&2 "ERROR: could not retrieve discovery doc from RailsAPI at $dd"
381 tail -v $WORKSPACE/tmp/railsapi.log
388 if [[ -n "$ARVADOS_TEST_API_HOST" ]]; then
391 echo 'Starting API, controller, keepproxy, keep-web, ws, and nginx ssl proxy...'
392 if [[ ! -d "$WORKSPACE/services/api/log" ]]; then
393 mkdir -p "$WORKSPACE/services/api/log"
395 # Remove empty api.pid file if it exists
396 if [[ -f "$WORKSPACE/tmp/api.pid" && ! -s "$WORKSPACE/tmp/api.pid" ]]; then
397 rm -f "$WORKSPACE/tmp/api.pid"
399 all_services_stopped=
403 && eval $(python3 sdk/python/tests/run_test_server.py start --auth admin) \
404 && export ARVADOS_TEST_API_HOST="$ARVADOS_API_HOST" \
405 && export ARVADOS_TEST_API_INSTALLED="$$" \
406 && checkpidfile api \
407 && checkdiscoverydoc $ARVADOS_API_HOST \
408 && eval $(python3 sdk/python/tests/run_test_server.py start_nginx) \
409 && checkpidfile nginx \
410 && python3 sdk/python/tests/run_test_server.py start_controller \
411 && checkpidfile controller \
412 && checkhealth Controller \
413 && checkdiscoverydoc $ARVADOS_API_HOST \
414 && python3 sdk/python/tests/run_test_server.py start_keep_proxy \
415 && checkpidfile keepproxy \
416 && python3 sdk/python/tests/run_test_server.py start_keep-web \
417 && checkpidfile keep-web \
418 && checkhealth WebDAV \
419 && python3 sdk/python/tests/run_test_server.py start_ws \
421 && export ARVADOS_TEST_PROXY_SERVICES=1 \
422 && (env | egrep ^ARVADOS) \
424 if [[ $fail != 0 ]]; then
425 unset ARVADOS_TEST_API_HOST
431 if [[ -n "$all_services_stopped" ]]; then
434 unset ARVADOS_TEST_API_HOST ARVADOS_TEST_PROXY_SERVICES
436 && python3 sdk/python/tests/run_test_server.py stop_nginx \
437 && python3 sdk/python/tests/run_test_server.py stop_ws \
438 && python3 sdk/python/tests/run_test_server.py stop_keep-web \
439 && python3 sdk/python/tests/run_test_server.py stop_keep_proxy \
440 && python3 sdk/python/tests/run_test_server.py stop_controller \
441 && python3 sdk/python/tests/run_test_server.py stop \
442 && all_services_stopped=1
447 if [[ -n "$ignore_sigint" ]]; then
448 echo >&2 "ignored SIGINT"
451 failures+=("($(basename $0) interrupted)")
456 setup_ruby_environment() {
457 # When our "bundle install"s need to install new gems to
458 # satisfy dependencies, we want them to go where "gem install
459 # --user-install" would put them. (However, if the caller has
460 # already set GEM_HOME, we assume that's where dependencies
461 # should be installed, and we should leave it alone.)
463 if [ -z "$GEM_HOME" ]; then
464 user_gempath="$(gem env gempath)"
465 export GEM_HOME="${user_gempath%%:*}"
467 PATH="$(gem env gemdir)/bin:$PATH"
469 # When we build and install our own gems, we install them in our
470 # $GEMHOME tmpdir, and we want them to be at the front of GEM_PATH and
471 # PATH so integration tests prefer them over other versions that
472 # happen to be installed in $user_gempath, system dirs, etc.
474 tmpdir_gem_home="$(env - PATH="$PATH" HOME="$GEMHOME" gem env gempath | cut -f1 -d:)"
475 PATH="$tmpdir_gem_home/bin:$PATH"
476 export GEM_PATH="$tmpdir_gem_home:$(gem env gempath)"
478 echo "Will install dependencies to $(gem env gemdir)"
479 echo "Will install bundler and arvados gems to $tmpdir_gem_home"
480 echo "Gem search path is GEM_PATH=$GEM_PATH"
481 gem install --user --no-document --conservative --version '~> 2.4.0' bundler \
482 || fatal 'install bundler'
486 GEM_HOME="$tmpdir_gem_home" GEM_PATH="$tmpdir_gem_home" "$@"
489 gem_uninstall_if_exists() {
490 if gem list "$1\$" | egrep '^\w'; then
491 gem uninstall --force --all --executables "$1"
496 if [[ -z "${VENV3DIR:-}" ]]; then
497 fatal "setup_virtualenv called before \$VENV3DIR was set"
498 elif ! [[ -e "$VENV3DIR/bin/activate" ]]; then
499 python3 -m venv "$VENV3DIR" || fatal "virtualenv creation failed"
500 # Configure pip options we always want to use.
501 "$VENV3DIR/bin/pip" config --quiet --site set global.disable-pip-version-check true
502 "$VENV3DIR/bin/pip" config --quiet --site set global.no-input true
503 "$VENV3DIR/bin/pip" config --quiet --site set global.no-python-version-warning true
504 "$VENV3DIR/bin/pip" config --quiet --site set install.progress-bar off
505 # If we didn't have a virtualenv before, we couldn't have started any
506 # services. Set the flag used by stop_services to indicate that.
507 all_services_stopped=1
509 . "$VENV3DIR/bin/activate" || fatal "virtualenv activation failed"
510 # pip >= 20.3 is necessary for modern dependency resolution.
511 # setuptools is our chosen Python build tool.
512 # wheel modernizes the venv (as of early 2024) and makes it more closely
513 # match our package build environment.
514 # We must have these in place *before* we install the PySDK below.
515 pip install "pip>=20.3" setuptools wheel ||
516 fatal "failed to install build packages in virtualenv"
517 # run-tests.sh uses run_test_server.py from the Python SDK.
518 # This requires both the Python SDK itself and PyYAML.
519 # Hence we must install these dependencies this early for the rest of the
521 pip install PyYAML || fatal "failed to install PyYAML in virtualenv"
522 do_install_once sdk/python pip || fatal "failed to install PySDK in virtualenv"
526 # If dependencies like ruby, go, etc. are installed in
527 # /var/lib/arvados -- presumably by "arvados-server install" --
528 # then we want to use those versions, instead of whatever happens
529 # to be installed in /usr.
530 PATH="/var/lib/arvados/bin:${PATH}"
533 echo "WORKSPACE=$WORKSPACE"
536 if [[ -z "$temp" ]]; then
540 # Set up temporary install dirs (unless existing dirs were supplied)
541 for tmpdir in VENV3DIR GOPATH GEMHOME R_LIBS
543 if [[ -z "${!tmpdir}" ]]; then
544 eval "$tmpdir"="$temp/$tmpdir"
546 if ! [[ -d "${!tmpdir}" ]]; then
547 mkdir "${!tmpdir}" || fatal "can't create ${!tmpdir} (does $temp exist?)"
551 rm -vf "${WORKSPACE}/tmp/*.log"
556 # Make sure our compiled binaries under test override anything
557 # else that might be in the environment.
558 export PATH=$GOPATH/bin:$PATH
560 # Jenkins config requires that glob tmp/*.log match something. Ensure
561 # that happens even if we don't end up running services that set up
563 mkdir -p "${WORKSPACE}/tmp/" || fatal "could not mkdir ${WORKSPACE}/tmp"
564 touch "${WORKSPACE}/tmp/controller.log" || fatal "could not touch ${WORKSPACE}/tmp/controller.log"
566 unset http_proxy https_proxy no_proxy
568 setup_ruby_environment
575 go mod download || fatal "Go deps failed"
576 which goimports >/dev/null || go install golang.org/x/tools/cmd/goimports@latest || fatal "Go setup failed"
577 # parameterized and pytest are direct dependencies of Python tests.
578 # pdoc is needed to build PySDK documentation.
579 pip install parameterized pdoc pytest ||
580 fatal "failed to install test+documentation packages in virtualenv"
588 if [[ "$remain" -gt 1 ]]; then
589 remain=$((${remain}-1))
590 title "(repeating ${remain} more times)"
594 elif [[ "$retry" == 1 ]]; then
595 read -p 'Try again? [Y/n] ' x
596 if [[ "$x" != "y" ]] && [[ "$x" != "" ]]
608 services/workbench2_units | services/workbench2_integration)
609 suite=services/workbench2
615 if [[ -n "${skip[$suite]}" || \
616 -n "${skip[$1]}" || \
617 (${#only[@]} -ne 0 && ${only[$suite]} -eq 0 && ${only[$1]} -eq 0) ]]; then
623 check_arvados_config "$1"
626 | arvados_version.py \
627 | cmd/arvados-package \
632 | lib/cloud/cloudtest \
635 | lib/dispatchcloud/sshexecutor \
636 | lib/dispatchcloud/worker \
638 | services/workbench2_integration \
639 | services/workbench2_units \
641 check_arvados_config "$1"
642 # don't care whether services are running
645 check_arvados_config "$1"
646 if ! start_services; then
647 checkexit 1 "$1 tests"
648 title "test $1 -- failed to start services"
653 retry do_test_once ${@}
657 version=${ARVADOS_VERSION:-$(git log -n1 --format=%H)-dev}
658 echo "-X git.arvados.org/arvados.git/lib/cmd.version=${version} -X main.version=${version} -s -w"
664 if [[ "$2" == pip ]]; then
665 # We need to install the module before testing to ensure all the
666 # dependencies are satisfied. We need to do this before we start
667 # the test header+timer.
668 do_install_once "$1" "$2" || return
675 if [[ "$2" == "go" ]]
677 covername="coverage-$(echo "$1" | sed -e 's/\//_/g')"
678 coverflags=("-covermode=count" "-coverprofile=$WORKSPACE/tmp/.$covername.tmp")
680 if [[ "$1" == "cmd/arvados-package" ]]; then
681 testflags+=("-timeout" "20m")
683 # We do "go install" here to catch compilation errors
684 # before trying "go test". Otherwise, coverage-reporting
685 # mode makes Go show the wrong line numbers when reporting
686 # compilation errors.
687 go install -ldflags "$(go_ldflags)" "$WORKSPACE/$1" && \
688 cd "$WORKSPACE/$1" && \
689 if [[ -n "${testargs[$1]}" ]]
691 # "go test -check.vv giturl" doesn't work, but this
693 go test ${short:+-short} ${testflags[@]} ${testargs[$1]}
695 # The above form gets verbose even when testargs is
696 # empty, so use this form in such cases:
697 go test ${short:+-short} ${testflags[@]} ${coverflags[@]} "git.arvados.org/arvados.git/$1"
700 if [[ -f "$WORKSPACE/tmp/.$covername.tmp" ]]
702 go tool cover -html="$WORKSPACE/tmp/.$covername.tmp" -o "$WORKSPACE/tmp/$covername.html"
703 rm "$WORKSPACE/tmp/.$covername.tmp"
705 [[ $result = 0 ]] && gofmt -e -d *.go
706 elif [[ "$2" == "pip" ]]
711 tries=$((${tries}+1))
712 env -C "$WORKSPACE/$1" python3 -m pytest ${testargs[$1]}
714 # pytest uses exit code 2 to mean "test collection failed."
715 # See discussion in FUSE's IntegrationTest and MountTestBase.
716 if [[ ${tries} < 3 && ${result} == 2 ]]
718 printf '\n*****\n%s tests exited with code 2 -- retrying\n*****\n\n' "$1"
724 elif [[ "$2" != "" ]]
731 checkexit $result "$1 tests"
732 title "test $1 -- `timer`"
736 check_arvados_config() {
737 if [[ "$1" = "env" ]] ; then
740 if [[ -z "$ARVADOS_CONFIG" ]] ; then
742 eval $(python3 sdk/python/tests/run_test_server.py setup_config)
747 if [[ -n ${skip["install_$1"]} || -n "${skip[install]}" || ( -n "${only_install}" && "${only_install}" != "${1}" && "${only_install}" != "${2}" ) ]]; then
750 check_arvados_config "$1"
751 retry do_install_once ${@}
759 if [[ "$2" == "go" ]]
761 go install -ldflags "$(go_ldflags)" "$WORKSPACE/$1"
762 elif [[ "$2" == "pip" ]]
764 # Generate _version.py before installing.
765 python3 "$WORKSPACE/$1/arvados_version.py" >/dev/null &&
766 pip install "$WORKSPACE/$1"
767 elif [[ "$2" != "" ]]
774 checkexit $result "$1 install"
775 title "install $1 -- `timer`"
779 bundle_install_trylocal() {
782 echo "(Running bundle install --local. 'could not find package' messages are OK.)"
783 if ! bundle install --local --no-deployment; then
784 echo "(Running bundle install again, without --local.)"
785 bundle install --no-deployment
792 cd "$WORKSPACE/doc" \
793 && bundle_install_trylocal \
800 with_test_gemset gem_uninstall_if_exists "$gemname" \
801 && cd "$WORKSPACE/$srcpath" \
802 && bundle_install_trylocal \
803 && gem build "$gemname.gemspec" \
804 && with_test_gemset gem install --no-document $(ls -t "$gemname"-*.gem|head -n1)
808 install_gem arvados sdk/ruby
811 install_sdk/ruby-google-api-client() {
812 install_gem arvados-google-api-client sdk/ruby-google-api-client
816 if [[ "$NEED_SDK_R" = true ]]; then
817 cd "$WORKSPACE/sdk/R" \
818 && Rscript --vanilla install_deps.R
823 install_gem arvados-cli sdk/cli
826 install_services/login-sync() {
827 install_gem arvados-google-api-client sdk/ruby-google-api-client
828 install_gem arvados sdk/ruby
829 install_gem arvados-login-sync services/login-sync
832 install_services/api() {
834 check_arvados_config "services/api"
835 cd "$WORKSPACE/services/api" \
836 && RAILS_ENV=test bundle_install_trylocal \
839 rm -f config/environments/test.rb
840 cp config/environments/test.rb.example config/environments/test.rb
842 # Clear out any lingering postgresql connections to the test
843 # database, so that we can drop it. This assumes the current user
844 # is a postgresql superuser.
845 cd "$WORKSPACE/services/api" \
846 && test_database=$("${VENV3DIR}/bin/python3" -c "import yaml; print(yaml.safe_load(open('$ARVADOS_CONFIG','r'))['Clusters']['zzzzz']['PostgreSQL']['Connection']['dbname'])") \
847 && 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
849 mkdir -p "$WORKSPACE/services/api/tmp/pids"
851 cert="$WORKSPACE/services/api/tmp/self-signed"
852 if [[ ! -e "$cert.pem" || "$(date -r "$cert.pem" +%s)" -lt 1512659226 ]]; then
854 dir="$WORKSPACE/services/api/tmp"
856 openssl req -newkey rsa:2048 -nodes -subj '/C=US/ST=State/L=City/CN=localhost' -out "$cert.csr" -keyout "$cert.key" </dev/null
857 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')
863 cd "$WORKSPACE/services/api"
864 export RAILS_ENV=test
865 if bin/rails db:environment:set ; then
869 bin/rake db:fixtures:load
873 declare -a pythonstuff
875 # The ordering of sdk/python, tools/crunchstat-summary, and
876 # sdk/cwl here is significant. See
877 # https://dev.arvados.org/issues/19744#note-26
879 tools/crunchstat-summary
881 services/dockercleaner
883 tools/cluster-activity
887 gostuff=($(cd "$WORKSPACE" && git ls-files | grep '\.go$' | sed -e 's/\/[^\/]*$//' | sort -u))
889 install_services/workbench2() {
890 cd "$WORKSPACE/services/workbench2" \
891 && make yarn-install ARVADOS_DIRECTORY="${WORKSPACE}"
895 local arvados_api_host=pirca.arvadosapi.com && \
896 env -C "$WORKSPACE/doc" \
897 bundle exec rake linkchecker \
898 arvados_api_host="$arvados_api_host" \
899 arvados_workbench_host="https://workbench.$arvados_api_host" \
900 baseurl="file://$WORKSPACE/doc/.site/" \
905 cd "$WORKSPACE" || return 1
906 dirs=$(ls -d */ | egrep -v 'vendor|tmp')
907 [[ -z "$(gofmt -e -d $dirs | tee -a /dev/stderr)" ]]
908 go vet -composites=false ./...
911 test_arvados_version.py() {
914 while read -d "" fn; do
915 if [[ -z "$orig_fn" ]]; then
917 elif ! cmp "$orig_fn" "$fn"; then
918 fail_count=$(( $fail_count + 1 ))
919 printf "FAIL: %s and %s are not identical\n" "$orig_fn" "$fn"
921 done < <(git -C "$WORKSPACE" ls-files -z | grep -z '/arvados_version\.py$')
923 "") return 66 ;; # EX_NOINPUT
924 *) return "$fail_count" ;;
928 test_services/api() {
929 rm -f "$WORKSPACE/services/api/git-commit.version"
930 cd "$WORKSPACE/services/api" \
931 && eval env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec rake test TESTOPTS=\'-v -d\' ${testargs[services/api]}
935 cd "$WORKSPACE/sdk/ruby" \
936 && bundle exec rake test TESTOPTS=-v ${testargs[sdk/ruby]}
939 test_sdk/ruby-google-api-client() {
940 echo "*** note \`test sdk/ruby-google-api-client\` does not actually run any tests, see https://dev.arvados.org/issues/20993 ***"
945 if [[ "$NEED_SDK_R" = true ]]; then
946 env -C "$WORKSPACE/sdk/R" make test
951 cd "$WORKSPACE/sdk/cli" \
952 && mkdir -p /tmp/keep \
953 && KEEP_LOCAL_STORE=/tmp/keep bundle exec rake test TESTOPTS=-v ${testargs[sdk/cli]}
957 cd "$WORKSPACE/sdk/java-v2" && gradle test ${testargs[sdk/java-v2]}
960 test_services/login-sync() {
961 cd "$WORKSPACE/services/login-sync" \
962 && bundle exec rake test TESTOPTS=-v ${testargs[services/login-sync]}
965 test_services/workbench2_units() {
966 cd "$WORKSPACE/services/workbench2" && make unit-tests ARVADOS_DIRECTORY="${WORKSPACE}" WORKSPACE="$(pwd)" ${testargs[services/workbench2]}
969 test_services/workbench2_integration() {
971 FAIL_FAST_ENABLED=false
972 if [[ -n ${interactive} ]]; then
974 FAIL_FAST_ENABLED=true
976 cd "$WORKSPACE/services/workbench2" && make integration-tests ARVADOS_DIRECTORY="${WORKSPACE}" \
978 INTERACTIVE=$INTERACTIVE \
979 CYPRESS_FAIL_FAST_ENABLED=$FAIL_FAST_ENABLED \
980 ${testargs[services/workbench2]}
984 # Install parts needed by test suites
986 # Many other components rely on PySDK's run_test_server.py, which relies on
987 # the SDK itself, so install that first.
988 do_install sdk/python pip
989 # lib/controller integration tests depend on arv-mount to run containers.
990 do_install services/fuse pip
991 # sdk/cwl depends on crunchstat-summary.
992 do_install tools/crunchstat-summary pip
993 do_install cmd/arvados-server go
994 do_install sdk/ruby-google-api-client
997 do_install services/api
998 do_install services/keepproxy go
999 do_install services/keep-web go
1005 do_install sdk/ruby-google-api-client
1009 do_install services/login-sync
1011 if [[ -z ${skip[python3]} ]]; then
1012 for pkg_dir in "${pythonstuff[@]}"
1014 do_install "$pkg_dir" pip
1017 for pkg_dir in "${gostuff[@]}"
1019 do_install "$pkg_dir" go
1021 do_install services/api
1022 do_install services/workbench2
1027 do_test services/api
1029 do_test arvados_version.py
1031 do_test sdk/ruby-google-api-client
1035 do_test services/login-sync
1038 if [[ -z ${skip[python3]} ]]; then
1039 for pkg_dir in "${pythonstuff[@]}"
1041 do_test "$pkg_dir" pip
1044 for pkg_dir in "${gostuff[@]}"
1046 do_test "$pkg_dir" go
1048 do_test services/workbench2_units
1049 do_test services/workbench2_integration
1054 for g in "${gostuff[@]}"
1060 help_interactive() {
1061 echo "== Interactive commands:"
1062 echo "TARGET (short for 'test DIR')"
1064 echo "10 test TARGET (run test 10 times)"
1065 echo "test TARGET -check.vv (pass arguments to test)"
1066 echo "install TARGET"
1067 echo "install env (go/python libs)"
1068 echo "install deps (go/python libs + arvados components needed for integration tests)"
1069 echo "reset (...services used by integration tests)"
1071 echo "== Test targets:"
1072 echo "${!testfuncargs[@]}" | tr ' ' '\n' | sort | column
1077 declare -A testfuncargs=()
1078 for g in "${gostuff[@]}"; do
1079 testfuncargs[$g]="$g go"
1081 for p in "${pythonstuff[@]}"; do
1082 testfuncargs[$p]="$p pip"
1085 testfuncargs["sdk/cli"]="sdk/cli"
1086 testfuncargs["sdk/R"]="sdk/R"
1087 testfuncargs["sdk/java-v2"]="sdk/java-v2"
1089 if [[ -z ${interactive} ]]; then
1098 if [[ "$TERM" = dumb ]]; then
1099 # assume emacs, or something, is offering a history buffer
1100 # and pre-populating the command will only cause trouble
1102 elif [[ ! -e "$GOPATH/bin/arvados-server" ]]; then
1103 nextcmd="install deps"
1111 HISTFILE="$WORKSPACE/tmp/.history"
1114 while read -p 'What next? ' -e -i "$nextcmd" nextcmd; do
1115 history -s "$nextcmd"
1118 if [[ "${nextcmd}" =~ ^[0-9] ]]; then
1119 read count nextcmd <<<"${nextcmd}"
1121 read verb target opts <<<"${nextcmd}"
1122 target="${target%/}"
1123 target="${target/\/:/:}"
1124 # Remove old Python version suffix for backwards compatibility
1125 target="${target%:py3}"
1142 testargs["$target"]="${opts}"
1143 tt="${testfuncargs[${target}]}"
1145 while [ $count -gt 0 ]; do
1156 if [[ ${#successes[@]} -gt 0 || ${#failures[@]} -gt 0 ]]; then