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 # test directory name on test box
180 ssh ${TESTBOXSSH} rm -rf ${testdir}
182 ssh ${TESTBOXSSH} svn co ${TESTSVNPATH} ${testdir}
183 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
185 for config in ${TESTCONFIG} ; do
186 configs="$configs --config $config"
189 # need to proceed despite of set -e
191 ssh 2>&1 ${TESTBOXSSH} ${testdir}/runtest --build ${SVNPATH} --url ${url} $configs --all || success=
193 # gather logs in the vserver
194 mkdir -p /vservers/$BASE/build/testlogs
195 ssh 2>&1 ${TESTBOXSSH} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
196 # push them to the build web
197 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
198 chmod -R a+r $WEBPATH/$BASE/testlogs/
200 if [ -z "$success" ] ; then
204 echo -n "============================== End $COMMAND:runtest on $(date)"
207 function show_env () {
209 echo FCDISTRO=$FCDISTRO
210 echo PLDISTRO=$PLDISTRO
212 echo SVNPATH=$SVNPATH
213 echo MAKEVARS="${MAKEVARS[@]}"
214 echo DRY_RUN="$DRY_RUN"
215 echo PLDISTROTAGS="$PLDISTROTAGS"
216 echo TAGSRELEASE="$TAGSRELEASE"
217 echo -n "(might be unexpanded)"
218 echo WEBPATH="$WEBPATH"
219 if [ -d /vservers ] ; then
220 echo PLDISTROTAGS="$PLDISTROTAGS"
222 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
223 cat /build/$PLDISTROTAGS
224 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
230 echo "Usage: $COMMAND [option] make-targets"
231 echo "This is $REVISION"
232 echo "Supported options"
233 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
234 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
235 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
236 echo " -b base - defaults to $DEFAULT_BASE"
237 echo " @NAME@ replaced as appropriate"
238 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
239 echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
240 echo " -s svnpath - where to fetch the build module"
241 echo " -x testsvnpath - defaults to $DEFAULT_TESTSVNPATH"
242 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
243 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
244 echo " -m mailto - no default"
245 echo " -O : overwrite - re-run in base directory, do not re-create vserver"
246 echo " -B : run build only"
247 echo " -T : run test only"
248 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
249 echo " -v : be verbose"
250 echo " -7 : uses weekday-@FCDISTRO@ as base"
251 echo " -a makevar=value - space in values are not supported"
252 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
265 while getopts "f:d:p:b:t:r:s:x:c:w:m:OBTnv7a:i:" opt ; do
267 f) FCDISTRO=$OPTARG ;;
268 d) PLDISTRO=$OPTARG ;;
269 p) PERSONALITY=$OPTARG ;;
271 t) PLDISTROTAGS=$OPTARG ;;
272 r) TAGSRELEASE=$OPTARG ;;
273 s) SVNPATH=$OPTARG ;;
274 x) TESTSVNPATH=$OPTARG ;;
275 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
276 w) WEBPATH=$OPTARG ;;
278 O) OVERWRITEMODE=true ;;
280 T) DO_BUILD= ; OVERWRITEMODE=true ;;
283 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
284 a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
290 # preserve options for passing them again later, together with expanded base
292 toshift=$(($OPTIND - 1))
293 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
298 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
299 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
300 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
301 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
302 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
303 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
304 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
305 [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
306 [ -z "$TESTSVNPATH" ] && TESTSVNPATH="$DEFAULT_TESTSVNPATH"
307 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
309 [ -n "$DRY_RUN" ] && MAILTO=""
311 ### set BASE from DISTRO, if unspecified
312 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
313 BASE=$(echo ${BASE} | sed $sedargs)
314 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
316 if [ ! -d /vservers ] ; then
318 echo "==================== Within vserver BEG $(date)"
320 echo "==================== Within vserver END $(date)"
324 # we run in the root context :
325 # (*) create or check for the vserver to use
326 # (*) copy this command in the vserver
329 if [ -n "$OVERWRITEMODE" ] ; then
330 ### Re-use a vserver (finish an unfinished build..)
331 if [ ! -d /vservers/${BASE} ] ; then
332 echo $COMMAND : cannot find vserver $BASE
335 # manage LOG - beware it might be a symlink so nuke it first
336 LOG=/vservers/${BASE}.log.txt
340 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
343 vserver ${BASE} exec svn update /build
345 # create vserver: check it does not exist yet
347 while [ -d /vservers/${BASE}${i} ] ; do
348 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
349 [ -z ${i} ] && BASE=${BASE}-n
351 if [ $i -gt 100 ] ; then
352 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
358 # manage LOG - beware it might be a symlink so nuke it first
359 LOG=/vservers/${BASE}.log.txt
363 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
366 ### extract the whole build - much simpler
367 tmpdir=/tmp/$COMMAND-$$
368 svn export $SVNPATH $tmpdir
371 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
375 # Extract build again - in the vserver
376 vserver ${BASE} exec svn checkout ${SVNPATH} /build
378 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
380 # The log inside the vserver contains everything
381 LOG2=/vservers/${BASE}/log.txt
382 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
384 echo "==================== END VSERVER Transcript of vserver creation" ; \
385 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
386 ### not too nice : nuke the former log, symlink it to the new one
387 rm $LOG; ln -s $LOG2 $LOG
392 if [ -n "$DO_BUILD" ] ; then
394 cp $COMMANDPATH /vservers/${BASE}/build/
396 # invoke this command in the vserver for building (-T)
397 vserver ${BASE} exec chmod +x /build/$COMMAND
398 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" $MAKETARGETS
401 # publish to the web so runtest can find them
402 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
403 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
404 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
406 if [ -n "$DO_TEST" ] ; then