Bump version
[plcapi.git] / peers-test.mk
1 ### -*-Makefile-*-
2 CHROOT=/plc/root
3 PORT=5432
4 SITEDIR=/etc/planetlab/configs
5 SITE=site.xml
6 RPM=$(shell ls -rt /root/myplc*rpm | tail -1)
7 APIDIR=/usr/share/plc_api
8
9 PLC1=planetlab-devbox.inria.fr
10 PLC2=lurch.cs.princeton.edu
11 PLC1SSH=root@$(PLC1)
12 PLC2SSH=root@$(PLC2)
13
14 PY=python -u
15
16 all:help
17
18 ####################
19 PUSH=pclean pplc1 papi1 pplc2 papi2
20 #EXTRA-PUSHS= ./Shell.py ./TestPeers.py ./planetlab4.sql ./dummy-config ./peers-test.mk ./person-password.sh
21 EXTRA-PUSHS=  ./TestPeers.py ./planetlab4.sql ./peers-test.mk ./person-password.sh ./plcsh
22
23 push:$(PUSH)
24
25 papi: pclean papi1 papi2
26 pplc: pclean pplc1 pplc2
27
28 pclean:
29         -find . '(' -name '*.pyc' -o -name '*~' ')' | xargs rm
30 papi1:
31         rsync -a -v -C ./ root@$(PLC1):new_plc_api/
32 pplc1:
33         rsync -a -v -C $(EXTRA-PUSHS) ./PLC root@$(PLC1):$(CHROOT)$(APIDIR)/
34 papi2:
35         rsync -a -v -C ./ root@$(PLC2):new_plc_api/
36 pplc2:
37         rsync -a -v -C $(EXTRA-PUSHS) ./PLC root@$(PLC2):$(CHROOT)$(APIDIR)/
38
39 ####################
40 DB=install-schema stop-clients db-drop restart-full-db
41 DBRESTORE= stop-clients db-drop restart-db db-restore restart-http
42 WEB=install-api restart
43
44 db: $(DB)
45         @date
46
47 dbrestore: $(DBRESTORE)
48         @echo Restored $(DBDUMPFILE) on $(shell hostname) at $(shell date)
49
50 DBDUMPFILE=planetlab4.dump
51
52 db-dump:
53         chroot $(CHROOT) pg_dump -c -U pgsqluser planetlab4 > $(DBDUMPFILE)
54
55 web: $(WEB)
56
57 install-schema:
58         @echo 'installing schema'
59         @rsync -a -v planetlab4.sql $(CHROOT)$(APIDIR)/planetlab4.sql
60
61 install-api:
62         find . -name '*.py' | xargs tar cf - | ( cd $(CHROOT)$(APIDIR) ; tar xf -)
63         -find $(CHROOT)$(APIDIR) -name '*pyc' | xargs rm
64
65 stop-clients:
66         @echo 'pkilling psql'
67         @-pkill psql
68         @echo 'pkilling Shell.py'
69         @-pkill Shell.py
70         @echo stopping httpd
71         service plc stop httpd
72
73 db-drop:
74         echo 'dropping db'
75         chroot $(CHROOT) psql -U postgres --port $(PORT) template1 -c 'drop database planetlab4'
76
77 db-restore: 
78         echo Restoring $(DBDUMPFILE)
79         rm -f $(DBDUMPFILE).rest-log  $(DBDUMPFILE).rest-err
80         chroot $(CHROOT) psql -U postgres --port $(PORT) -d planetlab4 < $(DBDUMPFILE) > $(DBDUMPFILE).rest-log 2> $(DBDUMPFILE).rest-err
81         ls -l $(DBDUMPFILE).rest-log  $(DBDUMPFILE).rest-err
82
83 restart-db:
84         @echo 'restarting db only'
85         service plc stop postgresql
86         service plc start postgresql
87
88 restart-full-db:
89         @echo 'restarting full db'
90         service plc stop db postgresql httpd
91         service plc start httpd postgresql db
92
93 restart:
94         @echo 'Restarting PLC'
95         @chroot $(CHROOT) service plc restart
96
97 restart-http:
98         @echo 'Restarting httpd'
99         service plc stop httpd
100         service plc start httpd
101
102 ####################
103 PEERS= peer-gpg peer-push-gpg peer-push-cacert
104
105 peers: $(PEERS)
106 peer-gpg: peer-gpg-1 peer-gpg-2
107 peer-gpg-1:
108         ssh $(PLC1SSH) "gpg --homedir=/etc/planetlab --export --armor > /etc/planetlab/gpg_plc1.pub"
109 peer-gpg-2:
110         ssh $(PLC2SSH) "gpg --homedir=/etc/planetlab --export --armor > /etc/planetlab/gpg_plc2.pub"
111
112 # directly scp'ing from one url to the other does not work, looks like
113 # first host tries to connect the second one
114 peer-push-gpg: peer-push-gpg-1 peer-push-gpg-2
115 peer-push-gpg-1:
116         scp $(PLC1SSH):/etc/planetlab/gpg_plc1.pub ./
117         scp ./gpg_plc1.pub $(PLC2SSH):/etc/planetlab/
118 peer-push-gpg-2:
119         scp $(PLC2SSH):/etc/planetlab/gpg_plc2.pub ./
120         scp ./gpg_plc2.pub $(PLC1SSH):/etc/planetlab/
121
122 peer-push-cacert: peer-push-cacert-1 peer-push-cacert-2
123 peer-push-cacert-1:
124         scp $(PLC1SSH):/etc/planetlab/api_ca_ssl.crt ./api_plc1.crt
125         scp ./api_plc1.crt $(PLC2SSH):/etc/planetlab/
126         scp ./api_plc1.crt $(PLC1SSH):/etc/planetlab/
127 peer-push-cacert-2:
128         scp $(PLC2SSH):/etc/planetlab/api_ca_ssl.crt ./api_plc2.crt
129         scp ./api_plc2.crt $(PLC1SSH):/etc/planetlab/
130         scp ./api_plc2.crt $(PLC2SSH):/etc/planetlab/
131
132 HELP += peers-clean
133 peers-clean: peers-clean-1 peers-clean-2
134 peers-clean-1:
135         ssh $(PLC1SSH) "rm -f /etc/planetlab/*plc[12]*"
136 peers-clean-2:
137         ssh $(PLC1SSH) "rm -f /etc/planetlab/*plc[12]*"
138
139 ####################
140 UPGRADE=stop-clients down clean-plc up reconfig restart
141
142 upgrade: $(UPGRADE)
143
144 rpm:
145         @echo latest rpm is $(RPM)
146
147 down:
148         cp $(SITEDIR)/$(SITE) .
149         rpm -e myplc
150 clean-plc:
151         rm -rf /plc
152 up:
153         rpm -i $(RPM)
154
155 reconfig:
156         service plc mount
157         mkdir -p $(SITEDIR)
158         cp $(SITE) $(SITEDIR)
159         (echo w; echo q) | chroot $(CHROOT) plc-config-tty
160
161 ####################
162 RUN=api sql log
163 api:
164         chroot $(CHROOT) /usr/bin/plcsh
165
166 sql:
167         chroot $(CHROOT) psql -U pgsqluser planetlab4
168
169 log:
170         emacs /plc/data/var/log/httpd/error_log /plc/data/var/log/boot.log
171
172 ####################
173 # remove time/delay dependent output
174 normalize       = egrep -v "'expires':|^+++.*ellapsed"
175
176 TEST=run diff ckp
177 run: run-en 
178 diff: diff-en
179 ckp: ckp-en
180
181 %.nout: %.out
182         $(normalize) $*.out > $@
183 %.nref: %.ref
184         $(normalize) $*.ref > $@
185
186 # variant runs
187 VARIANT-TESTS :=
188
189 # run end of test (after it was populated) with mini size
190 VARIANT-TESTS += run-em
191 run-em:
192         $(PY) ./TestPeers.py -e -m > testpeers-em.out 2>&1
193 VARIANT-TESTS += run-en
194 run-en:
195         $(PY) ./TestPeers.py -e > testpeers-en.out 2>&1
196 # big size
197 VARIANT-TESTS += run-eb
198 run-eb:
199         $(PY) ./TestPeers.py -e -b > testpeers-eb.out 2>&1
200 # huge size
201 VARIANT-TESTS += run-eh
202 run-eh:
203         $(PY) ./TestPeers.py -e -H > testpeers-eh.out 2>&1
204
205 # normal size - performs diff and checkpoint (adopt result)
206 VARIANT-TESTS += diff-en
207 diff-en: testpeers-en.nref testpeers-en.nout 
208         diff testpeers-en.nref testpeers-en.nout
209 VARIANT-TESTS += ckp-en
210 ckp-en:
211         cp testpeers-en.out testpeers-en.ref
212         rm -f testpeers-en.n???
213
214 VARIANT-TESTS += diff-eb
215 diff-eb: testpeers-eb.nref testpeers-eb.nout 
216         diff testpeers-eb.nref testpeers-eb.nout
217 VARIANT-TESTS += ckp-eb
218 ckp-eb:
219         cp testpeers-eb.out testpeers-eb.ref
220         rm -f testpeers-eb.n???
221
222 VARIANT-TESTS += diff-eh
223 diff-eh: testpeers-eh.nref testpeers-eh.nout 
224         diff testpeers-eh.nref testpeers-eh.nout
225 VARIANT-TESTS += ckp-eh
226 ckp-eh:
227         cp testpeers-eh.out testpeers-eh.ref
228         rm -f testpeers-eh.n???
229
230 ### locally populate, various sizes
231 # need to run in installed plc for gaining direct access (psycopg2 broken)
232 VARIANT-TESTS += run-lpn-1
233 run-lpm-1:
234         chroot $(CHROOT) make -C $(APIDIR) -f peers-test.mk chroot-run-lpm-1
235 chroot-run-lpm-1:
236         $(PY) TestPeers.py -m -p -l 1 > testpeers-pm-1.out
237 VARIANT-TESTS += run-lpm-2
238 run-lpm-2:
239         chroot $(CHROOT) make -C $(APIDIR) -f peers-test.mk chroot-run-lpm-2
240 chroot-run-lpm-2:
241         $(PY) TestPeers.py -m -p -l 2 > testpeers-pm-2.out
242
243 VARIANT-TESTS += run-lpn-1
244 run-lpn-1:
245         chroot $(CHROOT) make -C $(APIDIR) -f peers-test.mk chroot-run-lpn-1
246 chroot-run-lpn-1:
247         $(PY) TestPeers.py -p -l 1 > testpeers-pn-1.out
248 VARIANT-TESTS += run-lpn-2
249 run-lpn-2:
250         chroot $(CHROOT) make -C $(APIDIR) -f peers-test.mk chroot-run-lpn-2
251 chroot-run-lpn-2:
252         $(PY) TestPeers.py -p -l 2 > testpeers-pn-2.out
253
254 VARIANT-TESTS += run-lpb-1
255 run-lpb-1:
256         chroot $(CHROOT) make -C $(APIDIR) -f peers-test.mk chroot-run-lpb-1
257 chroot-run-lpb-1:
258         $(PY) TestPeers.py -b -p -l 1 > testpeers-pb-1.out
259 VARIANT-TESTS += run-lpb-2
260 run-lpb-2:
261         chroot $(CHROOT) make -C $(APIDIR) -f peers-test.mk chroot-run-lpb-2
262 chroot-run-lpb-2:
263         $(PY) TestPeers.py -b -p -l 2 > testpeers-pb-2.out
264
265 VARIANT-TESTS += run-lph-1
266 run-lph-1:
267         chroot $(CHROOT) make -C $(APIDIR) -f peers-test.mk chroot-run-lph-1
268 chroot-run-lph-1:
269         $(PY) TestPeers.py -H -p -l 1 > testpeers-ph-1.out
270 VARIANT-TESTS += run-lph-1
271 run-lph-2:
272         chroot $(CHROOT) make -C $(APIDIR) -f peers-test.mk chroot-run-lph-2
273 chroot-run-lph-2:
274         $(PY) TestPeers.py -H -p -l 2 > testpeers-ph-2.out
275
276
277 ### old-fashioned all-in-one tests - too slow
278 VARIANT-TESTS += run-n
279 run-n: 
280         $(PY) ./TestPeers.py > testpeers-n.out 2>&1
281 VARIANT-TESTS += run-m
282 run-m:
283         $(PY) ./TestPeers.py -m > testpeers-m.out 2>&1
284 VARIANT-TESTS += diff-m
285 diff-m: testpeers-m.nref testpeers-m.nout 
286         diff testpeers-m.nref testpeers-m.nout
287 VARIANT-TESTS += ckp-m
288 ckp-m:
289         cp testpeers-m.out testpeers-m.ref
290         rm -f testpeers-m.n???
291
292 ### populating only, but remotely - too slow too
293 VARIANT-TESTS += run-p run-pn
294 run-pn:
295         $(PY) ./TestPeers.py -p > testpeers-pn.out 2>&1
296 VARIANT-TESTS += run-pb
297 run-pb:
298         $(PY) ./TestPeers.py -p -b > testpeers-pb.out 2>&1
299 VARIANT-TESTS += run-ph
300 run-ph:
301         $(PY) ./TestPeers.py -p -H > testpeers-ph.out 2>&1
302
303 ##############################
304 VARIANTS-DB := 
305
306 DB1=populate-1.sql
307 DB2=populate-2.sql
308
309 VARIANT-DB += save-n
310 save-n: save-n-1 save-n-2
311 save-n-1: DB1=populate-n-1.sql
312 save-n-1: save1
313 save-n-2: DB2=populate-n-2.sql
314 save-n-2:save2
315
316 VARIANT-DB += save-b
317 save-b: save-b-1 save-b-2
318 save-b-1: DB1=populate-b-1.sql
319 save-b-1: save1
320 save-b-2: DB2=populate-b-2.sql
321 save-b-2:save2
322
323 VARIANT-DB += save-h
324 save-h: save-h-1 save-h-2
325 save-h-1: DB1=populate-h-1.sql
326 save-h-1: save1
327 save-h-2: DB2=populate-h-2.sql
328 save-h-2:save2
329
330 save1:
331         ssh $(PLC1SSH) make -C new_plc_api -f peers-test.mk DBDUMPFILE=$(DB1) db-dump
332         scp $(PLC1SSH):new_plc_api/$(DB1) .
333 save2:
334         ssh $(PLC2SSH) make -C new_plc_api -f peers-test.mk DBDUMPFILE=$(DB2) db-dump
335         scp $(PLC2SSH):new_plc_api/$(DB2) .
336
337 VARIANT-DB += restore-n
338 restore-n: restore-n-1 restore-n-2
339 restore-n-1: DB1=populate-n-1.sql
340 restore-n-1: restore1
341 restore-n-2: DB2=populate-n-2.sql
342 restore-n-2:restore2
343
344 VARIANT-DB += restore-b
345 restore-b: restore-b-1 restore-b-2
346 restore-b-1: DB1=populate-b-1.sql
347 restore-b-1: restore1
348 restore-b-2: DB2=populate-b-2.sql
349 restore-b-2:restore2
350
351 VARIANT-DB += restore-h
352 restore-h: restore-h-1 restore-h-2
353 restore-h-1: DB1=populate-h-1.sql
354 restore-h-1: restore1
355 restore-h-2: DB2=populate-h-2.sql
356 restore-h-2:restore2
357
358 restore1:
359         scp $(DB1) $(PLC1SSH):new_plc_api/
360         ssh $(PLC1SSH) make -C  new_plc_api -f peers-test.mk DBDUMPFILE=$(DB1) dbrestore
361 restore2:
362         scp $(DB2) $(PLC2SSH):new_plc_api/
363         ssh $(PLC2SSH) make -C  new_plc_api -f peers-test.mk DBDUMPFILE=$(DB2) dbrestore
364
365 #######
366 HELP=rpm db-dump restart-http
367
368 help:
369         @echo known targets:
370         @echo push: $(PUSH) 
371         @echo peers: $(PEERS)
372         @echo db: $(DB) 
373         @echo dbrestore: $(DBRESTORE) 
374         @echo run: $(RUN)
375         @echo web: $(WEB) 
376         @echo upgrade: $(UPGRADE)
377         @echo test: $(TEST)
378         @echo other test targets: $(VARIANT-TESTS)
379         @echo db targets: $(VARIANT-DB)
380         @echo OTHERS: $(HELP)
381