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"
14 # web publishing results
15 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
18 TESTBUILDURL="http://build.one-lab.org/"
19 TESTBOX=onelab-test.inria.fr
20 TESTBOXSSH=root@onelab-test.inria.fr
21 TESTSVNPATH="http://svn.planet-lab.org/svn/tests/trunk/system/"
23 # assuming vserver runs in UTC
24 DATE=$(date +'%Y.%m.%d')
26 # temporary - wrap a quick summary of suspicious stuff
27 # this is to focus on installation that go wrong
28 # use with care, a *lot* of other things can go bad as well
31 echo "******************** BEG SUMMARY"
34 # read a full log and tries to extract the interesting stuff
37 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*")
38 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
39 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
40 m_installing_end=re.compile('Installed:.*')
41 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
42 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
44 def summary (filename):
53 for line in f.xreadlines():
54 # first off : discard warnings related to doc
55 if m_installing_doc1.match(line):
56 (begin,end)=m_installing_doc1.match(line).groups()
58 if m_installing_doc2.match(line):
59 (begin,end)=m_installing_doc2.match(line).groups()
61 # unconditionnally show these lines
62 if m_show_line.match(line):
64 # an 'installing' line with messages afterwards : needs to be echoed
65 elif m_installing_err.match(line):
66 (installing,error)=m_installing_err.match(line).groups()
67 print '>>>',installing
70 # closing an 'installing' section
71 elif m_installing_end.match(line):
73 # any 'installing' line
74 elif m_installing_any.match(line):
76 installing=m_installing_any.match(line).group(1)
77 print '>>>',installing
79 # print lines when echo is true
81 if echo: print '>>>',line,
84 print 'Failed to analyze',filename
86 for arg in sys.argv[1:]:
89 echo "******************** END SUMMARY"
93 # Notify recipient of failure or success, manage various stamps
96 WEBLOG=${WEBPATH}/${BASE}.log.txt
98 summary $LOG >> ${WEBLOG}
99 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 20k $WEBLOG) > ${WEBLOG}.ko
100 if [ -n "$MAILTO" ] ; then
101 tail -c 20k ${WEBLOG} | mail -s "Failures for build ${BASE}" $MAILTO
106 function success () {
108 WEBLOG=${WEBPATH}/${BASE}.log.txt
110 summary $LOG >> ${WEBLOG}
112 if [ -n "$MAILTO" ] ; then
113 (echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ) | mail -s "Successful build for ${BASE}" $MAILTO
118 # run in the vserver - do not manage success/failure, will be done from the root ctx
123 echo -n "============================== Starting $COMMAND:build on "
127 # if TAGSRELEASE specified : update PLDISTROTAGS with this tag
128 if [ -n "$TAGSRELEASE" ] ; then
129 svn up -r $TAGSRELEASE $PLDISTROTAGS
134 echo "Running make IN $(pwd)"
136 # stuff our own variable settings
137 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
138 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
139 MAKEVARS=("NIGHTLY_BASE=${BASE}" "${MAKEVARS[@]}")
140 MAKEVARS=("NIGHTLY_PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
143 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
145 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
147 make -C /build $DRY_RUN "${MAKEVARS[@]}" $MAKETARGETS
151 # this was formerly run in the myplc-devel chroot but now is run in the root context,
152 # this is so that the .ssh config gets done manually, and once and for all
153 function runtest () {
158 echo -n "============================== Starting $COMMAND:runtest on $(date)"
160 ### the URL to the myplc package
161 rpm=$( (cd /vservers/$BASE/build/RPMS/i386 ; ls myplc-[0-9]*.rpm) )
162 if [ ${#rpm[@]} != 1 ] ; then
163 echo "$COMMAND: Cannot locate rpm for testing"
167 url=${TESTBUILDURL}${PLDISTRO}/${BASE}/RPMS/i386/${rpm}
169 # compute test directory name on test box
172 ssh ${TESTBOXSSH} rm -rf ${testdir}
174 ssh ${TESTBOXSSH} svn co ${TESTSVNPATH} ${testdir}
175 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
176 ssh 2>&1 ${TESTBOXSSH} python -u ${testdir}/runtest --build ${SVNPATH} --url ${url} --all
177 # still missing - need to populate /var/www/html/install-rpms on the myplc
179 if [ "$?" != 0 ] ; then
183 echo -n "============================== End $COMMAND:runtest on $(date)"
186 function show_env () {
188 echo FCDISTRO=$FCDISTRO
189 echo PLDISTRO=$PLDISTRO
191 echo SVNPATH=$SVNPATH
192 echo MAKEVARS="${MAKEVARS[@]}"
193 echo DRY_RUN="$DRY_RUN"
194 echo PLDISTROTAGS="$PLDISTROTAGS"
195 echo TAGSRELEASE="$TAGSRELEASE"
196 echo -n "(might be unexpanded)"
197 echo WEBPATH="$WEBPATH"
198 if [ -d /vservers ] ; then
199 echo PLDISTROTAGS="$PLDISTROTAGS"
201 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
202 cat /build/$PLDISTROTAGS
203 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
209 echo "Usage: $COMMAND [option] make-targets"
210 echo "This is $REVISION"
211 echo "Supported options"
212 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
213 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
214 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
215 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
216 echo " -b base - defaults to $DEFAULT_BASE"
217 echo " @NAME@ replaced as appropriate"
218 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
219 echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
220 echo " -s svnpath - where to fetch the build module"
221 echo " -o : overwrite - re-run in base directory, do not create vserver"
223 echo " -a makevar=value - space in values are not supported"
224 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
225 echo " -B : run build only"
226 echo " -T : run test only"
227 echo " -v : be verbose"
228 echo " -7 : uses weekday-@FCDISTRO@ as base"
236 # preserve arguments for passing them again later
238 for arg in "$@"; do argv=(${argv[@]} "$arg") ; done
245 while getopts "nf:d:b:p:t:r:s:om:a:w:BTvh7" opt ; do
248 f) FCDISTRO=$OPTARG ;;
249 d) PLDISTRO=$OPTARG ;;
250 p) PERSONALITY=$OPTARG ;;
252 t) PLDISTROTAGS=$OPTARG ;;
253 r) TAGSRELEASE=$OPTARG ;;
254 s) SVNPATH=$OPTARG ;;
255 o) OVERWRITEMODE=true ;;
257 a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
258 w) WEBPATH=$OPTARG ;;
260 T) DO_BUILD= ; OVERWRITEMODE=true ;;
262 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
267 shift $(($OPTIND - 1))
271 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
272 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
273 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
274 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
275 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
276 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
277 [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
279 [ -n "$DRY_RUN" ] && MAILTO=""
281 ### set BASE from DISTRO, if unspecified
282 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
283 BASE=$(echo ${BASE} | sed $sedargs)
284 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
286 if [ ! -d /vservers ] ; then
288 echo "==================== Within vserver BEG $(date)"
290 echo "==================== Within vserver END $(date)"
294 # we run in the root context :
295 # (*) create or check for the vserver to use
296 # (*) copy this command in the vserver
299 if [ -n "$OVERWRITEMODE" ] ; then
300 ### Re-use a vserver (finish an unfinished build..)
301 if [ ! -d /vservers/${BASE} ] ; then
302 echo $COMMAND : cannot find vserver $BASE
305 # manage LOG - beware it might be a symlink so nuke it first
306 LOG=/vservers/${BASE}.log.txt
310 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
313 vserver ${BASE} exec svn update /build
315 # create vserver: check it does not exist yet
317 while [ -d /vservers/${BASE}${i} ] ; do
318 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
319 [ -z ${i} ] && BASE=${BASE}-n
321 if [ $i -gt 100 ] ; then
322 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
328 # manage LOG - beware it might be a symlink so nuke it first
329 LOG=/vservers/${BASE}.log.txt
333 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
336 ### extract the whole build - much simpler
337 tmpdir=/tmp/$COMMAND-$$
338 svn export $SVNPATH $tmpdir
341 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} ${BASE}
345 # Extract build again - in the vserver
346 vserver ${BASE} exec svn checkout ${SVNPATH} /build
348 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
350 # The log inside the vserver contains everything
351 LOG2=/vservers/${BASE}/log.txt
352 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
354 echo "==================== END VSERVER Transcript of vserver creation" ; \
355 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
356 ### not too nice : nuke the former log, symlink it to the new one
357 rm $LOG; ln -s $LOG2 $LOG
362 if [ -n "$DO_BUILD" ] ; then
364 cp $COMMANDPATH /vservers/${BASE}/build/
366 # invoke this command in the vserver for building (-T)
367 vserver ${BASE} exec chmod +x /build/$COMMAND
368 vserver ${BASE} exec /build/$COMMAND "${argv[@]}" -b "${BASE}"
371 # publish to the web so runtest can find them
372 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
373 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
374 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
376 if [ -n "$DO_TEST" ] ; then