7 CHROOT=chroot $(CHROOTJAIL)
9 SITEDIR=/etc/planetlab/configs
11 APIDIR=/usr/share/plc_api
12 ROOTAPIDIR=/plc/root$(APIDIR)
13 WORKDIR=new_plc_api/tests
25 # if make is invoked with -n, run rsync, but with --dry-run
26 RSYNC_EXCLUDES := --exclude .svn --exclude '*~' --exclude '*.pyc'
28 RSYNC_COND_DRY_RUN := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
29 RSYNC_ARGS += $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES)
30 RSYNC := $(RSYNC_CMD) $(RSYNC_ARGS)
32 #################### remote invokation and chroot hops
33 # rule to invoke a target within the chroot context
34 %.chroot: target=$(subst .chroot,,$@)
36 $(CHROOT) $(MAKE) -C $(APIDIR)/tests INCHROOT=true $(target)
37 -cp $(ROOTAPIDIR)/tests/$(target) .
39 # generic rules to ssh and make
40 # need to explicitly export MAKEFLAGS that cannot be exported by make through ssh
41 %.1: prefix=$(subst .1,,$@)
42 %.1: output=$(subst .chroot,,$(prefix))
44 @echo ">>>>>>>> entering ssh $(PLC1SSH)"
45 ssh $(PLC1SSH) $(MAKE) MAKEFLAGS=$(MAKEFLAGS) -C $(WORKDIR) PLCEND=1 $(prefix)
46 @echo "<<<<<<<< exiting ssh $(PLC1SSH)"
47 -scp $(PLC1SSH):$(WORKDIR)/$(output) . 2> /dev/null
48 %.2: prefix=$(subst .2,,$@)
49 %.2: output=$(subst .chroot,,$(prefix))
51 @echo ">>>>>>>> entering ssh $(PLC2SSH)"
52 ssh $(PLC2SSH) $(MAKE) MAKEFLAGS=$(MAKEFLAGS) -C $(WORKDIR) PLCEND=2 $(prefix)
53 @echo "<<<<<<<< exiting ssh $(PLC2SSH)"
54 -scp $(PLC2SSH):$(WORKDIR)/$(output) . 2> /dev/null
56 # cannot just depend on .1 and .2 because they are phony
57 %.3: prefix=$(subst .3,,$@)
59 $(MAKE) $(prefix).1 $(prefix).2
61 %.both: prefix=$(subst .both,,$@)
63 $(MAKE) $(prefix).chroot.1 $(prefix).chroot.2
66 # phony targets MUST NOT try to get their result through scp
67 # usage: ssh_phony_target <target>
68 define ssh_phony_target
70 $(CHROOT) $(MAKE) -C $(APIDIR)/tests INCHROOT=true $(1)
72 @echo ">>>>>>>> entering ssh $(PLC1SSH)"
73 ssh $(PLC1SSH) $(MAKE) MAKEFLAGS=$(MAKEFLAGS) -C $(WORKDIR) PLCEND=1 $(1)
74 @echo "<<<<<<<< exiting ssh $(PLC1SSH)"
76 @echo ">>>>>>>> entering ssh $(PLC2SSH)"
77 ssh $(PLC2SSH) $(MAKE) MAKEFLAGS=$(MAKEFLAGS) -C $(WORKDIR) PLCEND=2 $(1)
78 @echo "<<<<<<<< exiting ssh $(PLC2SSH)"
82 define here_and_proceed_target
101 PLC-PUSHS= ../PLC ../planetlab4.sql ../migrations ../plcsh ../tests
105 -find .. '(' -name '*.pyc' -o -name '*~' ')' | xargs rm
108 +$(RSYNC) -a -v -C ../ root@$(PLC1):new_plc_api/
111 +$(RSYNC) -a -v -C $(PLC-PUSHS) root@$(PLC1):$(CHROOTJAIL)$(APIDIR)/
114 +$(RSYNC) -a -v -C ../ root@$(PLC2):new_plc_api/
117 +$(RSYNC) -a -v -C $(PLC-PUSHS) root@$(PLC2):$(CHROOTJAIL)$(APIDIR)/
120 push.1: proot1 pchroot1
121 push.2: proot2 pchroot2
122 # DONT! mention this in PHONIES
123 .PHONY: push push.1 push.2
130 ssh $(PLC1SSH) "gpg --homedir=/etc/planetlab --export --armor > /etc/planetlab/gpg_plc1.pub"
133 ssh $(PLC2SSH) "gpg --homedir=/etc/planetlab --export --armor > /etc/planetlab/gpg_plc2.pub"
134 # directly scp'ing from one url to the other does not work, looks like
135 # first host tries to connect the second one
136 PEERS += peer-push-gpg-1
138 scp $(PLC1SSH):/etc/planetlab/gpg_plc1.pub ./
139 scp ./gpg_plc1.pub $(PLC2SSH):/etc/planetlab/
140 PEERS += peer-push-gpg-2
142 scp $(PLC2SSH):/etc/planetlab/gpg_plc2.pub ./
143 scp ./gpg_plc2.pub $(PLC1SSH):/etc/planetlab/
144 PEERS += peer-push-cacert-1
146 scp $(PLC1SSH):/etc/planetlab/api_ca_ssl.crt ./api_plc1.crt
147 scp ./api_plc1.crt $(PLC2SSH):/etc/planetlab/
148 scp ./api_plc1.crt $(PLC1SSH):/etc/planetlab/
149 PEERS += peer-push-cacert-2
151 scp $(PLC2SSH):/etc/planetlab/api_ca_ssl.crt ./api_plc2.crt
152 scp ./api_plc2.crt $(PLC1SSH):/etc/planetlab/
153 scp ./api_plc2.crt $(PLC2SSH):/etc/planetlab/
160 PHONIES += peers-clean
162 rm -f /etc/planetlab/*plc[12]*
164 HELP += peers-clean.3
166 # upgrade : install the most recent myplc rpm found in /root/$(WORKDIR)
167 RPM=$(shell ls -rt /root/$(WORKDIR)/myplc*rpm | tail -1)
171 @echo upgrade would install latest rpm : $(RPM)
180 -$(CHROOT) service plc safestop
181 UPGRADE += plc-preserve
183 cp $(SITEDIR)/$(SITE) .
184 UPGRADE += plc-uninstall
189 -rm -rf /plc/root /plc/data
190 UPGRADE += plc-install
193 UPGRADE += plc-reconfig
197 cp $(SITE) $(SITEDIR)
198 (echo w; echo q) | $(CHROOT) plc-config-tty
201 $(CHROOT) service plc start
203 PHONIES += $(UPGRADE)
209 # cleaning the database
213 $(CHROOT) psql -U postgres --port $(PORT) template1 -c 'drop database planetlab4'
216 service plc stop db postgresql httpd
217 service plc start httpd postgresql db
220 $(CHROOT) pg_dump -c -U pgsqluser planetlab4 > test-clean.sql
222 db-safeclean: db-drop db-restart db-clean-save
226 $(CHROOT) psql -U pgsqluser --port $(PORT) -d planetlab4 < test-clean.sql &> test-clean.restore
231 # TestPeers options :
232 # -m -b -h : allow to select test size (mini, normal, big, huge)
233 # -l 1|2 required for running -p locally from a given end for performance
234 # -1 | -2 shorthands for -l 1 and -l 2 - for integration with this Makefile
236 # first clean off dbs
237 # run populate separately on both ends
238 # optionally save database at this point
239 # then run end of script locally
242 ### for a given 'targetname' like, e.g. 'e-n', we define the following targets
243 # testpeers.<targetname>.out -- for running the test
244 # testpeers.<targetname>.diff -- to compute the difference with expected result
245 # testpeers.<targetname>.adopt -- phony target for adopting new result - no commit done
248 # generic rule for running TestPeers
249 # make testpeers.-option.some.stuff.out
250 # => python -u ./TestPeers.py -option some stuff > testpeers.-option.some.stuff.out 2>&1
251 testpeers.%.out: prefix=$(subst .out,,$@)
252 testpeers.%.out: dotargs=$(subst testpeers.,,$(prefix))
253 testpeers.%.out: args=$(subst ., ,$(dotargs))
255 $(PY) ./TestPeers.py $(args) > $@ 2>&1 ; if [ "$$?" != 0 ] ; then mv $@ $@.fail ; exit 1; fi
257 ### generic rule for computing differences --
258 # xxx this requires changes in TestPeers due to the new return code of RefreshPeers
259 # remove time/delay dependent output
260 normalize = egrep -v "'expires':|^+++.*ellapsed"
262 $(normalize) $*.out > $@
264 $(normalize) $*.ref > $@
266 testpeers.%.diff: out=$(subst .diff,.out,$@)
267 testpeers.%.diff: nout=$(subst .diff,.nout,$@)
268 testpeers.%.diff: ref=$(subst .diff,.ref,$@)
269 testpeers.%.diff: nref=$(subst .diff,.nref,$@)
271 @if [ ! -f $(out) ] ; then echo "Could not locate $(out)" ; exit 1 ; fi
272 @if [ ! -f $(ref) ] ; then echo "Could not locate $(ref)" ; exit 1 ; fi
273 $(MAKE) $(nref) $(nout)
274 diff $(nref) $(nout) > $@
276 ### generic rule for adopting current result
277 testpeers.%.ckp: prefix=$(subst .ckp,,$@)
278 testpeers.%.ckp: out=$(subst .ckp,.out,$@)
279 testpeers.%.ckp: ref=$(subst .ckp,.ref,$@)
281 @if [ ! -f $(out) ] ; then echo "Could not locate $(out)" ; exit 1 ; fi
283 rm -f $(prefix).{diff,nout,nref}
285 testpeers.%.clean: prefix=$(subst .clean,,$@)
287 rm -f $(prefix).{out,nout,nref,diff}
290 HELP += testpeers-clean
291 $(eval $(call here_and_proceed_target,testpeers-clean,rm -f testpeers*.nref testpeers*.nout))
293 HELP += testpeers-distclean
294 $(eval $(call here_and_proceed_target,testpeers-distclean,rm -f testpeers*.out testpeers*.sql testpeers*.nref testpeers*.nout))
297 clean: testpeers-clean
299 $(eval $(call here_and_proceed_target,sqlclean,rm test*.sql))
301 distclean: testpeers-distclean
302 PHONIES += clean distclean
305 $(eval $(call here_and_proceed_target,sql-clean,rm testpeers.*.sql))
307 ##############################
308 # creating a snapshot of the databases
309 # for efficiency this is done from a Direct API method, thus under a chroot
311 define snapshot_and_restore_size_plc
312 testpeers.$(1).$(2).sql: testpeers.$(1).$(2).out
313 pg_dump -c -U pgsqluser planetlab4 > testpeers.$(1).$(2).sql
315 testpeers.$(1).$(2).restore: testpeers.$(1).$(2).sql
316 echo Restoring testpeers.$(1).$(2).sql
317 psql -U pgsqluser --port $(PORT) -d planetlab4 -f testpeers.$(1).$(2).sql &> testpeers.$(1).$(2).restore
318 DB-SQL += testpeers.$(1).$(2).sql
319 DB-RESTORE += testpeers.$(1).$(2).restore
322 define snapshot_and_restore_size
323 $(foreach plc,$(PLCS),$(eval $(call snapshot_and_restore_size_plc,$(1),$(plc).populate)))
326 $(foreach size,$(SIZES),$(eval $(call snapshot_and_restore_size,$(size))))
328 define populate_shortcut
330 populate$(1): populate$(1).init populate$(1).run
331 populate$(1).all: db-clean.3 populate$(1).clean populate$(1).init populate$(1).run
332 populate$(1).init: testpeers.$(1).-1.populate.out.chroot.1 testpeers.$(1).-1.populate.sql.chroot.1
333 populate$(1).init: testpeers.$(1).-2.populate.out.chroot.2 testpeers.$(1).-2.populate.sql.chroot.2
334 populate$(1).restore: testpeers.$(1).-1.populate.restore.chroot.1 testpeers.$(1).-2.populate.restore.chroot.2
335 populate$(1).run: testpeers.$(1).populate_end.out
336 populate$(1).diff: testpeers.$(1).-1.populate.diff testpeers.$(1).-2.populate.diff testpeers.$(1).populate_end.diff
337 populate$(1).ckp: testpeers.$(1).-1.populate.ckp testpeers.$(1).-2.populate.ckp testpeers.$(1).populate_end.ckp
338 $(eval $(call here_and_proceed_target,populate$(1).clean,rm -f testpeers.$(1)*populate*.out testpeers.$(1)*populate*.restore))
339 $(eval $(call here_and_proceed_target,populate$(1).sqlclean,rm -f testpeers.$(1)*populate*.sql))
343 $(foreach size,$(SIZES),$(eval $(call populate_shortcut,$(size))))
346 @echo "===================="
347 @echo "populate test targets"
348 @echo -e "populate-n\t\truns .init and .run"
349 @echo -e "populate-b.init\t\texpects a clean db, populates only and dumps"
350 @echo -e "populate-b.all\t\tcleans the db and former test results, runs the full test"
351 @echo -e "populate-m.run\t\truns the actual test after both plcs were inited"
352 @echo -e "populate-h.restore\t\trestores both plcs as if just inited"
353 @echo -e "populate-n.ckp\t\tcheckpoints out files as references"
354 @echo -e "populate-n.diff\t\tcompares out files against reference"
357 define testpeers_shortcut
359 testpeers$(1).run: testpeers.$(1).test_all.out
360 testpeers$(1).all: db-clean.3 testpeers.$(1).test_all.out
361 testpeers$(1).diff: testpeers.$(1).test_all.diff
362 testpeers$(1).ckp: testpeers.$(1).test_all.ckp
366 $(foreach size,$(SIZES),$(eval $(call testpeers_shortcut,$(size))))
369 @echo "Available sizes" $(SIZES)
370 @echo "testpeers targets"
371 @echo -e "testpeers-n.run\t\truns the test"
372 @echo -e "testpeers-b.all\t\tcleans the db and former test results, runs the full test"
373 @echo -e "testpeers-m.run\t\truns the actual test after both plcs were inited"
374 @echo -e "testpeers-h.restore\t\trestores both plcs as if just inited"
375 @echo -e "testpeers-n.ckp\t\tcheckpoints out files as references"
376 @echo -e "testpeers-n.diff\t\tcompares out files against reference"
382 $(CHROOT) /usr/bin/plcsh
385 $(CHROOT) psql -U pgsqluser planetlab4
388 emacs /plc/data/var/log/httpd/error_log /plc/data/var/log/boot.log
393 $(foreach phony,$(PHONIES),$(eval $(call ssh_phony_target,$(phony))))
396 help: testpeers.help populate.help
397 @echo "===================="
398 @echo "other known targets:"
399 @echo "db family:" $(DB)
400 @echo -e "e.g.\tmake db-clean.3"
401 @echo "push:" $(PUSH)
402 @echo "peers:" $(PEERS)
403 @echo "===================="
404 @echo "For running on plc1, on plc2, or both:"
405 @echo -e "\t make <target>.1 <target>.2 <target.3>"
406 @echo "For running in a chroot jail"
407 @echo -e "\t make <target>.chroot"
408 @echo "So for running on both nodes chroots"
409 @echo -e "\t make <target>.chroot.3"
410 @echo "for running TestPeers : testpeers=<args separated by +>.out"
411 @echo -e "\t e.g. make testpeers.-m.test_all"
412 @echo -e "\t e.g. make testpeers.-h.-1.populate"
413 @echo "comparing run with reference : testpeers.<args separated by .>.diff"
414 @echo "adopt run as reference : testpeers.<args separated by .>.ckp"
415 @echo -e "\t e.g. make testpeers.-m.test_all"
416 @echo -e "\t e.g. make testpeers.-h.-1.populate"
417 @echo "===================="
418 @echo "Supported size variants:" $(SIZES)
419 @echo "Supported plc ids:" $(PLCS)
420 @echo "snapshotting the DB : " $(DB-SQL) $(DB-RESTORE)
421 @echo "===================="
422 @echo "upgrade:" $(UPGRADE)
423 @echo "run family (convenience):" $(RUN)
424 @echo "OTHERS:" $(HELP)
427 #################### convenience, for debugging only
428 # make +foo : prints the value of $(foo)
429 # make ++foo : idem but verbose, i.e. foo=$(foo)
430 ++%: varname=$(subst +,,$@)
432 @echo "$(varname)=$($(varname))"
433 +%: varname=$(subst +,,$@)
435 @echo "$($(varname))"