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