2 REVISION=$(echo '$Revision$' | sed -e 's,\$,,g' -e 's,^\w*:\s,,' )
7 # default values, tunable with command-line options
8 DEFAULT_FCDISTRO=centos5
9 DEFAULT_PLDISTRO=planetlab
10 DEFAULT_PERSONALITY=linux32
11 DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
12 DEFAULT_build_SVNPATH="http://svn.planet-lab.org/svn/build/trunk"
15 # default gpg path used in signing yum repo
16 DEFAULT_GPGPATH="/etc/planetlab"
17 # default email to use in gpg secring
18 DEFAULT_GPGUID="root@$( /bin/hostname )"
20 # web publishing results
21 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
24 DEFAULT_TESTCONFIG="default"
26 y=$(hostname|sed -e s,inria,,)
28 if [ "$x" != "$y" ] ; then
29 DEFAULT_TESTBUILDURL="http://build.onelab.eu/"
30 DEFAULT_TESTMASTER="testmaster.onelab.eu"
32 DEFAULT_TESTBUILDURL="http://build.planet-lab.org/"
33 ### xxx change as appropriate
34 DEFAULT_TESTMASTER="p-testmaster.onelab.eu"
38 # assuming vserver runs in UTC
39 DATE=$(date +'%Y.%m.%d')
41 # temporary - wrap a quick summary of suspicious stuff
42 # this is to focus on installation that go wrong
43 # use with care, a *lot* of other things can go bad as well
46 echo "******************** BEG SUMMARY"
49 # read a full log and tries to extract the interesting stuff
52 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*|.*PROPFIND.*|.*Starting.*:runtest.*")
53 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
54 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
55 m_installing_end=re.compile('Installed:.*')
56 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
57 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
59 def summary (filename):
68 for line in f.xreadlines():
69 # first off : discard warnings related to doc
70 if m_installing_doc1.match(line):
71 (begin,end)=m_installing_doc1.match(line).groups()
73 if m_installing_doc2.match(line):
74 (begin,end)=m_installing_doc2.match(line).groups()
76 # unconditionnally show these lines
77 if m_show_line.match(line):
79 # an 'installing' line with messages afterwards : needs to be echoed
80 elif m_installing_err.match(line):
81 (installing,error)=m_installing_err.match(line).groups()
82 print '>>>',installing
85 # closing an 'installing' section
86 elif m_installing_end.match(line):
88 # any 'installing' line
89 elif m_installing_any.match(line):
91 installing=m_installing_any.match(line).group(1)
92 print '>>>',installing
94 # print lines when echo is true
96 if echo: print '>>>',line,
99 print 'Failed to analyze',filename
101 for arg in sys.argv[1:]:
104 echo "******************** END SUMMARY"
108 # Notify recipient of failure or success, manage various stamps
111 # early stage ? - let's not create /build/@PLDISTRO@
112 if [ ! -d ${WEBPATH} ] ; then
114 WEBLOG=/tmp/vbuild-early.log.txt
117 summary $LOG >> ${WEBLOG}
118 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
119 if [ -n "$MAILTO" ] ; then
121 echo "See full build log at ${LOG_URL}" ; \
122 echo "and tail version at ${LOG_URL}.ko" ; \
123 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
124 tail -c 30k ${WEBLOG} ) | mail -s "Failures with ${MAIL_SUBJECT}" $MAILTO
129 function success () {
131 # early stage ? - let's not create /build/@PLDISTRO@
132 if [ ! -d ${WEBPATH} ] ; then
134 WEBLOG=/tmp/vbuild-early-$(date +%Y-%m-%d).log.txt
137 summary $LOG >> ${WEBLOG}
138 if [ -n "$DO_TEST" ] ; then
140 echo "Successfully built and tested" ; \
141 echo "See full build log at ${LOG_URL}" ; \
142 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
144 rm -f ${WEBLOG}.pkg-ok ${WEBLOG}.ko
147 echo "Successful package-only build, no test requested" ; \
148 echo "See full build log at ${LOG_URL}" ; \
152 if [ -n "$MAILTO" ] ; then
154 echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ; \
155 echo "See full build log at ${LOG_URL}" ; \
156 [ -n "$DO_TEST" ] && echo "See complete set of testlogs at ${TESTLOGS_URL}" ) \
157 | mail -s "Success with ${MAIL_SUBJECT}" $MAILTO
162 # run in the vserver - do not manage success/failure, will be done from the root ctx
167 echo -n "============================== Starting $COMMAND:build on "
173 echo "Running make IN $(pwd)"
175 # stuff our own variable settings
176 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
177 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
178 MAKEVARS=("build-SVNPATH=${build_SVNPATH}" "${MAKEVARS[@]}")
179 MAKEVARS=("PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
180 MAKEVARS=("MAILTO=${MAILTO}" "${MAKEVARS[@]}")
182 MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
185 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
186 # store tests_svnpath
187 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
189 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
191 make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
195 # this was formerly run in the myplc-devel chroot but now is run in the root context,
196 # this is so that the .ssh config gets done manually, and once and for all
197 function runtest () {
202 echo -n "============================== Starting $COMMAND:runtest on $(date)"
204 # where to find TESTS_SVNPATH
205 stamp=/vservers/$BASE/build/tests_svnpath
206 if [ ! -f $stamp ] ; then
207 echo "$COMMAND: Cannot figure TESTS_SVNPATH from missing $stamp"
211 TESTS_SVNPATH=$(cat $stamp)
212 # xxx - Thierry - need to rework the test framework in tests/system so it can work
213 # with the entire tests/ module checked out, rather than only tests/system/
214 # ugly workaround for now
215 TESTS_SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
217 ### the URL to the RPMS/<arch> location
219 for a in i386 x86_64; do
220 archdir=/vservers/$BASE/build/RPMS/$a
221 if [ -d $archdir ] ; then
222 url=$(echo $archdir | sed -e "s,/vservers/$BASE/build,${TESTBUILDURL}${PLDISTRO}/${BASE},")
227 if [ -z "$url" ] ; then
228 echo "$COMMAND: Cannot locate arch URL for testing"
233 testmaster_ssh="root@${TESTMASTER}"
235 # test directory name on test box
238 ssh -n ${testmaster_ssh} rm -rf ${testdir}
240 ssh -n ${testmaster_ssh} svn co ${TESTS_SYSTEM_SVNPATH} ${testdir}
241 # check out the entire tests/ module (with system/ duplicated) as a subdir - see xxx above
242 ssh -n ${testmaster_ssh} svn co ${TESTS_SVNPATH} ${testdir}/tests
243 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
245 for config in ${TESTCONFIG} ; do
246 configs="$configs --config $config"
248 test_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
250 # need to proceed despite of set -e
252 ssh 2>&1 -n ${testmaster_ssh} ${testdir}/runtest --build ${build_SVNPATH} --url ${url} $configs $test_env --all || success=
254 # gather logs in the vserver
255 mkdir -p /vservers/$BASE/build/testlogs
256 ssh 2>&1 -n ${testmaster_ssh} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
257 # push them to the build web
258 chmod -R a+r /vservers/$BASE/build/testlogs/
259 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
261 if [ -z "$success" ] ; then
265 echo -n "============================== End $COMMAND:runtest on $(date)"
268 function in_root_context () {
269 rpm -q util-vserver > /dev/null
272 # this part won't work with a remote(rsync) WEBPATH
273 function sign_node_packages () {
275 echo "Signing node packages"
279 repository=$WEBPATH/$BASE/RPMS/
280 # the rpms that need signing
282 # and the corresponding stamps
285 for package in $(find $repository/ -name '*.rpm') ; do
286 stamp=$repository/signed-stamps/$(basename $package).signed
287 # If package is newer than signature stamp
288 if [ $package -nt $stamp ] ; then
289 new_rpms="$new_rpms $package"
290 new_stamps="$new_stamps $stamp"
292 # Or than createrepo database
293 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
296 if [ -n "$new_rpms" ] ; then
297 # Create a stamp once the package gets signed
298 mkdir $repository/signed-stamps 2> /dev/null
300 # Sign RPMS. setsid detaches rpm from the terminal,
301 # allowing the (hopefully blank) GPG password to be
302 # entered from stdin instead of /dev/tty.
304 --define "_signature gpg" \
305 --define "_gpg_path $GPGPATH" \
306 --define "_gpg_name $GPGUID" \
307 --resign $new_rpms && touch $new_stamps
310 # Update repository index / yum metadata.
311 if [ -n "$need_createrepo" ] ; then
312 echo "Indexing node packages after signing"
313 if [ -f $repository/yumgroups.xml ] ; then
314 createrepo --quiet -g yumgroups.xml $repository
316 createrepo --quiet $repository
321 function show_env () {
323 echo FCDISTRO=$FCDISTRO
324 echo PLDISTRO=$PLDISTRO
325 echo PERSONALITY=$PERSONALITY
327 echo build_SVNPATH=$build_SVNPATH
328 echo MAKEVARS="${MAKEVARS[@]}"
329 echo DRY_RUN="$DRY_RUN"
330 echo PLDISTROTAGS="$PLDISTROTAGS"
331 # this does not help, it's not yet set when we run show_env
332 #echo WEBPATH="$WEBPATH"
333 echo TESTBUILDURL="$TESTBUILDURL"
334 if in_root_context ; then
335 echo PLDISTROTAGS="$PLDISTROTAGS"
337 if [ -f /build/$PLDISTROTAGS ] ; then
338 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
339 cat /build/$PLDISTROTAGS
340 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
342 echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
349 echo "Usage: $COMMAND [option] [var=value...] make-targets"
350 echo "This is $REVISION"
351 echo "Supported options"
352 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
353 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
354 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
355 echo " -m mailto - no default"
356 echo " -s svnpath - where to fetch the build module - defaults to $DEFAULT_build_SVNPATH"
357 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
358 echo " -b base - defaults to $DEFAULT_BASE"
359 echo " @NAME@ replaced as appropriate"
360 echo " -o base: (overwrite) do not re-create vserver, re-use base instead"
361 echo " the -f/-d/-p/-m/-s/-t options are uneffective in this case"
362 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
363 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
364 echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL"
365 echo " -M testmaster - defaults to $DEFAULT_TESTMASTER"
366 echo " -y sign yum repo in webpath"
367 echo " -g path to gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
368 echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
369 echo " -B : run build only"
370 echo " -T : run test only"
371 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
372 echo " -v : be verbose"
373 echo " -7 : uses weekday-@FCDISTRO@ as base"
374 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
389 while getopts "f:d:p:m:s:t:b:o:c:w:W:M:yg:u:BTnv7i:" opt ; do
391 f) FCDISTRO=$OPTARG ;;
392 d) PLDISTRO=$OPTARG ;;
393 p) PERSONALITY=$OPTARG ;;
395 s) build_SVNPATH=$OPTARG ;;
396 t) PLDISTROTAGS=$OPTARG ;;
398 o) OVERBASE=$OPTARG ;;
399 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
400 w) WEBPATH=$OPTARG ;;
401 W) TESTBUILDURL=$OPTARG ;;
402 M) TESTMASTER=$OPTARG ;;
403 y) SIGNYUMREPO=true ;;
404 g) GPGPATH=$OPTARG ;;
410 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
416 # preserve options for passing them again later, together with expanded base
418 toshift=$(($OPTIND - 1))
419 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
421 # allow var=value stuff;
422 for target in "$@" ; do
423 # check if contains '='
424 target1=$(echo $target | sed -e s,=,,)
425 if [ "$target" = "$target1" ] ; then
426 MAKETARGETS=(${MAKETARGETS[@]} "$target")
428 MAKEVARS=(${MAKEVARS[@]} "$target")
433 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
434 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
435 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
436 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
437 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
438 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
439 [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
440 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
441 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
442 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
443 [ -z "$build_SVNPATH" ] && build_SVNPATH="$DEFAULT_build_SVNPATH"
444 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
446 [ -n "$DRY_RUN" ] && MAILTO=""
448 if [ -n "$OVERBASE" ] ; then
449 sedargs="-e s,@DATE@,${DATE},g"
450 BASE=$(echo ${OVERBASE} | sed $sedargs)
452 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
453 BASE=$(echo ${BASE} | sed $sedargs)
456 ### elaborate mail subject
457 if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
458 MAIL_SUBJECT="complete"
459 elif [ -n "$DO_BUILD" ] ; then
460 MAIL_SUBJECT="package-only"
461 elif [ -n "$DO_TEST" ] ; then
462 MAIL_SUBJECT="test-only"
464 if [ -n "$OVERBASE" ] ; then
465 MAIL_SUBJECT="$MAIL_SUBJECT incremental run on"
467 MAIL_SUBJECT="$MAIL_SUBJECT fresh build"
469 MAIL_SUBJECT="$MAIL_SUBJECT ${BASE}"
471 if ! in_root_context ; then
473 echo "==================== Within vserver BEG $(date)"
475 echo "==================== Within vserver END $(date)"
479 # we run in the root context :
480 # (*) create or check for the vserver to use
481 # (*) copy this command in the vserver
484 if [ -n "$OVERBASE" ] ; then
485 ### Re-use a vserver (finish an unfinished build..)
486 if [ ! -d /vservers/${BASE} ] ; then
487 echo $COMMAND : cannot find vserver $BASE
490 # manage LOG - beware it might be a symlink so nuke it first
491 LOG=/vservers/${BASE}.log.txt
495 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
496 # start in case e.g. we just rebooted
497 vserver ${BASE} start || :
499 vserver ${BASE} exec svn update /build
500 # get environment from the first run
501 FCDISTRO=$(vserver ${BASE} exec /build/getdistroname.sh)
503 PLDISTRO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTRO)
504 PLDISTROTAGS=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTROTAGS)
505 build_SVNPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +build-SVNPATH)
506 PERSONALITY=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PERSONALITY)
507 MAILTO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +MAILTO)
510 # create vserver: check it does not exist yet
512 while [ -d /vservers/${BASE}${i} ] ; do
513 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
514 [ -z ${i} ] && BASE=${BASE}-n
516 if [ $i -gt 100 ] ; then
517 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
523 # manage LOG - beware it might be a symlink so nuke it first
524 LOG=/vservers/${BASE}.log.txt
528 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
531 ### extract the whole build - much simpler
532 tmpdir=/tmp/$COMMAND-$$
533 svn export $build_SVNPATH $tmpdir
536 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
540 # Extract build again - in the vserver
541 vserver ${BASE} exec svn checkout ${build_SVNPATH} /build
543 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
545 # The log inside the vserver contains everything
546 LOG2=/vservers/${BASE}/log.txt
547 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
549 echo "==================== END VSERVER Transcript of vserver creation" ; \
550 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
551 ### not too nice : nuke the former log, symlink it to the new one
552 rm $LOG; ln -s $LOG2 $LOG
557 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
558 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
561 # where to store the log for web access
562 WEBLOG=${WEBPATH}/${BASE}.log.txt
563 # compute the log URL - inserted in the mail messages for convenience
564 LOG_URL=$(echo ${WEBLOG} | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
565 TESTLOGS_URL=$(echo ${WEBPATH}/${BASE}/testlogs | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
567 if [ -n "$DO_BUILD" ] ; then
569 cp $COMMANDPATH /vservers/${BASE}/build/
571 # invoke this command in the vserver for building (-T)
572 vserver ${BASE} exec chmod +x /build/$COMMAND
573 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
576 # publish to the web so runtest can find them
577 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
578 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
579 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
580 # publish myplc-release
581 rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
583 # create yum repo and sign packages.
584 if [ -n "$SIGNYUMREPO" ] ; then
588 if [ -n "$DO_TEST" ] ; then