3551: Fix dependency cycle: Install Python SDK, then install+test Go stuff, then...
[arvados.git] / jenkins / run-tests.sh
1 #!/bin/bash
2
3 EXITCODE=0
4
5 COLUMNS=80
6
7 ARVADOS_API_HOST=qr1hi.arvadosapi.com
8
9 title () {
10   printf "\n%*s\n\n" $(((${#title}+$COLUMNS)/2)) "********** $1 **********"
11 }
12
13 source /etc/profile.d/rvm.sh
14 echo $WORKSPACE
15
16 export GOPATH=$(mktemp -d)
17 mkdir -p "$GOPATH/src/git.curoverse.com"
18 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
19
20 VENVDIR=$(mktemp -d)
21 virtualenv --setuptools "$VENVDIR"
22 PATH="$VENVDIR/bin:$PATH"
23
24 # DOCS
25 title "Starting DOC build"
26 cd "$WORKSPACE"
27 cd doc
28 bundle install --deployment
29 rm -rf .site
30 # Make sure python-epydoc is installed or the next line won't do much good!
31 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
32
33 checkexit() {
34     ECODE=$?
35
36     if [[ "$ECODE" != "0" ]]; then
37         title "!!!!!! $1 FAILED !!!!!!"
38         EXITCODE=$(($EXITCODE + $ECODE))
39     fi
40 }
41
42 gotest() {
43     title "Starting $1 tests"
44     cd "$WORKSPACE"
45
46     go get -t "git.curoverse.com/arvados.git/$1" \
47         && go test "git.curoverse.com/arvados.git/$1"
48
49     checkexit "$1 tests"
50     title "$1 tests complete"
51 }
52
53 checkexit "Doc build"
54 title "DOC build complete"
55
56 # DOC linkchecker
57 title "Starting DOC linkchecker"
58 cd "$WORKSPACE"
59 cd doc
60 bundle exec rake linkchecker baseurl=file://$WORKSPACE/doc/.site/
61
62 checkexit "Doc linkchecker"
63 title "DOC linkchecker complete"
64
65 # API SERVER
66 title "Starting API server tests"
67 cd "$WORKSPACE"
68 cd services/api
69 bundle install --deployment
70
71 rm -f config/database.yml
72 rm -f config/environments/test.rb
73 cp config/environments/test.rb.example config/environments/test.rb
74
75 # Get test database config
76 cp $HOME/arvados-api-server/database.yml config/
77 # Get test application.yml file
78 cp $HOME/arvados-api-server/application.yml config/
79
80 # Fill in a random secret_token and blob_signing_key for testing
81 SECRET_TOKEN=`echo 'puts rand(2**512).to_s(36)' |ruby`
82 BLOB_SIGNING_KEY=`echo 'puts rand(2**512).to_s(36)' |ruby`
83
84 sed -i'' -e "s:SECRET_TOKEN:$SECRET_TOKEN:" config/application.yml
85 sed -i'' -e "s:BLOB_SIGNING_KEY:$BLOB_SIGNING_KEY:" config/application.yml
86
87 export RAILS_ENV=test
88
89 # Set up empty git repo (for git tests)
90 GITDIR=$WORKSPACE/tmpgit
91 rm -rf $GITDIR
92 mkdir $GITDIR
93 sed -i'' -e "s:/var/cache/git:$GITDIR:" config/application.default.yml
94
95 rm -rf $GITDIR
96 mkdir -p $GITDIR/test
97 cd $GITDIR/test
98 /usr/bin/git init
99 /usr/bin/git config user.email "jenkins@ci.curoverse.com"
100 /usr/bin/git config user.name "Jenkins, CI"
101 touch tmp
102 /usr/bin/git add tmp
103 /usr/bin/git commit -m 'initial commit'
104
105 cd "$WORKSPACE"
106 cd services/api
107
108 bundle exec rake db:drop
109 bundle exec rake db:create
110 bundle exec rake db:setup
111 bundle exec rake test
112
113 checkexit "API server tests"
114 title "API server tests complete"
115
116 # Install CLI gem's dependencies.
117
118 cd "$WORKSPACE"
119 cd sdk/cli
120 bundle install --deployment
121
122 # Install the Python SDK early. Various other test suites (like
123 # keepproxy) bring up run_test_server.py, which imports the arvados
124 # module. We can't actually *test* the Python SDK yet though, because
125 # its own test suite brings up some of those other programs (like
126 # keepproxy).
127
128 python setup.py egg_info -b ".$(git log --format=format:%ct.%h -n1 .)" sdist rotate --keep=1 --match .tar.gz
129 pip install dist/arvados-python-client-0.1.*.tar.gz
130
131 checkexit "Python SDK install"
132
133 # Keep daemons
134
135 gotest services/keepstore
136
137 gotest services/keepproxy
138
139 # Python SDK (already installed, but we didn't run its tests yet)
140
141 title "Starting Python SDK tests"
142 cd "$WORKSPACE"
143 cd sdk/python
144
145 python setup.py test
146
147 checkexit "Python SDK tests"
148
149 # FUSE driver
150
151 cd "$WORKSPACE"
152 cd services/fuse
153
154 python setup.py test
155
156 checkexit "FUSE tests"
157
158 python setup.py egg_info -b ".$(git log --format=format:%ct.%h -n1 .)" sdist rotate --keep=1 --match .tar.gz
159 pip install dist/arvados_fuse-0.1.*.tar.gz
160
161 checkexit "FUSE install"
162
163 title "Python SDK tests complete"
164
165 # Go SDK packages
166
167 for dir in sdk/go/arvadosclient sdk/go/keepclient sdk/go/streamer
168 do
169   gotest "$dir"
170 done
171
172 # WORKBENCH
173 title "Starting workbench tests"
174 cd "$WORKSPACE"
175 cd apps/workbench
176 bundle install --deployment
177
178 echo $PATH
179
180 bundle exec rake test
181
182 checkexit "Workbench tests"
183 title "Workbench tests complete"
184
185 # Clean up temporary virtualenv and GOPATH
186 rm -rf "$VENVDIR"
187 rm -rf "$GOPATH"
188
189 # The CLI SDK tests require a working API server, so let's skip those for now.
190 exit $EXITCODE
191
192 ########################################################################
193
194 # CLI SDK
195 title "Starting SDK CLI tests"
196 cd "$WORKSPACE"
197 cd sdk/cli
198 bundle install --deployment
199
200 # Set up Python SDK and dependencies
201 cd ../python
202 rm -rf $HOME/lib/python
203 mkdir $HOME/lib/python
204 PYTHONPATH="$HOME/lib/python" easy_install --install-dir=$HOME/lib/python --upgrade google-api-python-client
205 PYTHONPATH="$HOME/lib/python" python setup.py install --home=$HOME
206
207 cd ../cli
208 mkdir -p /tmp/keep
209 export KEEP_LOCAL_STORE=/tmp/keep
210 PYTHONPATH="$HOME/lib/python" bundle exec rake test
211
212 checkexit "SDK CLI tests"
213 title "SDK CLI tests complete"
214
215 exit $EXITCODE