cleaning up the root creation functions and build.common - untested
[build.git] / vbuild-nightly.sh
index a7b58df..3ebcab0 100755 (executable)
@@ -5,47 +5,62 @@ COMMANDPATH=$0
 COMMAND=$(basename $0)
 
 # default values, tunable with command-line options
-DEFAULT_FCDISTRO=fc6
+DEFAULT_FCDISTRO=f7
 DEFAULT_PLDISTRO=planetlab
-DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@"
+DEFAULT_PERSONALITY=linux32
+DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
 DEFAULT_SVNPATH="http://svn.planet-lab.org/svn/build/trunk"
 
-DEFAULT_MAILTO_onelab="onelab-build@one-lab.org"
-# tmp - send all mails to onelab
-#DEFAULT_MAILTO_planetlab="devel@planet-lab.org"
-DEFAULT_MAILTO_planetlab=$DEFAULT_MAILTO_onelab
+# NOTE: do not think we want to put email addresses into scripts
+# that can be harvested by spambots. --mef
+DEFAULT_MAILTO="onelab-build@one-lab.org"
 
 # web publishing results
-DEFAULT_WEBPATH="/build/@PLDISTRO@/@BASE@"
+DEFAULT_WEBPATH="/build/@PLDISTRO@/"
 
 # for the test part
 TESTBUILDURL="http://build.one-lab.org/"
 TESTBOX=onelab-test.inria.fr
 TESTBOXSSH=root@onelab-test.inria.fr
-TESTSVNPATH="http://svn.one-lab.org/new_plc_api/trunk/plctest"
+TESTSVNPATH="http://svn.planet-lab.org/svn/tests/trunk/system/"
 TESTSCRIPT=TestMain.py
 ####################
 # assuming vserver runs in UTC
-DATE=$(date -u +'%Y.%m.%d')
+DATE=$(date +'%Y.%m.%d')
+
+# temporary - wrap a quick summary of suspicious stuff
+# this is to focus on installation that go wrong
+# use with care, a *lot* of other things can go bad as well
+function summary () {
+    from=$1; shift
+    echo "******************** BEG SUMMARY" 
+    tr -d '\r' < $from | egrep 'BEG RPM|not installed|Installing:.*([eE]rror|[wW]arning)' 
+    echo "******************** END SUMMARY" 
+}
+
 
 # Notify recipient of failure or success, manage various stamps 
 function failure() {
     set -x
+    WEBLOG=${WEBPATH}/${BASE}.log.txt
+    cp $LOG ${WEBLOG}
+    summary $LOG >> ${WEBLOG}
+    (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 20k $WEBLOG) > ${WEBLOG}.ko
     if [ -n "$MAILTO" ] ; then
-       tail -c 8k $LOG | mail -s "Failures for build ${BASE}" $MAILTO
+       tail -c 20k ${WEBPATH}/${BASE}.log.txt | mail -s "Failures for build ${BASE}" $MAILTO
     fi
-    cp $LOG ${WEBPATH}.log.txt
-    (echo -n "============================== $COMMAND: failure at" ; date ; tail -c 20k $LOG) > ${WEBPATH}.broken.txt
     exit 1
 }
 
 function success () {
     set -x
+    WEBLOG=${WEBPATH}/${BASE}.log.txt
+    cp $LOG ${WEBLOG}
+    summary $LOG >> ${WEBLOG}
+    touch ${WEBLOG}.ok
     if [ -n "$MAILTO" ] ; then
-       (echo "http://build.one-lab.org/$PLDISTRO/$BASE" ; echo "Completed on $(date)" ) | mail -s "Successfull build for ${BASE}" $MAILTO
+       (echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ) | mail -s "Successfull build for ${BASE}" $MAILTO
     fi
-    cp $LOG ${WEBPATH}.log.txt
-    touch ${WEBPATH}.ok.txt
     exit 0
 }
 
@@ -83,6 +98,7 @@ function build () {
 function runtest () {
     set -x
     set -e
+    trap failure ERR INT
 
     echo -n "============================== Starting $COMMAND:runtest on $(date)"
     here=$(pwd)
@@ -92,21 +108,27 @@ function runtest () {
     rpm=$(ls myplc-[0-9]*.rpm)
     if [ ${#rpm[@]} != 1 ] ; then
        echo "$COMMAND: Cannot locate rpm for testing"
+       failure
        exit 1
     fi
     url=${TESTBUILDURL}${PLDISTRO}/${BASE}/RPMS/i386/${rpm}
 
-    # find the place where the plctest material was checked out
-    cd /vservers/$BASE/build/CODEBASES/PLCAPI
-    if [ ! -d plctest/ ] ; then
-       echo "$COMMAND : Cannot not locate plctest/ - exiting"
+    # checkout the system test (formerly known as plctest)
+    cd /vservers/${BASE}/build
+    rm -rf TESTS
+    svn export $TESTSVNPATH TESTS
+    # dont trust retcod
+    if [ ! -d TESTS ] ; then 
+       echo "$COMMAND: could not svn export $SVNPATH - check url"
        exit 1
     fi
+
   # compute test directory name on test box
     testdir=plctest-${BASE}
-  # rsync/push test material onto the test box
+  # rsync/push test material onto the test box - clean first
+    ssh ${TESTBOXSSH} rm -rf ${testdir}
     ssh ${TESTBOXSSH} mkdir -p ${testdir}
-    rsync -a -v plctest/ ${TESTBOXSSH}:${testdir}
+    rsync -a -v TESTS/ ${TESTBOXSSH}:${testdir}/
   # invoke test on testbox
     ssh ${TESTBOXSSH} python -u ${testdir}/${TESTSCRIPT} ${url} 
   #invoke make install from build to the testbox
@@ -132,6 +154,7 @@ function show_env () {
     echo MAKEOPTS="${MAKEOPTS[@]}"
     echo PLDISTROTAGS="$PLDISTROTAGS"
     echo TAGSRELEASE="$TAGSRELEASE"
+    echo -n "(might be unexpanded)"
     echo WEBPATH="$WEBPATH"
     if [ -d /vservers ] ; then
        echo PLDISTROTAGS="$PLDISTROTAGS"
@@ -148,17 +171,18 @@ function usage () {
     echo "This is $REVISION"
     echo "Supported options"
     echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
-    echo " -f FCDISTRO - defaults to $DEFAULT_FCDISTRO"
-    echo " -d PLDISTRO - defaults to $DEFAULT_PLDISTRO"
-    echo " -b BASE - defaults to $DEFAULT_BASE"
+    echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
+    echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
+    echo " -p personality - defaults to $DEFAULT_PERSONALITY"
+    echo " -b base - defaults to $DEFAULT_BASE"
     echo "    @NAME@ replaced as appropriate"
-    echo " -t PLDISTROTAGS - defaults to \${PLDISTRO}-tags.mk"
-    echo " -r TAGSRELEASE - a release number that refers to PLDISTROTAGS - defaults to HEAD"
-    echo " -s SVNPATH - where to fetch the build module"
+    echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
+    echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
+    echo " -s svnpath - where to fetch the build module"
     echo " -o : overwrite - re-run in base directory, do not create vserver"
-    echo " -m MAILTO"
-    echo " -a MAKEVAR=value - space in values are not supported"
-    echo " -w WEBPATH - defaults to $DEFAULT_WEBPATH"
+    echo " -m mailto"
+    echo " -a makevar=value - space in values are not supported"
+    echo " -w webpath - defaults to $DEFAULT_WEBPATH"
     echo " -B : run build only"
     echo " -T : run test only"
     echo " -v : be verbose"
@@ -178,11 +202,12 @@ function main () {
     MAKEOPTS=()
     DO_BUILD=true
     DO_TEST=true
-    while getopts "nf:d:b:t:r:s:om:a:w:BTvh" opt ; do
+    while getopts "nf:d:b:p:t:r:s:om:a:w:BTvh" opt ; do
        case $opt in
            n) DRY_RUN="true" ; MAKEOPTS=(${MAKEOPTS[@]} -n) ;;
            f) FCDISTRO=$OPTARG ;;
            d) PLDISTRO=$OPTARG ;;
+           p) PERSONALITY=$OPTARG ;;
            b) BASE=$OPTARG ;;
            t) PLDISTROTAGS=$OPTARG ;;
            r) TAGSRELEASE=$OPTARG ;;
@@ -204,22 +229,24 @@ function main () {
     # set defaults
     [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
     [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
+    [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
     [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
     [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
     [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
     [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
-    # 
+
+    # NOTE: suggest that by default no email is sent and that the user
+    # should explicitly invoke this script with the -m arg to pass in
+    # the appropriate email address. --mef
     if [ "$PLDISTRO" = "onelab" ] ; then
-       [ -z "$MAILTO" ] && MAILTO="$DEFAULT_MAILTO_onelab"
-    else
-       [ -z "$MAILTO" ] && MAILTO="$DEFAULT_MAILTO_planetlab"
+       [ -z "$MAILTO" ] && MAILTO="$DEFAULT_MAILTO"
     fi
     [ -n "$DRY_RUN" ] && MAILTO=""
        
     ### set BASE from DISTRO, if unspecified
-    sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g"
+    sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
     BASE=$(echo ${BASE} | sed $sedargs)
-    WEBPATH=$(echo ${WEBPATH} | sed $sedargs -e s,@BASE@,"$BASE",g)
+    WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
 
     if [ ! -d /vservers ] ; then
         # in the vserver
@@ -241,7 +268,7 @@ function main () {
                exit 1
            fi
            # manage LOG - beware it might be a symlink so nuke it first
-           LOG=/vservers/${BASE}.txt
+           LOG=/vservers/${BASE}.log.txt
            rm -f $LOG
            exec > $LOG 2>&1
            set -x
@@ -263,38 +290,33 @@ function main () {
            done
            BASE=${BASE}${i}
            # need update
-           WEBPATH=$(echo ${WEBPATH} | sed $sedargs -e s,@BASE@,"$BASE",g)
            # manage LOG - beware it might be a symlink so nuke it first
-           LOG=/vservers/${BASE}.txt
+           LOG=/vservers/${BASE}.log.txt
            rm -f $LOG
            exec > $LOG 2>&1 
            set -x
            echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
            show_env
 
-           ### extract vbuild-init-vserver.sh and run it
-           svn cat $SVNPATH/vbuild-init-vserver.sh > /tmp/vbuild-init-vserver-$$.sh
-           # get .lst 
-           lst=${PLDISTRO}-${FCDISTRO}-devel.lst
-           svn cat $SVNPATH/$lst > /tmp/$lst 
-
+           ### extract the whole build - much simpler
+           tmpdir=/tmp/$COMMAND-$$
+           svn export $SVNPATH $tmpdir
             # Create vserver
-           cd /tmp
-           chmod +x vbuild-init-vserver-$$.sh
-           /tmp/vbuild-init-vserver-$$.sh ${BASE} ${FCDISTRO} ${PLDISTRO}
+           cd $tmpdir
+           ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} ${BASE}
            # cleanup
-           rm -f /tmp/vbuild-init-vserver-$$.sh /tmp/$lst
            cd -
-           # Extract build
+           rm -rf $tmpdir
+           # Extract build again - in the vserver
            vserver ${BASE} exec svn checkout ${SVNPATH} /build
        fi
        echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
 
        # The log inside the vserver contains everything
        LOG2=/vservers/${BASE}/log.txt
-       (echo "==================== Transcript of vserver creation -- BEG $(date)" ; \
+       (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
         cat $LOG ; \
-        echo "==================== Transcript of vserver creation -- END $(date)" ; \
+        echo "==================== END VSERVER Transcript of vserver creation" ; \
         echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
        ### not too nice : nuke the former log, symlink it to the new one
        rm $LOG; ln -s $LOG2 $LOG
@@ -307,14 +329,15 @@ function main () {
            cp $COMMANDPATH /vservers/${BASE}/build/
 
            # invoke this command in the vserver for building (-T)
+           vserver ${BASE} exec chmod +x /build/$COMMAND
            vserver ${BASE} exec /build/$COMMAND "${argv[@]}" -b "${BASE}"
        fi
 
        # publish to the web so runtest can find them
-       rm -rf $WEBPATH ; mkdir -p $WEBPATH
-       tar -C /vservers/$BASE/build -cf - RPMS SRPMS | tar -C $WEBPATH -xf -
+       rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
+       rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
+       rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
        
-       set +e
        if [ -n "$DO_TEST" ] ; then 
            runtest
        fi