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 # NOTE: do not think we want to put email addresses into scripts
15 # that can be harvested by spambots. --mef
16 DEFAULT_MAILTO="onelab-build@one-lab.org"
18 # web publishing results
19 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
22 TESTBUILDURL="http://build.one-lab.org/"
23 TESTBOX=onelab-test.inria.fr
24 TESTBOXSSH=root@onelab-test.inria.fr
25 TESTSVNPATH="http://svn.planet-lab.org/svn/tests/trunk/system/"
26 TESTSCRIPT=TestMain.py
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"
38 # read a full log and tries to extract the interesting stuff
41 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*")
42 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
43 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
44 m_installing_end=re.compile('Installed:.*')
45 m_installing_doc=re.compile(".*such file or directory for /usr/share/info.*")
47 def scan_log (filename):
56 for line in f.xreadlines():
57 if m_show_line.match(line):
59 elif m_installing_err.match(line):
60 (installing,error)=m_installing_err.match(line).groups()
64 elif m_installing_end.match(line):
66 elif m_installing_any.match(line):
68 installing=m_installing_any.match(line).group(1)
75 print 'Failed to analyze',filename
77 for arg in sys.argv[1:]:
80 echo "******************** END SUMMARY"
84 # Notify recipient of failure or success, manage various stamps
87 WEBLOG=${WEBPATH}/${BASE}.log.txt
89 summary $LOG >> ${WEBLOG}
90 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 20k $WEBLOG) > ${WEBLOG}.ko
91 if [ -n "$MAILTO" ] ; then
92 tail -c 20k ${WEBPATH}/${BASE}.log.txt | mail -s "Failures for build ${BASE}" $MAILTO
99 WEBLOG=${WEBPATH}/${BASE}.log.txt
101 summary $LOG >> ${WEBLOG}
103 if [ -n "$MAILTO" ] ; then
104 (echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ) | mail -s "Successfull build for ${BASE}" $MAILTO
109 # run in the vserver - do not manage success/failure, will be done from the root ctx
114 echo -n "============================== Starting $COMMAND:build on "
118 # if TAGSRELEASE specified : update PLDISTROTAGS with this tag
119 if [ -n "$TAGSRELEASE" ] ; then
120 svn up -r $TAGSRELEASE $PLDISTROTAGS
125 echo "Running make IN $(pwd)"
127 make -C /build "${MAKEOPTS[@]}" PLDISTROTAGS=${PLDISTROTAGS} PLDISTRO=${PLDISTRO} "${MAKEVARS[@]}" stage1=true
129 make -C /build "${MAKEOPTS[@]}" PLDISTROTAGS=${PLDISTROTAGS} PLDISTRO=${PLDISTRO} "${MAKEVARS[@]}" NIGHTLY_BASE=${BASE} versions
131 make -C /build "${MAKEOPTS[@]}" PLDISTROTAGS=${PLDISTROTAGS} PLDISTRO=${PLDISTRO} "${MAKEVARS[@]}" $MAKETARGETS
135 # this was formerly run in the myplc-devel chroot but now is run in the root context,
136 # this is so that the .ssh config gets done manually, and once and for all
137 function runtest () {
142 echo -n "============================== Starting $COMMAND:runtest on $(date)"
144 ### the URL to the myplc package
145 rpm=$( (cd /vservers/$BASE/build/RPMS/i386 ; ls myplc-[0-9]*.rpm) )
146 if [ ${#rpm[@]} != 1 ] ; then
147 echo "$COMMAND: Cannot locate rpm for testing"
151 rpms_url=${TESTBUILDURL}${PLDISTRO}/${BASE}/RPMS/
152 url=${TESTBUILDURL}${PLDISTRO}/${BASE}/RPMS/i386/${rpm}
154 # compute test directory name on test box
157 ssh ${TESTBOXSSH} rm -rf ${testdir}
159 ssh ${TESTBOXSSH} svn co ${TESTSVNPATH} ${testdir}
160 # store the myplc http url in the newly created test dir - for testing in chroot mode
161 echo ${url} | ssh ${TESTBOXSSH} "cat > ${testdir}/MYPLC-URL"
162 # store the build svn path in the newly created test dir - so it can perform myplc-init-vserver
163 echo ${SVNPATH} | ssh ${TESTBOXSSH} "cat > ${testdir}/BUILD-URL"
164 # store the rpms http url in the newly created test dir - for passing to myplc-init-vserver
165 echo ${rpms_url} | ssh ${TESTBOXSSH} "cat > ${testdir}/RPMS-URL"
166 # invoke test on testbox
167 ssh 2>&1 ${TESTBOXSSH} python -u ${testdir}/${TESTSCRIPT} ${url}
168 # still missing - need to populate /var/www/html/install-rpms on the myplc
170 if [ "$?" != 0 ] ; then
174 echo -n "============================== End $COMMAND:runtest on $(date)"
177 function show_env () {
179 echo FCDISTRO=$FCDISTRO
180 echo PLDISTRO=$PLDISTRO
182 echo SVNPATH=$SVNPATH
183 echo MAKEVARS="${MAKEVARS[@]}"
184 echo MAKEOPTS="${MAKEOPTS[@]}"
185 echo PLDISTROTAGS="$PLDISTROTAGS"
186 echo TAGSRELEASE="$TAGSRELEASE"
187 echo -n "(might be unexpanded)"
188 echo WEBPATH="$WEBPATH"
189 if [ -d /vservers ] ; then
190 echo PLDISTROTAGS="$PLDISTROTAGS"
192 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
193 cat /build/$PLDISTROTAGS
194 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
200 echo "Usage: $COMMAND [option] make-targets"
201 echo "This is $REVISION"
202 echo "Supported options"
203 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
204 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
205 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
206 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
207 echo " -b base - defaults to $DEFAULT_BASE"
208 echo " @NAME@ replaced as appropriate"
209 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
210 echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
211 echo " -s svnpath - where to fetch the build module"
212 echo " -o : overwrite - re-run in base directory, do not create vserver"
214 echo " -a makevar=value - space in values are not supported"
215 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
216 echo " -B : run build only"
217 echo " -T : run test only"
218 echo " -v : be verbose"
219 echo " -7 : uses weekday-@FCDISTRO@ as base"
227 # preserve arguments for passing them again later
229 for arg in "$@"; do argv=(${argv[@]} "$arg") ; done
236 while getopts "nf:d:b:p:t:r:s:om:a:w:BTvh7" opt ; do
238 n) DRY_RUN="true" ; MAKEOPTS=(${MAKEOPTS[@]} -n) ;;
239 f) FCDISTRO=$OPTARG ;;
240 d) PLDISTRO=$OPTARG ;;
241 p) PERSONALITY=$OPTARG ;;
243 t) PLDISTROTAGS=$OPTARG ;;
244 r) TAGSRELEASE=$OPTARG ;;
245 s) SVNPATH=$OPTARG ;;
246 o) OVERWRITEMODE=true ;;
248 a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
249 w) WEBPATH=$OPTARG ;;
251 T) DO_BUILD= ; OVERWRITEMODE=true ;;
253 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
258 shift $(($OPTIND - 1))
262 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
263 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
264 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
265 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
266 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
267 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
268 [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
270 # NOTE: suggest that by default no email is sent and that the user
271 # should explicitly invoke this script with the -m arg to pass in
272 # the appropriate email address. --mef
273 if [ "$PLDISTRO" = "onelab" ] ; then
274 [ -z "$MAILTO" ] && MAILTO="$DEFAULT_MAILTO"
276 [ -n "$DRY_RUN" ] && MAILTO=""
278 ### set BASE from DISTRO, if unspecified
279 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
280 BASE=$(echo ${BASE} | sed $sedargs)
281 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
283 if [ ! -d /vservers ] ; then
285 echo "==================== Within vserver BEG $(date)"
287 echo "==================== Within vserver END $(date)"
291 # we run in the root context :
292 # (*) create or check for the vserver to use
293 # (*) copy this command in the vserver
296 if [ -n "$OVERWRITEMODE" ] ; then
297 ### Re-use a vserver (finish an unfinished build..)
298 if [ ! -d /vservers/${BASE} ] ; then
299 echo $COMMAND : cannot find vserver $BASE
302 # manage LOG - beware it might be a symlink so nuke it first
303 LOG=/vservers/${BASE}.log.txt
307 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
310 vserver ${BASE} exec svn update /build
312 # create vserver: check it does not exist yet
314 while [ -d /vservers/${BASE}${i} ] ; do
315 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
316 [ -z ${i} ] && BASE=${BASE}-n
318 if [ $i -gt 100 ] ; then
319 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
325 # manage LOG - beware it might be a symlink so nuke it first
326 LOG=/vservers/${BASE}.log.txt
330 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
333 ### extract the whole build - much simpler
334 tmpdir=/tmp/$COMMAND-$$
335 svn export $SVNPATH $tmpdir
338 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} ${BASE}
342 # Extract build again - in the vserver
343 vserver ${BASE} exec svn checkout ${SVNPATH} /build
345 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
347 # The log inside the vserver contains everything
348 LOG2=/vservers/${BASE}/log.txt
349 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
351 echo "==================== END VSERVER Transcript of vserver creation" ; \
352 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
353 ### not too nice : nuke the former log, symlink it to the new one
354 rm $LOG; ln -s $LOG2 $LOG
359 if [ -n "$DO_BUILD" ] ; then
361 cp $COMMANDPATH /vservers/${BASE}/build/
363 # invoke this command in the vserver for building (-T)
364 vserver ${BASE} exec chmod +x /build/$COMMAND
365 vserver ${BASE} exec /build/$COMMAND "${argv[@]}" -b "${BASE}"
368 # publish to the web so runtest can find them
369 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
370 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
371 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
373 if [ -n "$DO_TEST" ] ; then