Unset ARVADOS_ variable from the environment before running tests. no issue #
[arvados.git] / jenkins / run-tests.sh
1 #!/bin/bash
2
3 # Install and test Arvados components.
4 #
5 # Exit non-zero if any tests fail.
6 #
7 # Arguments:
8 # --skip FOO   Do not test the FOO component.
9 # --only FOO   Do not test anything except the FOO component.
10 #
11 # Regardless of which components are tested, install all components in
12 # the usual sequence. (Many test suites depend on other components
13 # being installed.)
14 #
15 #
16 # First make sure to remove any ARVADOS_ variables from the calling environment
17 # that could interfer with the tests.
18 unset $(env | cut -d= -f1 | grep \^ARVADOS_)
19
20 COLUMNS=80
21
22 export GOPATH=$(mktemp -d)
23 VENVDIR=$(mktemp -d)
24
25 source /etc/profile.d/rvm.sh
26
27 fatal() {
28     clear_temp
29     echo >&2 "Fatal: $* in ${FUNCNAME[1]} at ${BASH_SOURCE[1]} line ${BASH_LINENO[0]}"
30     exit 1
31 }
32
33 # Sanity check
34 echo "WORKSPACE=$WORKSPACE"
35 [[ -n "$WORKSPACE" ]] || fatal "WORKSPACE not set"
36
37 # Set up temporary install dirs
38 mkdir -p "$GOPATH/src/git.curoverse.com"
39 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git" \
40     || fatal "symlink failed"
41
42 virtualenv --setuptools "$VENVDIR" || fatal "virtualenv $VENVDIR failed"
43 PATH="$VENVDIR/bin:$PATH"
44
45 declare -a failures
46 declare -A skip
47
48 # Always skip CLI tests. They don't know how to use run_test_server.py.
49 skip[cli]=1
50
51 while [[ -n "$1" ]]
52 do
53     arg="$1"; shift
54     case "$arg" in
55         --skip)
56             skipwhat="$1"; shift
57             skip[$skipwhat]=1
58             ;;
59         --only)
60             only="$1"; shift
61             ;;
62         *)
63             echo >&2 "$0: Unrecognized option: '$arg'"
64             exit 1
65             ;;
66     esac
67 done
68
69 checkexit() {
70     if [[ "$?" != "0" ]]; then
71         title "!!!!!! $1 FAILED !!!!!!"
72         failures+=("$1 (`timer`)")
73     else
74         successes+=("$1 (`timer`)")
75     fi
76 }
77
78 timer_reset() {
79     t0=$SECONDS
80 }
81
82 timer() {
83     echo -n "$(($SECONDS - $t0))s"
84 }
85
86 do_test() {
87     if [[ -z "${skip[$1]}" ]] && ( [[ -z "$only" ]] || [[ "$only" == "$1" ]] )
88     then
89         title "Running $1 tests"
90         timer_reset
91         if [[ "$2" == "go" ]]
92         then
93             go test "git.curoverse.com/arvados.git/$1"
94         else
95             "test_$1"
96         fi
97         checkexit "$1 tests"
98         title "End of $1 tests (`timer`)"
99     else
100         title "Skipping $1 tests"
101     fi
102 }
103
104 do_install() {
105     title "Running $1 install"
106     timer_reset
107     if [[ "$2" == "go" ]]
108     then
109         go get -t "git.curoverse.com/arvados.git/$1"
110     else
111         "install_$1"
112     fi
113     checkexit "$1 install"
114     title "End of $1 install (`timer`)"
115 }
116
117 title () {
118     txt="********** $1 **********"
119     printf "\n%*s%s\n\n" $((($COLUMNS-${#txt})/2)) "" "$txt"
120 }
121
122 clear_temp() {
123     for t in "$VENVDIR" "$GOPATH"
124     do
125         if [[ -n "$t" ]]
126         then
127             rm -rf "$t"
128         fi
129     done
130 }
131
132 test_docs() {
133     cd "$WORKSPACE/doc"
134     bundle install --deployment
135     rm -rf .site
136     # Make sure python-epydoc is installed or the next line won't do much good!
137     ARVADOS_API_HOST=qr1hi.arvadosapi.com
138     PYTHONPATH=$WORKSPACE/sdk/python/ bundle exec rake generate baseurl=file://$WORKSPACE/doc/.site/ arvados_workbench_host=workbench.$ARVADOS_API_HOST arvados_api_host=$ARVADOS_API_HOST
139     unset ARVADOS_API_HOST
140 }
141 do_test docs
142
143 test_doclinkchecker() {
144     cd "$WORKSPACE/doc"
145     bundle exec rake linkchecker baseurl=file://$WORKSPACE/doc/.site/
146 }
147 do_test doclinkchecker
148
149 install_apiserver() {
150     cd "$WORKSPACE/services/api"
151     bundle install --deployment
152
153     rm -f config/environments/test.rb
154     cp config/environments/test.rb.example config/environments/test.rb
155
156     cp $HOME/arvados-api-server/database.yml config/ || fatal "database.yml"
157     cp $HOME/arvados-api-server/application.yml config/ || fatal "application.yml"
158
159     # Fill in a random secret_token and blob_signing_key for testing
160     SECRET_TOKEN=`echo 'puts rand(2**512).to_s(36)' |ruby`
161     BLOB_SIGNING_KEY=`echo 'puts rand(2**512).to_s(36)' |ruby`
162
163     sed -i'' -e "s:SECRET_TOKEN:$SECRET_TOKEN:" config/application.yml
164     sed -i'' -e "s:BLOB_SIGNING_KEY:$BLOB_SIGNING_KEY:" config/application.yml
165
166     export RAILS_ENV=test
167
168     # Set up empty git repo (for git tests)
169     GITDIR="$WORKSPACE/tmpgit"
170     sed -i'' -e "s:/var/cache/git:$GITDIR:" config/application.default.yml
171
172     rm -rf $GITDIR
173     mkdir -p $GITDIR/test
174     cd $GITDIR/test \
175         && git init \
176         && git config user.email "jenkins@ci.curoverse.com" \
177         && git config user.name "Jenkins, CI" \
178         && touch tmp \
179         && git add tmp \
180         && git commit -m 'initial commit'
181
182     cd "$WORKSPACE/services/api" \
183         && bundle exec rake db:drop \
184         && bundle exec rake db:create \
185         && bundle exec rake db:setup
186 }
187 do_install apiserver
188
189 test_apiserver() {
190     cd "$WORKSPACE/services/api"
191     bundle exec rake test
192 }
193 do_test apiserver
194
195 install_cli() {
196     cd "$WORKSPACE/sdk/cli"
197     bundle install --deployment
198 }
199 do_install cli
200
201 declare -a gostuff
202 gostuff=(
203     services/keepstore
204     services/keepproxy
205     sdk/go/arvadosclient
206     sdk/go/keepclient
207     sdk/go/streamer
208     )
209 for g in "${gostuff[@]}"
210 do
211     do_install "$g" go
212 done
213
214 install_python_sdk() {
215     # Install the Python SDK early. Various other test suites (like
216     # keepproxy) bring up run_test_server.py, which imports the arvados
217     # module. We can't actually *test* the Python SDK yet though, because
218     # its own test suite brings up some of those other programs (like
219     # keepproxy).
220
221     cd "$WORKSPACE/sdk/python" \
222         && python setup.py egg_info -b ".$(git log --format=format:%ct.%h -n1 .)" sdist rotate --keep=1 --match .tar.gz \
223         && pip install dist/arvados-python-client-0.1.*.tar.gz
224 }
225 do_install python_sdk
226
227 install_fuse() {
228     cd "$WORKSPACE/services/fuse" \
229         && python setup.py egg_info -b ".$(git log --format=format:%ct.%h -n1 .)" sdist rotate --keep=1 --match .tar.gz \
230         && pip install dist/arvados_fuse-0.1.*.tar.gz
231 }
232 do_install fuse
233
234 test_python_sdk() {
235     # Python SDK. We test this before testing keepproxy: keepproxy runs
236     # run_test_server.py, which depends on the yaml package, which is in
237     # tests_require but not install_requires, and therefore does not get
238     # installed by setuptools until we run "setup.py test" *and* install
239     # the .egg files that setup.py downloads.
240
241     cd "$WORKSPACE/sdk/python" \
242         && python setup.py test
243     r=$?
244     easy_install *.egg
245     return $r
246 }
247 do_test python_sdk
248
249 test_fuse() {
250     # Install test dependencies here too, in case run_test_server needs them.
251     cd "$WORKSPACE/services/fuse" \
252         && python setup.py test
253     r=$?
254     easy_install *.egg
255     return $r
256 }
257 do_test fuse
258
259 for g in "${gostuff[@]}"
260 do
261     do_test "$g" go
262 done
263
264 test_workbench() {
265     cd "$WORKSPACE/apps/workbench" \
266         && bundle install --deployment \
267         && bundle exec rake test
268 }
269 do_test workbench
270
271 test_cli() {
272     title "Starting SDK CLI tests"
273     cd "$WORKSPACE/sdk/cli" \
274         && bundle install --deployment \
275         && mkdir -p /tmp/keep \
276         && KEEP_LOCAL_STORE=/tmp/keep bundle exec rake test
277 }
278 do_test cli
279
280 clear_temp
281
282 for x in "${successes[@]}"
283 do
284     echo "Pass: $x"
285 done
286
287 if [[ ${#failures[@]} == 0 ]]
288 then
289     echo "All test suites passed."
290 else
291     echo "Failures (${#failures[@]}):"
292     for x in "${failures[@]}"
293     do
294         echo "Fail: $x"
295     done
296 fi
297 exit ${#failures}