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_TESTSVNPATH="http://svn.planet-lab.org/svn/tests/trunk/system/"
14 DEFAULT_TESTCONFIG="default"
17 # web publishing results
18 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
21 TESTBUILDURL="http://build.one-lab.org/"
22 TESTBOXSSH=root@testbox.one-lab.org
24 # assuming vserver runs in UTC
25 DATE=$(date +'%Y.%m.%d')
27 # temporary - wrap a quick summary of suspicious stuff
28 # this is to focus on installation that go wrong
29 # use with care, a *lot* of other things can go bad as well
32 echo "******************** BEG SUMMARY"
35 # read a full log and tries to extract the interesting stuff
38 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*")
39 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
40 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
41 m_installing_end=re.compile('Installed:.*')
42 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
43 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
45 def summary (filename):
54 for line in f.xreadlines():
55 # first off : discard warnings related to doc
56 if m_installing_doc1.match(line):
57 (begin,end)=m_installing_doc1.match(line).groups()
59 if m_installing_doc2.match(line):
60 (begin,end)=m_installing_doc2.match(line).groups()
62 # unconditionnally show these lines
63 if m_show_line.match(line):
65 # an 'installing' line with messages afterwards : needs to be echoed
66 elif m_installing_err.match(line):
67 (installing,error)=m_installing_err.match(line).groups()
68 print '>>>',installing
71 # closing an 'installing' section
72 elif m_installing_end.match(line):
74 # any 'installing' line
75 elif m_installing_any.match(line):
77 installing=m_installing_any.match(line).group(1)
78 print '>>>',installing
80 # print lines when echo is true
82 if echo: print '>>>',line,
85 print 'Failed to analyze',filename
87 for arg in sys.argv[1:]:
90 echo "******************** END SUMMARY"
94 # Notify recipient of failure or success, manage various stamps
97 WEBLOG=${WEBPATH}/${BASE}.log.txt
100 summary $LOG >> ${WEBLOG}
101 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
102 if [ -n "$MAILTO" ] ; then
103 tail -c 30k ${WEBLOG} | mail -s "Failures for build ${BASE}" $MAILTO
108 function success () {
110 WEBLOG=${WEBPATH}/${BASE}.log.txt
113 summary $LOG >> ${WEBLOG}
114 if [ -n "$DO_TEST" ] ; then
115 echo "Successfully built and tested - see testlogs for details" > ${WEBLOG}.pass
118 echo "Successfully built"> ${WEBLOG}.ok
120 if [ -n "$MAILTO" ] ; then
121 (echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ) | mail -s "Successful build for ${BASE}" $MAILTO
126 # run in the vserver - do not manage success/failure, will be done from the root ctx
131 echo -n "============================== Starting $COMMAND:build on "
135 # if TAGSRELEASE specified : update PLDISTROTAGS with this tag
136 if [ -n "$TAGSRELEASE" ] ; then
137 svn up -r $TAGSRELEASE $PLDISTROTAGS
142 echo "Running make IN $(pwd)"
144 # stuff our own variable settings
145 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
146 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
147 MAKEVARS=("NIGHTLY_BASE=${BASE}" "${MAKEVARS[@]}")
148 MAKEVARS=("NIGHTLY_PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
151 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
153 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
155 make -C /build $DRY_RUN "${MAKEVARS[@]}" $MAKETARGETS
159 # this was formerly run in the myplc-devel chroot but now is run in the root context,
160 # this is so that the .ssh config gets done manually, and once and for all
161 function runtest () {
166 echo -n "============================== Starting $COMMAND:runtest on $(date)"
168 ### the URL to the myplc package
169 rpm=$( find /vservers/$BASE/build/RPMS -name 'myplc-[0-9]*' )
170 if [ ${#rpm[@]} != 1 ] ; then
171 echo "$COMMAND: Cannot locate rpm for testing"
175 url=$(echo $rpm | sed -e "s,/vservers/$BASE/build,${TESTBUILDURL}${PLDISTRO}/${BASE},")
177 # compute test directory name on test box
178 testdir=chroot-${BASE}
179 # use another name if any config contains vserver
180 echo $TESTCONFIG | grep vserver &> /dev/null && testdir=vserver-${BASE}
182 ssh ${TESTBOXSSH} rm -rf ${testdir}
184 ssh ${TESTBOXSSH} svn co ${TESTSVNPATH} ${testdir}
185 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
187 for config in ${TESTCONFIG} ; do
188 configs="$configs --config $config"
191 # need to proceed despite of set -e
193 ssh 2>&1 ${TESTBOXSSH} ${testdir}/runtest --build ${SVNPATH} --url ${url} $configs --all || success=
195 # gather logs in the vserver
196 mkdir -p /vservers/$BASE/build/testlogs
197 ssh 2>&1 ${TESTBOXSSH} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
198 # push them to the build web
199 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
200 chmod -R a+r $WEBPATH/$BASE/testlogs/
202 if [ -z "$success" ] ; then
206 echo -n "============================== End $COMMAND:runtest on $(date)"
209 function show_env () {
211 echo FCDISTRO=$FCDISTRO
212 echo PLDISTRO=$PLDISTRO
214 echo SVNPATH=$SVNPATH
215 echo MAKEVARS="${MAKEVARS[@]}"
216 echo DRY_RUN="$DRY_RUN"
217 echo PLDISTROTAGS="$PLDISTROTAGS"
218 echo TAGSRELEASE="$TAGSRELEASE"
219 echo -n "(might be unexpanded)"
220 echo WEBPATH="$WEBPATH"
221 if [ -d /vservers ] ; then
222 echo PLDISTROTAGS="$PLDISTROTAGS"
224 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
225 cat /build/$PLDISTROTAGS
226 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
232 echo "Usage: $COMMAND [option] make-targets"
233 echo "This is $REVISION"
234 echo "Supported options"
235 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
236 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
237 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
238 echo " -b base - defaults to $DEFAULT_BASE"
239 echo " @NAME@ replaced as appropriate"
240 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
241 echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
242 echo " -s svnpath - where to fetch the build module"
243 echo " -x testsvnpath - defaults to $DEFAULT_TESTSVNPATH"
244 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
245 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
246 echo " -m mailto - no default"
247 echo " -O : overwrite - re-run in base directory, do not re-create vserver"
248 echo " -B : run build only"
249 echo " -T : run test only"
250 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
251 echo " -v : be verbose"
252 echo " -7 : uses weekday-@FCDISTRO@ as base"
253 echo " -a makevar=value - space in values are not supported"
254 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
267 while getopts "f:d:p:b:t:r:s:x:c:w:m:OBTnv7a:i:" opt ; do
269 f) FCDISTRO=$OPTARG ;;
270 d) PLDISTRO=$OPTARG ;;
271 p) PERSONALITY=$OPTARG ;;
273 t) PLDISTROTAGS=$OPTARG ;;
274 r) TAGSRELEASE=$OPTARG ;;
275 s) SVNPATH=$OPTARG ;;
276 x) TESTSVNPATH=$OPTARG ;;
277 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
278 w) WEBPATH=$OPTARG ;;
280 O) OVERWRITEMODE=true ;;
282 T) DO_BUILD= ; OVERWRITEMODE=true ;;
285 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
286 a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
292 # preserve options for passing them again later, together with expanded base
294 toshift=$(($OPTIND - 1))
295 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
300 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
301 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
302 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
303 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
304 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
305 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
306 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
307 [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
308 [ -z "$TESTSVNPATH" ] && TESTSVNPATH="$DEFAULT_TESTSVNPATH"
309 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
311 [ -n "$DRY_RUN" ] && MAILTO=""
313 ### set BASE from DISTRO, if unspecified
314 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
315 BASE=$(echo ${BASE} | sed $sedargs)
316 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
318 if [ ! -d /vservers ] ; then
320 echo "==================== Within vserver BEG $(date)"
322 echo "==================== Within vserver END $(date)"
326 # we run in the root context :
327 # (*) create or check for the vserver to use
328 # (*) copy this command in the vserver
331 if [ -n "$OVERWRITEMODE" ] ; then
332 ### Re-use a vserver (finish an unfinished build..)
333 if [ ! -d /vservers/${BASE} ] ; then
334 echo $COMMAND : cannot find vserver $BASE
337 # manage LOG - beware it might be a symlink so nuke it first
338 LOG=/vservers/${BASE}.log.txt
342 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
345 vserver ${BASE} exec svn update /build
347 # create vserver: check it does not exist yet
349 while [ -d /vservers/${BASE}${i} ] ; do
350 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
351 [ -z ${i} ] && BASE=${BASE}-n
353 if [ $i -gt 100 ] ; then
354 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
360 # manage LOG - beware it might be a symlink so nuke it first
361 LOG=/vservers/${BASE}.log.txt
365 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
368 ### extract the whole build - much simpler
369 tmpdir=/tmp/$COMMAND-$$
370 svn export $SVNPATH $tmpdir
373 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
377 # Extract build again - in the vserver
378 vserver ${BASE} exec svn checkout ${SVNPATH} /build
380 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
382 # The log inside the vserver contains everything
383 LOG2=/vservers/${BASE}/log.txt
384 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
386 echo "==================== END VSERVER Transcript of vserver creation" ; \
387 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
388 ### not too nice : nuke the former log, symlink it to the new one
389 rm $LOG; ln -s $LOG2 $LOG
394 if [ -n "$DO_BUILD" ] ; then
396 cp $COMMANDPATH /vservers/${BASE}/build/
398 # invoke this command in the vserver for building (-T)
399 vserver ${BASE} exec chmod +x /build/$COMMAND
400 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" $MAKETARGETS
403 # publish to the web so runtest can find them
404 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
405 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
406 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
408 if [ -n "$DO_TEST" ] ; then