7253: add sdk/go/manifest to gostuff
[arvados-dev.git] / jenkins / run-tests.sh
1 #!/bin/bash
2
3 . `dirname "$(readlink -f "$0")"`/libcloud-pin
4
5 read -rd "\000" helpmessage <<EOF
6 $(basename $0): Install and test Arvados components.
7
8 Exit non-zero if any tests fail.
9
10 Syntax:
11         $(basename $0) WORKSPACE=/path/to/arvados [options]
12
13 Options:
14
15 --skip FOO     Do not test the FOO component.
16 --only FOO     Do not test anything except the FOO component.
17 --temp DIR     Install components and dependencies under DIR instead of
18                making a new temporary directory. Implies --leave-temp.
19 --leave-temp   Do not remove GOPATH, virtualenv, and other temp dirs at exit.
20                Instead, show the path to give as --temp to reuse them in
21                subsequent invocations.
22 --skip-install Do not run any install steps. Just run tests.
23                You should provide GOPATH, GEMHOME, and VENVDIR options
24                from a previous invocation if you use this option.
25 --only-install Run specific install step
26 WORKSPACE=path Arvados source tree to test.
27 CONFIGSRC=path Dir with api server config files to copy into source tree.
28                (If none given, leave config files alone in source tree.)
29 services/api_test="TEST=test/functional/arvados/v1/collections_controller_test.rb"
30                Restrict apiserver tests to the given file
31 sdk/python_test="--test-suite test.test_keep_locator"
32                Restrict Python SDK tests to the given class
33 apps/workbench_test="TEST=test/integration/pipeline_instances_test.rb"
34                Restrict Workbench tests to the given file
35 services/arv-git-httpd_test="-check.vv"
36                Show all log messages, even when tests pass (also works
37                with services/keepstore_test etc.)
38 ARVADOS_DEBUG=1
39                Print more debug messages
40 envvar=value   Set \$envvar to value. Primarily useful for WORKSPACE,
41                *_test, and other examples shown above.
42
43 Assuming --skip-install is not given, all components are installed
44 into \$GOPATH, \$VENDIR, and \$GEMHOME before running any tests. Many
45 test suites depend on other components being installed, and installing
46 everything tends to be quicker than debugging dependencies.
47
48 As a special concession to the current CI server config, CONFIGSRC
49 defaults to $HOME/arvados-api-server if that directory exists.
50
51 More information and background:
52
53 https://arvados.org/projects/arvados/wiki/Running_tests
54
55 Available tests:
56
57 apps/workbench
58 apps/workbench_benchmark
59 apps/workbench_profile
60 doc
61 services/api
62 services/arv-git-httpd
63 services/crunchstat
64 services/dockercleaner
65 services/fuse
66 services/keep-web
67 services/keepproxy
68 services/keepstore
69 services/login-sync
70 services/nodemanager
71 sdk/cli
72 sdk/pam
73 sdk/python
74 sdk/ruby
75 sdk/go/arvadosclient
76 sdk/go/keepclient
77 sdk/go/manifest
78 sdk/go/streamer
79 tools/keep-rsync
80
81 EOF
82
83 # First make sure to remove any ARVADOS_ variables from the calling
84 # environment that could interfere with the tests.
85 unset $(env | cut -d= -f1 | grep \^ARVADOS_)
86
87 # Reset other variables that could affect our [tests'] behavior by
88 # accident.
89 GITDIR=
90 GOPATH=
91 VENVDIR=
92 VENV3DIR=
93 PYTHONPATH=
94 GEMHOME=
95 PERLINSTALLBASE=
96
97 COLUMNS=80
98
99 skip_install=
100 temp=
101 temp_preserve=
102
103 clear_temp() {
104     if [[ -z "$temp" ]]; then
105         # we didn't even get as far as making a temp dir
106         :
107     elif [[ -z "$temp_preserve" ]]; then
108         rm -rf "$temp"
109     else
110         echo "Leaving behind temp dirs in $temp"
111     fi
112 }
113
114 fatal() {
115     clear_temp
116     echo >&2 "Fatal: $* (encountered in ${FUNCNAME[1]} at ${BASH_SOURCE[1]} line ${BASH_LINENO[0]})"
117     exit 1
118 }
119
120 report_outcomes() {
121     for x in "${successes[@]}"
122     do
123         echo "Pass: $x"
124     done
125
126     if [[ ${#failures[@]} == 0 ]]
127     then
128         echo "All test suites passed."
129     else
130         echo "Failures (${#failures[@]}):"
131         for x in "${failures[@]}"
132         do
133             echo "Fail: $x"
134         done
135     fi
136 }
137
138 exit_cleanly() {
139     trap - INT
140     create-plot-data-from-log.sh $BUILD_NUMBER "$WORKSPACE/apps/workbench/log/test.log" "$WORKSPACE/apps/workbench/log/"
141     rotate_logfile "$WORKSPACE/apps/workbench/log/" "test.log"
142     stop_services
143     rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
144     report_outcomes
145     clear_temp
146     exit ${#failures}
147 }
148
149 sanity_checks() {
150     ( [[ -n "$WORKSPACE" ]] && [[ -d "$WORKSPACE/services" ]] ) \
151         || fatal "WORKSPACE environment variable not set to a source directory (see: $0 --help)"
152     echo Checking dependencies:
153     echo -n 'virtualenv: '
154     virtualenv --version \
155         || fatal "No virtualenv. Try: apt-get install virtualenv (on ubuntu: python-virtualenv)"
156     echo -n 'go: '
157     go version \
158         || fatal "No go binary. See http://golang.org/doc/install"
159     echo -n 'gcc: '
160     gcc --version | egrep ^gcc \
161         || fatal "No gcc. Try: apt-get install build-essential"
162     echo -n 'fuse.h: '
163     find /usr/include -wholename '*fuse/fuse.h' \
164         || fatal "No fuse/fuse.h. Try: apt-get install libfuse-dev"
165     echo -n 'pyconfig.h: '
166     find /usr/include -name pyconfig.h | egrep --max-count=1 . \
167         || fatal "No pyconfig.h. Try: apt-get install python-dev"
168     echo -n 'nginx: '
169     PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin" nginx -v \
170         || fatal "No nginx. Try: apt-get install nginx"
171     echo -n 'perl: '
172     perl -v | grep version \
173         || fatal "No perl. Try: apt-get install perl"
174     for mod in ExtUtils::MakeMaker JSON LWP Net::SSL; do
175         echo -n "perl $mod: "
176         perl -e "use $mod; print \"\$$mod::VERSION\\n\"" \
177             || fatal "No $mod. Try: apt-get install perl-modules libcrypt-ssleay-perl libjson-perl libwww-perl"
178     done
179     echo -n 'gitolite: '
180     which gitolite \
181         || fatal "No gitolite. Try: apt-get install gitolite3"
182 }
183
184 rotate_logfile() {
185   # i.e.  rotate_logfile "$WORKSPACE/apps/workbench/log/" "test.log"
186   # $BUILD_NUMBER is set by Jenkins if this script is being called as part of a Jenkins run
187   if [[ -f "$1/$2" ]]; then
188     THEDATE=`date +%Y%m%d%H%M%S`
189     mv "$1/$2" "$1/$THEDATE-$BUILD_NUMBER-$2"
190     gzip "$1/$THEDATE-$BUILD_NUMBER-$2"
191   fi
192 }
193
194 declare -a failures
195 declare -A skip
196 declare -A testargs
197 skip[apps/workbench_profile]=1
198
199 while [[ -n "$1" ]]
200 do
201     arg="$1"; shift
202     case "$arg" in
203         --help)
204             echo >&2 "$helpmessage"
205             echo >&2
206             exit 1
207             ;;
208         --skip)
209             skipwhat="$1"; shift
210             skip[$skipwhat]=1
211             ;;
212         --only)
213             only="$1"; skip[$1]=""; shift
214             ;;
215         --skip-install)
216             skip_install=1
217             ;;
218         --only-install)
219             skip_install=1
220             only_install="$1"; shift
221             ;;
222         --temp)
223             temp="$1"; shift
224             temp_preserve=1
225             ;;
226         --leave-temp)
227             temp_preserve=1
228             ;;
229         --retry)
230             retry=1
231             ;;
232         *_test=*)
233             suite="${arg%%_test=*}"
234             args="${arg#*=}"
235             testargs["$suite"]="$args"
236             ;;
237         *=*)
238             eval export $(echo $arg | cut -d= -f1)=\"$(echo $arg | cut -d= -f2-)\"
239             ;;
240         *)
241             echo >&2 "$0: Unrecognized option: '$arg'. Try: $0 --help"
242             exit 1
243             ;;
244     esac
245 done
246
247 start_api() {
248     echo 'Starting API server...'
249     cd "$WORKSPACE" \
250         && eval $(python sdk/python/tests/run_test_server.py start --auth admin) \
251         && export ARVADOS_TEST_API_HOST="$ARVADOS_API_HOST" \
252         && export ARVADOS_TEST_API_INSTALLED="$$" \
253         && (env | egrep ^ARVADOS)
254 }
255
256 start_nginx_proxy_services() {
257     echo 'Starting keepproxy, keep-web, arv-git-httpd, and nginx ssl proxy...'
258     cd "$WORKSPACE" \
259         && python sdk/python/tests/run_test_server.py start_keep_proxy \
260         && python sdk/python/tests/run_test_server.py start_keep-web \
261         && python sdk/python/tests/run_test_server.py start_arv-git-httpd \
262         && python sdk/python/tests/run_test_server.py start_nginx \
263         && export ARVADOS_TEST_PROXY_SERVICES=1
264 }
265
266 stop_services() {
267     if [[ -n "$ARVADOS_TEST_PROXY_SERVICES" ]]; then
268         unset ARVADOS_TEST_PROXY_SERVICES
269         cd "$WORKSPACE" \
270             && python sdk/python/tests/run_test_server.py stop_nginx \
271             && python sdk/python/tests/run_test_server.py stop_arv-git-httpd \
272             && python sdk/python/tests/run_test_server.py stop_keep-web \
273             && python sdk/python/tests/run_test_server.py stop_keep_proxy
274     fi
275     if [[ -n "$ARVADOS_TEST_API_HOST" ]]; then
276         unset ARVADOS_TEST_API_HOST
277         cd "$WORKSPACE" \
278             && python sdk/python/tests/run_test_server.py stop
279     fi
280 }
281
282 interrupt() {
283     failures+=("($(basename $0) interrupted)")
284     exit_cleanly
285 }
286 trap interrupt INT
287
288 sanity_checks
289
290 echo "WORKSPACE=$WORKSPACE"
291
292 if [[ -z "$CONFIGSRC" ]] && [[ -d "$HOME/arvados-api-server" ]]; then
293     # Jenkins expects us to use this by default.
294     CONFIGSRC="$HOME/arvados-api-server"
295 fi
296
297 # Clean up .pyc files that may exist in the workspace
298 cd "$WORKSPACE"
299 find -name '*.pyc' -delete
300
301 if [[ -z "$temp" ]]; then
302     temp="$(mktemp -d)"
303 fi
304
305 # Set up temporary install dirs (unless existing dirs were supplied)
306 for tmpdir in VENVDIR VENV3DIR GOPATH GEMHOME PERLINSTALLBASE
307 do
308     if [[ -z "${!tmpdir}" ]]; then
309         eval "$tmpdir"="$temp/$tmpdir"
310     fi
311     if ! [[ -d "${!tmpdir}" ]]; then
312         mkdir "${!tmpdir}" || fatal "can't create ${!tmpdir} (does $temp exist?)"
313     fi
314 done
315
316 setup_ruby_environment() {
317     if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
318       source "$HOME/.rvm/scripts/rvm"
319       using_rvm=true
320     elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
321       source "/usr/local/rvm/scripts/rvm"
322       using_rvm=true
323     else
324       using_rvm=false
325     fi
326
327     if [[ "$using_rvm" == true ]]; then
328         # If rvm is in use, we can't just put separate "dependencies"
329         # and "gems-under-test" paths to GEM_PATH: passenger resets
330         # the environment to the "current gemset", which would lose
331         # our GEM_PATH and prevent our test suites from running ruby
332         # programs (for example, the Workbench test suite could not
333         # boot an API server or run arv). Instead, we have to make an
334         # rvm gemset and use it for everything.
335
336         [[ `type rvm | head -n1` == "rvm is a function" ]] \
337             || fatal 'rvm check'
338
339         # Put rvm's favorite path back in first place (overriding
340         # virtualenv, which just put itself there). Ignore rvm's
341         # complaint about not being in first place already.
342         rvm use @default 2>/dev/null
343
344         # Create (if needed) and switch to an @arvados-tests
345         # gemset. (Leave the choice of ruby to the caller.)
346         rvm use @arvados-tests --create \
347             || fatal 'rvm gemset setup'
348
349         rvm env
350     else
351         # When our "bundle install"s need to install new gems to
352         # satisfy dependencies, we want them to go where "gem install
353         # --user-install" would put them. (However, if the caller has
354         # already set GEM_HOME, we assume that's where dependencies
355         # should be installed, and we should leave it alone.)
356
357         if [ -z "$GEM_HOME" ]; then
358             user_gempath="$(gem env gempath)"
359             export GEM_HOME="${user_gempath%%:*}"
360         fi
361         PATH="$(gem env gemdir)/bin:$PATH"
362
363         # When we build and install our own gems, we install them in our
364         # $GEMHOME tmpdir, and we want them to be at the front of GEM_PATH and
365         # PATH so integration tests prefer them over other versions that
366         # happen to be installed in $user_gempath, system dirs, etc.
367
368         tmpdir_gem_home="$(env - PATH="$PATH" HOME="$GEMHOME" gem env gempath | cut -f1 -d:)"
369         PATH="$tmpdir_gem_home/bin:$PATH"
370         export GEM_PATH="$tmpdir_gem_home:$(gem env gempath)"
371
372         echo "Will install dependencies to $(gem env gemdir)"
373         echo "Will install arvados gems to $tmpdir_gem_home"
374         echo "Gem search path is GEM_PATH=$GEM_PATH"
375     fi
376 }
377
378 with_test_gemset() {
379     if [[ "$using_rvm" == true ]]; then
380         "$@"
381     else
382         GEM_HOME="$tmpdir_gem_home" GEM_PATH="$tmpdir_gem_home" "$@"
383     fi
384 }
385
386 gem_uninstall_if_exists() {
387     if gem list "$1\$" | egrep '^\w'; then
388         gem uninstall --force --all --executables "$1"
389     fi
390 }
391
392 setup_virtualenv() {
393     local venvdest=$1; shift
394     if ! [[ -e "$venvdest/bin/activate" ]] || ! [[ -e "$venvdest/bin/pip" ]]; then
395         virtualenv --setuptools "$@" "$venvdest" || fatal "virtualenv $venvdest failed"
396     fi
397     "$venvdest/bin/pip" install 'setuptools>=18' 'pip>=7'
398     # ubuntu1404 can't seem to install mock via tests_require, but it can do this.
399     "$venvdest/bin/pip" install 'mock>=1.0'
400 }
401
402 export PERLINSTALLBASE
403 export PERLLIB="$PERLINSTALLBASE/lib/perl5:${PERLLIB:+$PERLLIB}"
404
405 export GOPATH
406 mkdir -p "$GOPATH/src/git.curoverse.com"
407 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git" \
408     || fatal "symlink failed"
409
410 setup_virtualenv "$VENVDIR" --python python2.7
411 . "$VENVDIR/bin/activate"
412
413 # Needed for run_test_server.py which is used by certain (non-Python) tests.
414 pip freeze 2>/dev/null | egrep ^PyYAML= \
415     || pip install PyYAML >/dev/null \
416     || fatal "pip install PyYAML failed"
417
418 # Preinstall forked version of libcloud, because nodemanager "pip install"
419 # won't pick it up by default.
420 pip freeze 2>/dev/null | egrep ^apache-libcloud==$LIBCLOUD_PIN \
421     || pip install --pre --ignore-installed https://github.com/curoverse/libcloud/archive/apache-libcloud-$LIBCLOUD_PIN.zip >/dev/null \
422     || fatal "pip install apache-libcloud failed"
423
424 # Deactivate Python 2 virtualenv
425 deactivate
426
427 # If Python 3 is available, set up its virtualenv in $VENV3DIR.
428 # Otherwise, skip dependent tests.
429 PYTHON3=$(which python3)
430 if [ "0" = "$?" ]; then
431     setup_virtualenv "$VENV3DIR" --python python3
432 else
433     PYTHON3=
434     skip[services/dockercleaner]=1
435     cat >&2 <<EOF
436
437 Warning: python3 could not be found
438 services/dockercleaner install and tests will be skipped
439
440 EOF
441 fi
442
443 # Reactivate Python 2 virtualenv
444 . "$VENVDIR/bin/activate"
445
446 # Note: this must be the last time we change PATH, otherwise rvm will
447 # whine a lot.
448 setup_ruby_environment
449
450 echo "PATH is $PATH"
451
452 if ! which bundler >/dev/null
453 then
454     gem install --user-install bundler || fatal 'Could not install bundler'
455 fi
456
457 checkexit() {
458     if [[ "$1" != "0" ]]; then
459         title "!!!!!! $2 FAILED !!!!!!"
460         failures+=("$2 (`timer`)")
461     else
462         successes+=("$2 (`timer`)")
463     fi
464 }
465
466 timer_reset() {
467     t0=$SECONDS
468 }
469
470 timer() {
471     echo -n "$(($SECONDS - $t0))s"
472 }
473
474 do_test() {
475     while ! do_test_once ${@} && [[ "$retry" == 1 ]]
476     do
477         read -p 'Try again? [Y/n] ' x
478         if [[ "$x" != "y" ]] && [[ "$x" != "" ]]
479         then
480             break
481         fi
482     done
483 }
484
485 do_test_once() {
486     unset result
487     if [[ -z "${skip[$1]}" ]] && ( [[ -z "$only" ]] || [[ "$only" == "$1" ]] )
488     then
489         title "Running $1 tests"
490         timer_reset
491         if [[ "$2" == "go" ]]
492         then
493             covername="coverage-$(echo "$1" | sed -e 's/\//_/g')"
494             coverflags=("-covermode=count" "-coverprofile=$WORKSPACE/tmp/.$covername.tmp")
495             # We do "go get -t" here to catch compilation errors
496             # before trying "go test". Otherwise, coverage-reporting
497             # mode makes Go show the wrong line numbers when reporting
498             # compilation errors.
499             if [[ -n "${testargs[$1]}" ]]
500             then
501                 # "go test -check.vv giturl" doesn't work, but this
502                 # does:
503                 cd "$WORKSPACE/$1" && \
504                     go get -t "git.curoverse.com/arvados.git/$1" && \
505                     go test ${coverflags[@]} ${testargs[$1]}
506             else
507                 # The above form gets verbose even when testargs is
508                 # empty, so use this form in such cases:
509                 go get -t "git.curoverse.com/arvados.git/$1" && \
510                     go test ${coverflags[@]} "git.curoverse.com/arvados.git/$1"
511             fi
512             result="$?"
513             go tool cover -html="$WORKSPACE/tmp/.$covername.tmp" -o "$WORKSPACE/tmp/$covername.html"
514             rm "$WORKSPACE/tmp/.$covername.tmp"
515         elif [[ "$2" == "pip" ]]
516         then
517             # $3 can name a path directory for us to use, including trailing
518             # slash; e.g., the bin/ subdirectory of a virtualenv.
519             cd "$WORKSPACE/$1" \
520                 && "${3}python" setup.py test ${testargs[$1]}
521         elif [[ "$2" != "" ]]
522         then
523             "test_$2"
524         else
525             "test_$1"
526         fi
527         result=${result:-$?}
528         checkexit $result "$1 tests"
529         title "End of $1 tests (`timer`)"
530         return $result
531     else
532         title "Skipping $1 tests"
533     fi
534 }
535
536 do_install() {
537     if [[ -z "$skip_install" || (-n "$only_install" && "$only_install" == "$1") ]]
538     then
539         title "Running $1 install"
540         timer_reset
541         if [[ "$2" == "go" ]]
542         then
543             go get -t "git.curoverse.com/arvados.git/$1"
544         elif [[ "$2" == "pip" ]]
545         then
546             # $3 can name a path directory for us to use, including trailing
547             # slash; e.g., the bin/ subdirectory of a virtualenv.
548
549             # Need to change to a different directory after creating
550             # the source dist package to avoid a pip bug.
551             # see https://arvados.org/issues/5766 for details.
552
553             # Also need to install twice, because if it believes the package is
554             # already installed, pip it won't install it.  So the first "pip
555             # install" ensures that the dependencies are met, the second "pip
556             # install" ensures that we've actually installed the local package
557             # we just built.
558             cd "$WORKSPACE/$1" \
559                 && "${3}python" setup.py sdist rotate --keep=1 --match .tar.gz \
560                 && cd "$WORKSPACE" \
561                 && "${3}pip" install --quiet "$WORKSPACE/$1/dist"/*.tar.gz \
562                 && "${3}pip" install --quiet --no-deps --ignore-installed "$WORKSPACE/$1/dist"/*.tar.gz
563         elif [[ "$2" != "" ]]
564         then
565             "install_$2"
566         else
567             "install_$1"
568         fi
569         checkexit $? "$1 install"
570         title "End of $1 install (`timer`)"
571     else
572         title "Skipping $1 install"
573     fi
574 }
575
576 title () {
577     txt="********** $1 **********"
578     printf "\n%*s%s\n\n" $((($COLUMNS-${#txt})/2)) "" "$txt"
579 }
580
581 bundle_install_trylocal() {
582     (
583         set -e
584         echo "(Running bundle install --local. 'could not find package' messages are OK.)"
585         if ! bundle install --local --no-deployment; then
586             echo "(Running bundle install again, without --local.)"
587             bundle install --no-deployment
588         fi
589         bundle package --all
590     )
591 }
592
593 install_doc() {
594     cd "$WORKSPACE/doc" \
595         && bundle_install_trylocal \
596         && rm -rf .site
597 }
598 do_install doc
599
600 install_gem() {
601     gemname=$1
602     srcpath=$2
603     with_test_gemset gem_uninstall_if_exists "$gemname" \
604         && cd "$WORKSPACE/$srcpath" \
605         && bundle_install_trylocal \
606         && gem build "$gemname.gemspec" \
607         && with_test_gemset gem install --no-ri --no-rdoc $(ls -t "$gemname"-*.gem|head -n1)
608 }
609
610 install_ruby_sdk() {
611     install_gem arvados sdk/ruby
612 }
613 do_install sdk/ruby ruby_sdk
614
615 install_perl_sdk() {
616     cd "$WORKSPACE/sdk/perl" \
617         && perl Makefile.PL INSTALL_BASE="$PERLINSTALLBASE" \
618         && make install INSTALLDIRS=perl
619 }
620 do_install sdk/perl perl_sdk
621
622 install_cli() {
623     install_gem arvados-cli sdk/cli
624 }
625 do_install sdk/cli cli
626
627 install_login-sync() {
628     install_gem arvados-login-sync services/login-sync
629 }
630 do_install services/login-sync login-sync
631
632 # Install the Python SDK early. Various other test suites (like
633 # keepproxy) bring up run_test_server.py, which imports the arvados
634 # module. We can't actually *test* the Python SDK yet though, because
635 # its own test suite brings up some of those other programs (like
636 # keepproxy).
637 declare -a pythonstuff
638 pythonstuff=(
639     sdk/pam
640     sdk/python
641     services/fuse
642     services/nodemanager
643     )
644 for p in "${pythonstuff[@]}"
645 do
646     do_install "$p" pip
647 done
648 if [ -n "$PYTHON3" ]; then
649     do_install services/dockercleaner pip "$VENV3DIR/bin/"
650 fi
651
652 install_apiserver() {
653     cd "$WORKSPACE/services/api" \
654         && RAILS_ENV=test bundle_install_trylocal
655
656     rm -f config/environments/test.rb
657     cp config/environments/test.rb.example config/environments/test.rb
658
659     if [ -n "$CONFIGSRC" ]
660     then
661         for f in database.yml application.yml
662         do
663             cp "$CONFIGSRC/$f" config/ || fatal "$f"
664         done
665     fi
666
667     # Fill in a random secret_token and blob_signing_key for testing
668     SECRET_TOKEN=`echo 'puts rand(2**512).to_s(36)' |ruby`
669     BLOB_SIGNING_KEY=`echo 'puts rand(2**512).to_s(36)' |ruby`
670
671     sed -i'' -e "s:SECRET_TOKEN:$SECRET_TOKEN:" config/application.yml
672     sed -i'' -e "s:BLOB_SIGNING_KEY:$BLOB_SIGNING_KEY:" config/application.yml
673
674     # Set up empty git repo (for git tests)
675     GITDIR=$(mktemp -d)
676     sed -i'' -e "s:/var/cache/git:$GITDIR:" config/application.default.yml
677
678     rm -rf $GITDIR
679     mkdir -p $GITDIR/test
680     cd $GITDIR/test \
681         && git init \
682         && git config user.email "jenkins@ci.curoverse.com" \
683         && git config user.name "Jenkins, CI" \
684         && touch tmp \
685         && git add tmp \
686         && git commit -m 'initial commit'
687
688     # Clear out any lingering postgresql connections to the test
689     # database, so that we can drop it. This assumes the current user
690     # is a postgresql superuser.
691     cd "$WORKSPACE/services/api" \
692         && test_database=$(python -c "import yaml; print yaml.load(file('config/database.yml'))['test']['database']") \
693         && psql "$test_database" -c "SELECT pg_terminate_backend (pg_stat_activity.procpid::int) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$test_database';" 2>/dev/null
694
695     cd "$WORKSPACE/services/api" \
696         && RAILS_ENV=test bundle exec rake db:drop \
697         && RAILS_ENV=test bundle exec rake db:setup \
698         && RAILS_ENV=test bundle exec rake db:fixtures:load
699 }
700 do_install services/api apiserver
701
702 declare -a gostuff
703 gostuff=(
704     sdk/go/arvadosclient
705     sdk/go/manifest
706     sdk/go/streamer
707     services/arv-git-httpd
708     services/crunchstat
709     services/keep-web
710     services/keepstore
711     sdk/go/keepclient
712     services/keepproxy
713     services/datamanager/summary
714     services/datamanager/collection
715     services/datamanager/keep
716     services/datamanager
717     tools/keep-rsync
718     )
719 for g in "${gostuff[@]}"
720 do
721     do_install "$g" go
722 done
723
724 install_workbench() {
725     cd "$WORKSPACE/apps/workbench" \
726         && mkdir -p tmp/cache \
727         && RAILS_ENV=test bundle_install_trylocal
728 }
729 do_install apps/workbench workbench
730
731 test_doclinkchecker() {
732     (
733         set -e
734         cd "$WORKSPACE/doc"
735         ARVADOS_API_HOST=qr1hi.arvadosapi.com
736         # Make sure python-epydoc is installed or the next line won't
737         # do much good!
738         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
739     )
740 }
741 do_test doc doclinkchecker
742
743 stop_services
744
745 test_apiserver() {
746     cd "$WORKSPACE/services/api" \
747         && RAILS_ENV=test bundle exec rake test TESTOPTS=-v ${testargs[services/api]}
748 }
749 do_test services/api apiserver
750
751 # Shortcut for when we're only running apiserver tests. This saves a bit of time,
752 # because we don't need to start up the api server for subsequent tests.
753 if [ ! -z "$only" ] && [ "$only" == "services/api" ]; then
754   rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
755   exit_cleanly
756 fi
757
758 start_api
759
760 test_ruby_sdk() {
761     cd "$WORKSPACE/sdk/ruby" \
762         && bundle exec rake test TESTOPTS=-v ${testargs[sdk/ruby]}
763 }
764 do_test sdk/ruby ruby_sdk
765
766 test_cli() {
767     cd "$WORKSPACE/sdk/cli" \
768         && mkdir -p /tmp/keep \
769         && KEEP_LOCAL_STORE=/tmp/keep bundle exec rake test TESTOPTS=-v ${testargs[sdk/cli]}
770 }
771 do_test sdk/cli cli
772
773 test_login-sync() {
774     cd "$WORKSPACE/services/login-sync" \
775         && bundle exec rake test TESTOPTS=-v ${testargs[services/login-sync]}
776 }
777 do_test services/login-sync login-sync
778
779 for p in "${pythonstuff[@]}"
780 do
781     do_test "$p" pip
782 done
783 do_test services/dockercleaner pip "$VENV3DIR/bin/"
784
785 for g in "${gostuff[@]}"
786 do
787     do_test "$g" go
788 done
789
790 test_workbench() {
791     start_nginx_proxy_services \
792         && cd "$WORKSPACE/apps/workbench" \
793         && RAILS_ENV=test bundle exec rake test TESTOPTS=-v ${testargs[apps/workbench]}
794 }
795 do_test apps/workbench workbench
796
797 test_workbench_benchmark() {
798     start_nginx_proxy_services \
799         && cd "$WORKSPACE/apps/workbench" \
800         && RAILS_ENV=test bundle exec rake test:benchmark ${testargs[apps/workbench_benchmark]}
801 }
802 do_test apps/workbench_benchmark workbench_benchmark
803
804 test_workbench_profile() {
805     start_nginx_proxy_services \
806         && cd "$WORKSPACE/apps/workbench" \
807         && RAILS_ENV=test bundle exec rake test:profile ${testargs[apps/workbench_profile]}
808 }
809 do_test apps/workbench_profile workbench_profile
810
811 exit_cleanly