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 TESTBUILDURL="http://build.one-lab.org/"
26 TESTBOXSSH=root@testbox.one-lab.org
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
101 WEBLOG=${WEBPATH}/${BASE}.log.txt
104 summary $LOG >> ${WEBLOG}
105 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
106 if [ -n "$MAILTO" ] ; then
107 tail -c 30k ${WEBLOG} | mail -s "Failures for build ${BASE}" $MAILTO
112 function success () {
114 WEBLOG=${WEBPATH}/${BASE}.log.txt
117 summary $LOG >> ${WEBLOG}
118 if [ -n "$DO_TEST" ] ; then
119 echo "Successfully built and tested - see testlogs for details" > ${WEBLOG}.pass
122 echo "Successfully built"> ${WEBLOG}.ok
124 if [ -n "$MAILTO" ] ; then
125 (echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ) | mail -s "Successful build for ${BASE}" $MAILTO
130 # run in the vserver - do not manage success/failure, will be done from the root ctx
135 echo -n "============================== Starting $COMMAND:build on "
139 # if TAGSRELEASE specified : update PLDISTROTAGS with this tag
140 if [ -n "$TAGSRELEASE" ] ; then
141 svn up -r $TAGSRELEASE $PLDISTROTAGS
146 echo "Running make IN $(pwd)"
148 # stuff our own variable settings
149 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
150 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
151 MAKEVARS=("NIGHTLY_BASE=${BASE}" "${MAKEVARS[@]}")
152 MAKEVARS=("NIGHTLY_PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
153 MAKEVARS=("build-SVNPATH=${SVNPATH}" "${MAKEVARS[@]}")
156 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
158 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
159 # store tests_svnpath
160 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
162 make -C /build $DRY_RUN "${MAKEVARS[@]}" $MAKETARGETS
166 # this was formerly run in the myplc-devel chroot but now is run in the root context,
167 # this is so that the .ssh config gets done manually, and once and for all
168 function runtest () {
173 echo -n "============================== Starting $COMMAND:runtest on $(date)"
175 # where to find TESTS_SVNPATH
176 stamp=/vservers/$BASE/build/tests_svnpath
177 if [ ! -f $stamp ] ; then
178 echo "$COMMAND: Cannot figure TESTS_SVNPATH from missing $stamp"
182 TESTS_SVNPATH=$(cat $stamp)
183 # xxx - Thierry - need to rework the test framework in tests/system so it can work
184 # with the entire tests/ module checked out, rather than only tests/system/
185 # ugly workaround for now
186 SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
188 ### the URL to the RPMS/<arch> location
190 for a in i386 x86_64; do
191 archdir=/vservers/$BASE/build/RPMS/$a
192 if [ -d $archdir ] ; then
193 url=$(echo $archdir | sed -e "s,/vservers/$BASE/build,${TESTBUILDURL}${PLDISTRO}/${BASE},")
198 if [ -z "$url" ] ; then
199 echo "$COMMAND: Cannot locate arch URL for testing"
204 # test directory name on test box
207 ssh -n ${TESTBOXSSH} rm -rf ${testdir}
209 ssh -n ${TESTBOXSSH} svn co ${SYSTEM_SVNPATH} ${testdir}
210 # check out the entire tests/ module (with system/ duplicated) as a subdir - see xxx above
211 ssh -n ${TESTBOXSSH} svn co ${TESTS_SVNPATH} ${testdir}/tests
212 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
214 for config in ${TESTCONFIG} ; do
215 configs="$configs --config $config"
218 # need to proceed despite of set -e
220 ssh 2>&1 -n ${TESTBOXSSH} ${testdir}/runtest --build ${SVNPATH} --url ${url} $configs --all || success=
222 # gather logs in the vserver
223 mkdir -p /vservers/$BASE/build/testlogs
224 ssh 2>&1 -n ${TESTBOXSSH} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
225 # push them to the build web
226 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
227 chmod -R a+r $WEBPATH/$BASE/testlogs/
229 if [ -z "$success" ] ; then
233 echo -n "============================== End $COMMAND:runtest on $(date)"
236 function in_root_context () {
237 rpm -q util-vserver > /dev/null
240 function show_env () {
242 echo FCDISTRO=$FCDISTRO
243 echo PLDISTRO=$PLDISTRO
245 echo SVNPATH=$SVNPATH
246 echo MAKEVARS="${MAKEVARS[@]}"
247 echo DRY_RUN="$DRY_RUN"
248 echo PLDISTROTAGS="$PLDISTROTAGS"
249 echo TAGSRELEASE="$TAGSRELEASE"
250 echo -n "(might be unexpanded)"
251 echo WEBPATH="$WEBPATH"
252 if in_root_context ; then
253 echo PLDISTROTAGS="$PLDISTROTAGS"
255 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
256 cat /build/$PLDISTROTAGS
257 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
263 echo "Usage: $COMMAND [option] make-targets"
264 echo "This is $REVISION"
265 echo "Supported options"
266 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
267 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
268 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
269 echo " -b base - defaults to $DEFAULT_BASE"
270 echo " @NAME@ replaced as appropriate"
271 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
272 echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
273 echo " -s svnpath - where to fetch the build module"
274 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
275 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
276 echo " -y create (and sign) yum repo in webpath"
277 echo " -g path to gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
278 echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
279 echo " -m mailto - no default"
280 echo " -O : overwrite - re-run in base directory, do not re-create vserver"
281 echo " -B : run build only"
282 echo " -T : run test only"
283 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
284 echo " -v : be verbose"
285 echo " -7 : uses weekday-@FCDISTRO@ as base"
286 echo " -a makevar=value - space in values are not supported"
287 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
300 while getopts "f:d:p:b:t:r:s:x:c:w:g:u:m:OBTnyv7a:i:" opt ; do
302 f) FCDISTRO=$OPTARG ;;
303 d) PLDISTRO=$OPTARG ;;
304 p) PERSONALITY=$OPTARG ;;
306 t) PLDISTROTAGS=$OPTARG ;;
307 r) TAGSRELEASE=$OPTARG ;;
308 s) SVNPATH=$OPTARG ;;
309 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
310 w) WEBPATH=$OPTARG ;;
311 y) MKYUMREPO=$OPTARG;;
315 O) OVERWRITEMODE=true ;;
317 T) DO_BUILD= ; OVERWRITEMODE=true ;;
320 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
321 a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
327 # preserve options for passing them again later, together with expanded base
329 toshift=$(($OPTIND - 1))
330 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
335 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
336 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
337 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
338 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
339 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
340 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
341 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
342 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
343 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
344 [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
345 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
347 [ -n "$DRY_RUN" ] && MAILTO=""
349 ### set BASE from DISTRO, if unspecified
350 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
351 BASE=$(echo ${BASE} | sed $sedargs)
352 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
354 if ! in_root_context ; then
356 echo "==================== Within vserver BEG $(date)"
358 echo "==================== Within vserver END $(date)"
362 # we run in the root context :
363 # (*) create or check for the vserver to use
364 # (*) copy this command in the vserver
367 if [ -n "$OVERWRITEMODE" ] ; then
368 ### Re-use a vserver (finish an unfinished build..)
369 if [ ! -d /vservers/${BASE} ] ; then
370 echo $COMMAND : cannot find vserver $BASE
373 # manage LOG - beware it might be a symlink so nuke it first
374 LOG=/vservers/${BASE}.log.txt
378 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
380 # start in case e.g. we just rebooted
381 vserver ${BASE} start || :
383 vserver ${BASE} exec svn update /build
385 # create vserver: check it does not exist yet
387 while [ -d /vservers/${BASE}${i} ] ; do
388 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
389 [ -z ${i} ] && BASE=${BASE}-n
391 if [ $i -gt 100 ] ; then
392 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
398 # manage LOG - beware it might be a symlink so nuke it first
399 LOG=/vservers/${BASE}.log.txt
403 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
406 ### extract the whole build - much simpler
407 tmpdir=/tmp/$COMMAND-$$
408 svn export $SVNPATH $tmpdir
411 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
415 # Extract build again - in the vserver
416 vserver ${BASE} exec svn checkout ${SVNPATH} /build
418 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
420 # The log inside the vserver contains everything
421 LOG2=/vservers/${BASE}/log.txt
422 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
424 echo "==================== END VSERVER Transcript of vserver creation" ; \
425 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
426 ### not too nice : nuke the former log, symlink it to the new one
427 rm $LOG; ln -s $LOG2 $LOG
432 if [ -n "$DO_BUILD" ] ; then
434 cp $COMMANDPATH /vservers/${BASE}/build/
436 # invoke this command in the vserver for building (-T)
437 vserver ${BASE} exec chmod +x /build/$COMMAND
438 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" $MAKETARGETS
441 # publish to the web so runtest can find them
442 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
443 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
444 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
445 # publish myplc-release
446 rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
448 # create yum repo and sign packages.
449 if [ -n $MKYUMREPO ] ; then
450 echo "Signing signing node packages"
452 ### availability of repo indexing tools
453 # old one - might be needed for old-style nodes
454 type -p yum-arch > /dev/null && have_yum_arch="true"
456 type -p createrepo > /dev/null && have_createrepo="true"
458 repository=$WEBPATH/$BASE/RPMS/
459 # the rpms that need signing
461 # and the corresponding stamps
463 # is there a need to refresh yum metadata
467 # right after installation, no package is present
468 # but we still need to create index
469 [ -n "$have_yum_arch" -a ! -f $repository/headers/header.info ] && need_yum_arch=true
470 [ -n "$have_createrepo" -a ! -f $repository/repodata/repomd.xml ] && need_createrepo=true
472 for package in $(find $repository/ -name '*.rpm') ; do
473 stamp=$repository/signed-stamps/$(basename $package).signed
474 # If package is newer than signature stamp
475 if [ $package -nt $stamp ] ; then
476 new_rpms="$new_rpms $package"
477 new_stamps="$new_stamps $stamp"
479 # Or than yum-arch headers
480 [ -n "$have_yum_arch" ] && [ $package -nt $repository/headers/header.info ] && need_yum_arch=true
481 # Or than createrepo database
482 [ -n "$have_createrepo" ] && [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
485 if [ -n "$new_rpms" ] ; then
486 # Create a stamp once the package gets signed
487 mkdir $repository/signed-stamps 2> /dev/null
489 # Sign RPMS. setsid detaches rpm from the terminal,
490 # allowing the (hopefully blank) GPG password to be
491 # entered from stdin instead of /dev/tty.
493 --define "_signature gpg" \
494 --define "_gpg_path $GPGPATH" \
495 --define "_gpg_name $GPGUID" \
496 --resign $new_rpms && touch $new_stamps
499 # Update repository index / yum metadata.
501 if [ -n "$need_yum_arch" ] ; then
502 # yum-arch sometimes leaves behind
503 # .oldheaders and .olddata directories accidentally.
504 rm -rf $repository/{.oldheaders,.olddata}
508 if [ -n "$need_createrepo" ] ; then
509 if [ -f $repository/yumgroups.xml ] ; then
510 createrepo --quiet -g yumgroups.xml $repository
512 createrepo --quiet $repository
518 if [ -n "$DO_TEST" ] ; then