2 REVISION=$(echo '$Revision$' | sed -e 's,\$,,g' -e 's,^\w*:\s,,' )
7 # default values, tunable with command-line options
9 DEFAULT_PLDISTRO=planetlab
10 DEFAULT_PERSONALITY=linux32
11 DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
12 DEFAULT_SVNPATH="http://svn.planet-lab.org/svn/build/trunk"
13 DEFAULT_TESTCONFIG="default"
16 # web publishing results
17 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
19 # default gpg path used in signing yum repo
20 DEFAULT_GPGPATH="/etc/planetlab"
21 # default email to use in gpg secring
22 DEFAULT_GPGUID="root@$( /bin/hostname )"
25 DEFAULT_TESTBUILDURL="http://build.onelab.eu/"
26 TESTBOXSSH=root@testbox.onelab.eu
28 # assuming vserver runs in UTC
29 DATE=$(date +'%Y.%m.%d')
31 # temporary - wrap a quick summary of suspicious stuff
32 # this is to focus on installation that go wrong
33 # use with care, a *lot* of other things can go bad as well
36 echo "******************** BEG SUMMARY"
39 # read a full log and tries to extract the interesting stuff
42 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*")
43 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
44 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
45 m_installing_end=re.compile('Installed:.*')
46 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
47 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
49 def summary (filename):
58 for line in f.xreadlines():
59 # first off : discard warnings related to doc
60 if m_installing_doc1.match(line):
61 (begin,end)=m_installing_doc1.match(line).groups()
63 if m_installing_doc2.match(line):
64 (begin,end)=m_installing_doc2.match(line).groups()
66 # unconditionnally show these lines
67 if m_show_line.match(line):
69 # an 'installing' line with messages afterwards : needs to be echoed
70 elif m_installing_err.match(line):
71 (installing,error)=m_installing_err.match(line).groups()
72 print '>>>',installing
75 # closing an 'installing' section
76 elif m_installing_end.match(line):
78 # any 'installing' line
79 elif m_installing_any.match(line):
81 installing=m_installing_any.match(line).group(1)
82 print '>>>',installing
84 # print lines when echo is true
86 if echo: print '>>>',line,
89 print 'Failed to analyze',filename
91 for arg in sys.argv[1:]:
94 echo "******************** END SUMMARY"
98 # Notify recipient of failure or success, manage various stamps
103 summary $LOG >> ${WEBLOG}
104 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
105 if [ -n "$MAILTO" ] ; then
107 echo "See full build log at ${LOG_URL}" ; \
108 echo "and tail version at ${LOG_URL}.ko" ; \
109 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
110 tail -c 30k ${WEBLOG} ) | mail -s "Failures for build ${BASE}" $MAILTO
115 function success () {
119 summary $LOG >> ${WEBLOG}
120 if [ -n "$DO_TEST" ] ; then
122 echo "Successfully built and tested" ; \
123 echo "See full build log at ${LOG_URL}" ; \
124 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
126 rm -f ${WEBLOG}.ok ${WEBLOG}.ko
129 echo "Successfully built, no test requested" ; \
130 echo "See full build log at ${LOG_URL}" ; \
133 if [ -n "$MAILTO" ] ; then
135 echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ; \
136 echo "See full build log at ${LOG_URL}" ; \
137 [ -n "$DO_TEST" ] && echo "See complete set of testlogs at ${TESTLOGS_URL}" ) \
138 | mail -s "Successful build for ${BASE}" $MAILTO
143 # run in the vserver - do not manage success/failure, will be done from the root ctx
148 echo -n "============================== Starting $COMMAND:build on "
152 # if TAGSRELEASE specified : update PLDISTROTAGS with this tag
153 if [ -n "$TAGSRELEASE" ] ; then
154 svn up -r $TAGSRELEASE $PLDISTROTAGS
159 echo "Running make IN $(pwd)"
161 # stuff our own variable settings
162 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
163 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
164 MAKEVARS=("NIGHTLY_BASE=${BASE}" "${MAKEVARS[@]}")
165 MAKEVARS=("NIGHTLY_PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
166 MAKEVARS=("build-SVNPATH=${SVNPATH}" "${MAKEVARS[@]}")
169 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
170 # store tests_svnpath
171 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
173 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
175 make -C /build $DRY_RUN "${MAKEVARS[@]}" $MAKETARGETS
179 # this was formerly run in the myplc-devel chroot but now is run in the root context,
180 # this is so that the .ssh config gets done manually, and once and for all
181 function runtest () {
186 echo -n "============================== Starting $COMMAND:runtest on $(date)"
188 # where to find TESTS_SVNPATH
189 stamp=/vservers/$BASE/build/tests_svnpath
190 if [ ! -f $stamp ] ; then
191 echo "$COMMAND: Cannot figure TESTS_SVNPATH from missing $stamp"
195 TESTS_SVNPATH=$(cat $stamp)
196 # xxx - Thierry - need to rework the test framework in tests/system so it can work
197 # with the entire tests/ module checked out, rather than only tests/system/
198 # ugly workaround for now
199 SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
201 ### the URL to the RPMS/<arch> location
203 for a in i386 x86_64; do
204 archdir=/vservers/$BASE/build/RPMS/$a
205 if [ -d $archdir ] ; then
206 url=$(echo $archdir | sed -e "s,/vservers/$BASE/build,${TESTBUILDURL}${PLDISTRO}/${BASE},")
211 if [ -z "$url" ] ; then
212 echo "$COMMAND: Cannot locate arch URL for testing"
217 # test directory name on test box
220 ssh -n ${TESTBOXSSH} rm -rf ${testdir}
222 ssh -n ${TESTBOXSSH} svn co ${SYSTEM_SVNPATH} ${testdir}
223 # check out the entire tests/ module (with system/ duplicated) as a subdir - see xxx above
224 ssh -n ${TESTBOXSSH} svn co ${TESTS_SVNPATH} ${testdir}/tests
225 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
227 for config in ${TESTCONFIG} ; do
228 configs="$configs --config $config"
230 test_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
232 # need to proceed despite of set -e
234 ssh 2>&1 -n ${TESTBOXSSH} ${testdir}/runtest --build ${SVNPATH} --url ${url} $configs $test_env --all || success=
236 # gather logs in the vserver
237 mkdir -p /vservers/$BASE/build/testlogs
238 ssh 2>&1 -n ${TESTBOXSSH} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
239 # push them to the build web
240 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
241 chmod -R a+r $WEBPATH/$BASE/testlogs/
243 if [ -z "$success" ] ; then
247 echo -n "============================== End $COMMAND:runtest on $(date)"
250 function in_root_context () {
251 rpm -q util-vserver > /dev/null
254 function sign_node_packages () {
256 echo "Signing node packages"
260 repository=$WEBPATH/$BASE/RPMS/
261 # the rpms that need signing
263 # and the corresponding stamps
266 for package in $(find $repository/ -name '*.rpm') ; do
267 stamp=$repository/signed-stamps/$(basename $package).signed
268 # If package is newer than signature stamp
269 if [ $package -nt $stamp ] ; then
270 new_rpms="$new_rpms $package"
271 new_stamps="$new_stamps $stamp"
273 # Or than createrepo database
274 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
277 if [ -n "$new_rpms" ] ; then
278 # Create a stamp once the package gets signed
279 mkdir $repository/signed-stamps 2> /dev/null
281 # Sign RPMS. setsid detaches rpm from the terminal,
282 # allowing the (hopefully blank) GPG password to be
283 # entered from stdin instead of /dev/tty.
285 --define "_signature gpg" \
286 --define "_gpg_path $GPGPATH" \
287 --define "_gpg_name $GPGUID" \
288 --resign $new_rpms && touch $new_stamps
291 # Update repository index / yum metadata.
292 if [ -n "$need_createrepo" ] ; then
293 echo "Indexing node packages after signing"
294 if [ -f $repository/yumgroups.xml ] ; then
295 createrepo --quiet -g yumgroups.xml $repository
297 createrepo --quiet $repository
302 function show_env () {
304 echo FCDISTRO=$FCDISTRO
305 echo PLDISTRO=$PLDISTRO
307 echo SVNPATH=$SVNPATH
308 echo MAKEVARS="${MAKEVARS[@]}"
309 echo DRY_RUN="$DRY_RUN"
310 echo PLDISTROTAGS="$PLDISTROTAGS"
311 echo TAGSRELEASE="$TAGSRELEASE"
312 echo -n "(might be unexpanded)"
313 echo WEBPATH="$WEBPATH"
314 echo TESTBUILDURL="$TESTBUILDURL"
315 if in_root_context ; then
316 echo PLDISTROTAGS="$PLDISTROTAGS"
318 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
319 cat /build/$PLDISTROTAGS
320 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
326 echo "Usage: $COMMAND [option] make-targets"
327 echo "This is $REVISION"
328 echo "Supported options"
329 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
330 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
331 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
332 echo " -b base - defaults to $DEFAULT_BASE"
333 echo " @NAME@ replaced as appropriate"
334 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
335 echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
336 echo " -s svnpath - where to fetch the build module"
337 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
338 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
339 echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL"
340 echo " -y sign yum repo in webpath"
341 echo " -g path to gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
342 echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
343 echo " -m mailto - no default"
344 echo " -O : overwrite - re-run in base directory, do not re-create vserver"
345 echo " -B : run build only"
346 echo " -T : run test only"
347 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
348 echo " -v : be verbose"
349 echo " -7 : uses weekday-@FCDISTRO@ as base"
350 echo " -a makevar=value - space in values are not supported"
351 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
365 while getopts "f:d:p:b:t:r:s:x:c:w:W:g:u:m:OBTnyv7a:i:" opt ; do
367 f) FCDISTRO=$OPTARG ;;
368 d) PLDISTRO=$OPTARG ;;
369 p) PERSONALITY=$OPTARG ;;
371 t) PLDISTROTAGS=$OPTARG ;;
372 r) TAGSRELEASE=$OPTARG ;;
373 s) SVNPATH=$OPTARG ;;
374 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
375 w) WEBPATH=$OPTARG ;;
376 W) TESTBUILDURL=$OPTARG ;;
377 y) SIGNYUMREPO=true ;;
378 g) GPGPATH=$OPTARG ;;
381 O) OVERWRITEMODE=true ;;
383 T) DO_BUILD= ; OVERWRITEMODE=true ;;
386 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
387 a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
393 # preserve options for passing them again later, together with expanded base
395 toshift=$(($OPTIND - 1))
396 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
401 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
402 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
403 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
404 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
405 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
406 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
407 [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
408 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
409 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
410 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
411 [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
412 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
414 [ -n "$DRY_RUN" ] && MAILTO=""
416 ### set BASE from DISTRO, if unspecified
417 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
418 BASE=$(echo ${BASE} | sed $sedargs)
419 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
421 # where to store the log for web access
422 WEBLOG=${WEBPATH}/${BASE}.log.txt
423 # compute the log URL - inserted in the mail messages for convenience
424 LOG_URL=$(echo ${WEBLOG} | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
425 TESTLOGS_URL=$(echo ${WEBPATH}/${BASE}/testlogs | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
427 if ! in_root_context ; then
429 echo "==================== Within vserver BEG $(date)"
431 echo "==================== Within vserver END $(date)"
435 # we run in the root context :
436 # (*) create or check for the vserver to use
437 # (*) copy this command in the vserver
440 if [ -n "$OVERWRITEMODE" ] ; then
441 ### Re-use a vserver (finish an unfinished build..)
442 if [ ! -d /vservers/${BASE} ] ; then
443 echo $COMMAND : cannot find vserver $BASE
446 # manage LOG - beware it might be a symlink so nuke it first
447 LOG=/vservers/${BASE}.log.txt
451 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
453 # start in case e.g. we just rebooted
454 vserver ${BASE} start || :
456 vserver ${BASE} exec svn update /build
458 # create vserver: check it does not exist yet
460 while [ -d /vservers/${BASE}${i} ] ; do
461 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
462 [ -z ${i} ] && BASE=${BASE}-n
464 if [ $i -gt 100 ] ; then
465 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
471 # manage LOG - beware it might be a symlink so nuke it first
472 LOG=/vservers/${BASE}.log.txt
476 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
479 ### extract the whole build - much simpler
480 tmpdir=/tmp/$COMMAND-$$
481 svn export $SVNPATH $tmpdir
484 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
488 # Extract build again - in the vserver
489 vserver ${BASE} exec svn checkout ${SVNPATH} /build
491 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
493 # The log inside the vserver contains everything
494 LOG2=/vservers/${BASE}/log.txt
495 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
497 echo "==================== END VSERVER Transcript of vserver creation" ; \
498 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
499 ### not too nice : nuke the former log, symlink it to the new one
500 rm $LOG; ln -s $LOG2 $LOG
505 if [ -n "$DO_BUILD" ] ; then
507 cp $COMMANDPATH /vservers/${BASE}/build/
509 # invoke this command in the vserver for building (-T)
510 vserver ${BASE} exec chmod +x /build/$COMMAND
511 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" $MAKETARGETS
514 # publish to the web so runtest can find them
515 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
516 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
517 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
518 # publish myplc-release
519 rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
521 # create yum repo and sign packages.
522 if [ -n "$SIGNYUMREPO" ] ; then
526 if [ -n "$DO_TEST" ] ; then