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