2411: Add copyright notices to everything.
[arvados.git] / build / run-tests.sh
index 4b6c81395f0925ca9a27c226acfaf3d30774d524..00987a8efab0f7bc81da391beb4c661e69db4813 100755 (executable)
@@ -1,6 +1,9 @@
 #!/bin/bash
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
 
-. `dirname "$(readlink -f "$0")"`/libcloud-pin
+. `dirname "$(readlink -f "$0")"`/libcloud-pin.sh
 
 COLUMNS=80
 . `dirname "$(readlink -f "$0")"`/run-library.sh
@@ -78,6 +81,7 @@ services/keepstore
 services/keep-balance
 services/login-sync
 services/nodemanager
+services/nodemanager-integration
 services/crunch-run
 services/crunch-dispatch-local
 services/crunch-dispatch-slurm
@@ -85,9 +89,11 @@ services/ws
 sdk/cli
 sdk/pam
 sdk/python
+sdk/python:py3
 sdk/ruby
 sdk/go/arvados
 sdk/go/arvadosclient
+sdk/go/dispatch
 sdk/go/keepclient
 sdk/go/httpserver
 sdk/go/manifest
@@ -163,23 +169,26 @@ sanity_checks() {
     echo -n 'ruby: '
     ruby -v \
         || fatal "No ruby. Install >=2.1.9 (using rbenv, rvm, or source)"
-    echo -n 'bundler: '
-    bundle version \
-        || fatal "No bundler. Try: gem install bundler"
     echo -n 'go: '
     go version \
         || fatal "No go binary. See http://golang.org/doc/install"
-    [[ $(go version) =~ go1.([0-9]+) ]] && [[ ${BASH_REMATCH[1]} -ge 7 ]] \
-        || fatal "Go >= 1.7 required. See http://golang.org/doc/install"
+    [[ $(go version) =~ go1.([0-9]+) ]] && [[ ${BASH_REMATCH[1]} -ge 8 ]] \
+        || fatal "Go >= 1.8 required. See http://golang.org/doc/install"
     echo -n 'gcc: '
     gcc --version | egrep ^gcc \
         || fatal "No gcc. Try: apt-get install build-essential"
     echo -n 'fuse.h: '
-    find /usr/include -wholename '*fuse/fuse.h' \
+    find /usr/include -path '*fuse/fuse.h' | egrep --max-count=1 . \
         || fatal "No fuse/fuse.h. Try: apt-get install libfuse-dev"
-    echo -n 'pyconfig.h: '
-    find /usr/include -name pyconfig.h | egrep --max-count=1 . \
-        || fatal "No pyconfig.h. Try: apt-get install python-dev"
+    echo -n 'gnutls.h: '
+    find /usr/include -path '*gnutls/gnutls.h' | egrep --max-count=1 . \
+        || fatal "No gnutls/gnutls.h. Try: apt-get install libgnutls28-dev"
+    echo -n 'Python2 pyconfig.h: '
+    find /usr/include -path '*/python2*/pyconfig.h' | egrep --max-count=1 . \
+        || fatal "No Python2 pyconfig.h. Try: apt-get install python2.7-dev"
+    echo -n 'Python3 pyconfig.h: '
+    find /usr/include -path '*/python3*/pyconfig.h' | egrep --max-count=1 . \
+        || fatal "No Python3 pyconfig.h. Try: apt-get install python3-dev"
     echo -n 'nginx: '
     PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin" nginx -v \
         || fatal "No nginx. Try: apt-get install nginx"
@@ -340,13 +349,13 @@ done
 
 setup_ruby_environment() {
     if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
-      source "$HOME/.rvm/scripts/rvm"
-      using_rvm=true
+        source "$HOME/.rvm/scripts/rvm"
+        using_rvm=true
     elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
-      source "/usr/local/rvm/scripts/rvm"
-      using_rvm=true
+        source "/usr/local/rvm/scripts/rvm"
+        using_rvm=true
     else
-      using_rvm=false
+        using_rvm=false
     fi
 
     if [[ "$using_rvm" == true ]]; then
@@ -395,12 +404,14 @@ setup_ruby_environment() {
 
         tmpdir_gem_home="$(env - PATH="$PATH" HOME="$GEMHOME" gem env gempath | cut -f1 -d:)"
         PATH="$tmpdir_gem_home/bin:$PATH"
-        export GEM_PATH="$tmpdir_gem_home:$(gem env gempath)"
+        export GEM_PATH="$tmpdir_gem_home"
 
         echo "Will install dependencies to $(gem env gemdir)"
         echo "Will install arvados gems to $tmpdir_gem_home"
         echo "Gem search path is GEM_PATH=$GEM_PATH"
     fi
+    bundle config || gem install bundler \
+        || fatal 'install bundler'
 }
 
 with_test_gemset() {
@@ -437,8 +448,10 @@ export PERLLIB="$PERLINSTALLBASE/lib/perl5:${PERLLIB:+$PERLLIB}"
 
 export GOPATH
 mkdir -p "$GOPATH/src/git.curoverse.com"
-ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git" \
+ln -sfT "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git" \
     || fatal "symlink failed"
+go get -v github.com/kardianos/govendor \
+    || fatal "govendor install failed"
 
 setup_virtualenv "$VENVDIR" --python python2.7
 . "$VENVDIR/bin/activate"
@@ -463,18 +476,28 @@ fi
 # Deactivate Python 2 virtualenv
 deactivate
 
+declare -a pythonstuff
+pythonstuff=(
+    sdk/pam
+    sdk/python
+    sdk/python:py3
+    sdk/cwl
+    services/dockercleaner:py3
+    services/fuse
+    services/nodemanager
+    tools/crunchstat-summary
+    )
+
 # If Python 3 is available, set up its virtualenv in $VENV3DIR.
 # Otherwise, skip dependent tests.
 PYTHON3=$(which python3)
-if [ "0" = "$?" ]; then
+if [[ ${?} = 0 ]]; then
     setup_virtualenv "$VENV3DIR" --python python3
 else
     PYTHON3=
-    skip[services/dockercleaner]=1
     cat >&2 <<EOF
 
-Warning: python3 could not be found
-services/dockercleaner install and tests will be skipped
+Warning: python3 could not be found. Python 3 tests will be skipped.
 
 EOF
 fi
@@ -518,7 +541,7 @@ retry() {
 
 do_test() {
     case "${1}" in
-        apps/workbench_units | apps/workbench_functional | apps/workbench_integration)
+        apps/workbench_units | apps/workbench_functionals | apps/workbench_integration)
             suite=apps/workbench
             ;;
         *)
@@ -547,14 +570,14 @@ do_test_once() {
         # before trying "go test". Otherwise, coverage-reporting
         # mode makes Go show the wrong line numbers when reporting
         # compilation errors.
-        go get -t "git.curoverse.com/arvados.git/$1" || return 1
-        cd "$WORKSPACE/$1" || return 1
-        gofmt -e -d . | egrep . && result=1
-        if [[ -n "${testargs[$1]}" ]]
+        go get -t "git.curoverse.com/arvados.git/$1" && \
+            cd "$GOPATH/src/git.curoverse.com/arvados.git/$1" && \
+            [[ -z "$(gofmt -e -d . | tee /dev/stderr)" ]] && \
+            if [[ -n "${testargs[$1]}" ]]
         then
             # "go test -check.vv giturl" doesn't work, but this
             # does:
-            cd "$WORKSPACE/$1" && go test ${short:+-short} ${testargs[$1]}
+            go test ${short:+-short} ${testargs[$1]}
         else
             # The above form gets verbose even when testargs is
             # empty, so use this form in such cases:
@@ -697,22 +720,19 @@ do_install services/login-sync login-sync
 # module. We can't actually *test* the Python SDK yet though, because
 # its own test suite brings up some of those other programs (like
 # keepproxy).
-declare -a pythonstuff
-pythonstuff=(
-    sdk/pam
-    sdk/python
-    sdk/cwl
-    services/fuse
-    services/nodemanager
-    tools/crunchstat-summary
-    )
 for p in "${pythonstuff[@]}"
 do
-    do_install "$p" pip
+    dir=${p%:py3}
+    if [[ ${dir} = ${p} ]]; then
+        if [[ -z ${skip[python2]} ]]; then
+            do_install ${dir} pip
+        fi
+    elif [[ -n ${PYTHON3} ]]; then
+        if [[ -z ${skip[python3]} ]]; then
+            do_install ${dir} pip "$VENV3DIR/bin/"
+        fi
+    fi
 done
-if [ -n "$PYTHON3" ]; then
-    do_install services/dockercleaner pip "$VENV3DIR/bin/"
-fi
 
 install_apiserver() {
     cd "$WORKSPACE/services/api" \
@@ -723,33 +743,12 @@ install_apiserver() {
 
     if [ -n "$CONFIGSRC" ]
     then
-        for f in database.yml application.yml
+        for f in database.yml
         do
             cp "$CONFIGSRC/$f" config/ || fatal "$f"
         done
     fi
 
-    # Fill in a random secret_token and blob_signing_key for testing
-    SECRET_TOKEN=`echo 'puts rand(2**512).to_s(36)' |ruby`
-    BLOB_SIGNING_KEY=`echo 'puts rand(2**512).to_s(36)' |ruby`
-
-    sed -i'' -e "s:SECRET_TOKEN:$SECRET_TOKEN:" config/application.yml
-    sed -i'' -e "s:BLOB_SIGNING_KEY:$BLOB_SIGNING_KEY:" config/application.yml
-
-    # Set up empty git repo (for git tests)
-    GITDIR=$(mktemp -d)
-    sed -i'' -e "s:/var/cache/git:$GITDIR:" config/application.default.yml
-
-    rm -rf $GITDIR
-    mkdir -p $GITDIR/test
-    cd $GITDIR/test \
-        && git init \
-        && git config user.email "jenkins@ci.curoverse.com" \
-        && git config user.name "Jenkins, CI" \
-        && touch tmp \
-        && git add tmp \
-        && git commit -m 'initial commit'
-
     # Clear out any lingering postgresql connections to the test
     # database, so that we can drop it. This assumes the current user
     # is a postgresql superuser.
@@ -757,6 +756,8 @@ install_apiserver() {
         && test_database=$(python -c "import yaml; print yaml.load(file('config/database.yml'))['test']['database']") \
         && 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
 
+    mkdir -p "$WORKSPACE/services/api/tmp/pids"
+
     cd "$WORKSPACE/services/api" \
         && RAILS_ENV=test bundle exec rake db:drop \
         && RAILS_ENV=test bundle exec rake db:setup \
@@ -764,11 +765,15 @@ install_apiserver() {
 }
 do_install services/api apiserver
 
+cd "$GOPATH/src/git.curoverse.com/arvados.git" && \
+    "$GOPATH/bin/govendor" sync -v || \
+        fatal "govendor sync failed"
 declare -a gostuff
 gostuff=(
     sdk/go/arvados
     sdk/go/arvadosclient
     sdk/go/blockdigest
+    sdk/go/dispatch
     sdk/go/httpserver
     sdk/go/manifest
     sdk/go/streamer
@@ -789,7 +794,7 @@ gostuff=(
     tools/keep-block-check
     tools/keep-exercise
     tools/keep-rsync
-    )
+)
 for g in "${gostuff[@]}"
 do
     do_install "$g" go
@@ -802,6 +807,8 @@ install_workbench() {
 }
 do_install apps/workbench workbench
 
+unset http_proxy https_proxy no_proxy
+
 test_doclinkchecker() {
     (
         set -e
@@ -830,7 +837,7 @@ if [ ! -z "$only" ] && [ "$only" == "services/api" ]; then
   exit_cleanly
 fi
 
-start_api
+start_api || { stop_services; fatal "start_api"; }
 
 test_ruby_sdk() {
     cd "$WORKSPACE/sdk/ruby" \
@@ -851,11 +858,25 @@ test_login-sync() {
 }
 do_test services/login-sync login-sync
 
+test_nodemanager-integration() {
+    cd "$WORKSPACE/services/nodemanager" \
+        && tests/integration_test.py ${testargs[services/nodemanager-integration]}
+}
+do_test services/nodemanager-integration nodemanager-integration
+
 for p in "${pythonstuff[@]}"
 do
-    do_test "$p" pip
+    dir=${p%:py3}
+    if [[ ${dir} = ${p} ]]; then
+        if [[ -z ${skip[python2]} ]]; then
+            do_test ${dir} pip
+        fi
+    elif [[ -n ${PYTHON3} ]]; then
+        if [[ -z ${skip[python3]} ]]; then
+            do_test ${dir} pip "$VENV3DIR/bin/"
+        fi
+    fi
 done
-do_test services/dockercleaner pip "$VENV3DIR/bin/"
 
 for g in "${gostuff[@]}"
 do