3894: Use gem install --user-install to avoid sudo/rvm requirement
[arvados-dev.git] / jenkins / run-tests.sh
index af2b3e2db8fd99e435b7e18cee9c5dfb9e02a15a..44bb60392d2f015d698453f4568acd0007fd19d5 100755 (executable)
@@ -7,6 +7,8 @@
 # Arguments:
 # --skip FOO     Do not test the FOO component.
 # --only FOO     Do not test anything except the FOO component.
+# WORKSPACE=path Arvados source tree to test.
+# CONFIGSRC=path Dir with api server config files to copy into source tree.
 # envvar=value   Set $envvar to value
 #
 # Regardless of which components are tested, install all components in
@@ -46,8 +48,10 @@ unset $(env | cut -d= -f1 | grep \^ARVADOS_)
 
 COLUMNS=80
 
-export GOPATH=$(mktemp -d)
-VENVDIR=$(mktemp -d)
+GITDIR=
+GOPATH=
+VENVDIR=
+PYTHONPATH=
 cli_test=
 workbench_test=
 apiserver_test=
@@ -62,24 +66,32 @@ then
     source /etc/profile.d/rvm.sh
 fi
 
+declare -A leave_temp
+clear_temp() {
+    leaving=""
+    for var in VENVDIR GOPATH GITDIR
+    do
+        if [[ -z "${leave_temp[$var]}" ]]
+        then
+            if [[ -n "${!var}" ]]
+            then
+                rm -rf "${!var}"
+            fi
+        else
+            leaving+=" $var=\"${!var}\""
+        fi
+    done
+    if [[ -z "$leaving" ]]; then
+        echo "Leaving behind temp dirs: $leaving"
+    fi
+}
+
 fatal() {
     clear_temp
     echo >&2 "Fatal: $* in ${FUNCNAME[1]} at ${BASH_SOURCE[1]} line ${BASH_LINENO[0]}"
     exit 1
 }
 
-# Sanity check
-echo "WORKSPACE=$WORKSPACE"
-[[ -n "$WORKSPACE" ]] || fatal "WORKSPACE not set"
-
-# Set up temporary install dirs
-mkdir -p "$GOPATH/src/git.curoverse.com"
-ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git" \
-    || fatal "symlink failed"
-
-virtualenv --setuptools "$VENVDIR" || fatal "virtualenv $VENVDIR failed"
-PATH="$VENVDIR/bin:$PATH"
-
 declare -a failures
 declare -A skip
 
@@ -101,7 +113,8 @@ do
             skip_install=1
             ;;
         --leave-temp)
-            leave_temp=1
+            leave_temp[VENVDIR]=1
+            leave_temp[GOPATH]=1
             ;;
         *=*)
             eval $(echo $arg | cut -d= -f1)=\"$(echo $arg | cut -d= -f2-)\"
@@ -113,6 +126,36 @@ do
     esac
 done
 
+# Sanity check
+echo "WORKSPACE=$WORKSPACE"
+[[ -n "$WORKSPACE" ]] || fatal "WORKSPACE not set"
+
+if [[ -n "$CONFIGSRC" ]]; then
+    if [[ -d "$HOME/arvados-api-server" ]]; then
+        # Jenkins expects us to use this by default.
+        CONFIGSRC="$HOME/arvados-api-server"
+    fi
+fi
+
+# Set up temporary install dirs (unless existing dirs were supplied)
+if [[ -n "$VENVDIR" ]]; then
+    leave_temp[VENVDIR]=1
+else
+    VENVDIR=$(mktemp -d)
+fi
+if [[ -n "$GOPATH" ]]; then
+    leave_temp[GOPATH]=1
+else
+    GOPATH=$(mktemp -d)
+fi
+export GOPATH
+mkdir -p "$GOPATH/src/git.curoverse.com"
+ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git" \
+    || fatal "symlink failed"
+
+virtualenv --setuptools "$VENVDIR" || fatal "virtualenv $VENVDIR failed"
+PATH="$VENVDIR/bin:$PATH"
+
 checkexit() {
     if [[ "$?" != "0" ]]; then
         title "!!!!!! $1 FAILED !!!!!!"
@@ -137,7 +180,7 @@ do_test() {
         timer_reset
         if [[ "$2" == "go" ]]
         then
-            go test -timeout 20s "git.curoverse.com/arvados.git/$1"
+            go test "git.curoverse.com/arvados.git/$1"
         else
             "test_$1"
         fi
@@ -155,7 +198,6 @@ do_install() {
         timer_reset
         if [[ "$2" == "go" ]]
         then
-            pip install pyyaml
             go get -t "git.curoverse.com/arvados.git/$1"
         else
             "install_$1"
@@ -172,22 +214,6 @@ title () {
     printf "\n%*s%s\n\n" $((($COLUMNS-${#txt})/2)) "" "$txt"
 }
 
-clear_temp() {
-    if [[ -z "$leave_temp" ]]
-    then
-        for t in "$VENVDIR" "$GOPATH"
-        do
-            if [[ -n "$t" ]]
-            then
-                rm -rf "$t"
-            fi
-        done
-    else
-        echo "Leaving VENVDIR=\"$VENVDIR\""
-        echo "Leaving GOPATH=\"$GOPATH\""
-    fi
-}
-
 test_docs() {
     cd "$WORKSPACE/doc"
     bundle install --no-deployment
@@ -215,14 +241,14 @@ do_test ruby_sdk
 install_ruby_sdk() {
     cd "$WORKSPACE/sdk/ruby" \
         && gem build arvados.gemspec \
-        && gem install --no-ri --no-rdoc `ls -t arvados-*.gem|head -n1`
+        && gem install --user-install --no-ri --no-rdoc `ls -t arvados-*.gem|head -n1`
 }
 do_install ruby_sdk
 
 install_cli() {
     cd "$WORKSPACE/sdk/cli" \
         && gem build arvados-cli.gemspec \
-        && gem install --no-ri --no-rdoc `ls -t arvados-cli-*.gem|head -n1`
+        && gem install --user-install --no-ri --no-rdoc `ls -t arvados-cli-*.gem|head -n1`
 }
 do_install cli
 
@@ -242,8 +268,13 @@ install_apiserver() {
     rm -f config/environments/test.rb
     cp config/environments/test.rb.example config/environments/test.rb
 
-    cp $HOME/arvados-api-server/database.yml config/ || fatal "database.yml"
-    cp $HOME/arvados-api-server/application.yml config/ || fatal "application.yml"
+    if [ -n "$CONFIGSRC" ]
+    then
+        for f in database.yml application.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`
@@ -255,7 +286,7 @@ install_apiserver() {
     export RAILS_ENV=test
 
     # Set up empty git repo (for git tests)
-    GITDIR="$WORKSPACE/tmpgit"
+    GITDIR=$(mktemp -d)
     sed -i'' -e "s:/var/cache/git:$GITDIR:" config/application.default.yml
 
     rm -rf $GITDIR