unsupported combination of vserver & util-vserver
[build.git] / vbuild-nightly.sh
index 9e10a68..b753343 100755 (executable)
@@ -5,15 +5,13 @@ COMMANDPATH=$0
 COMMAND=$(basename $0)
 
 # default values, tunable with command-line options
-DEFAULT_FCDISTRO=f7
+DEFAULT_FCDISTRO=f8
 DEFAULT_PLDISTRO=planetlab
 DEFAULT_PERSONALITY=linux32
 DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
 DEFAULT_SVNPATH="http://svn.planet-lab.org/svn/build/trunk"
-
-# 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"
+DEFAULT_TESTSVNPATH="http://svn.planet-lab.org/svn/tests/trunk/system/"
+DEFAULT_IFNAME=eth0
 
 # web publishing results
 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
@@ -22,8 +20,6 @@ DEFAULT_WEBPATH="/build/@PLDISTRO@/"
 TESTBUILDURL="http://build.one-lab.org/"
 TESTBOX=onelab-test.inria.fr
 TESTBOXSSH=root@onelab-test.inria.fr
-TESTSVNPATH="http://svn.planet-lab.org/svn/tests/trunk/system/"
-TESTSCRIPT=TestMain.py
 ####################
 # assuming vserver runs in UTC
 DATE=$(date +'%Y.%m.%d')
@@ -35,16 +31,18 @@ function summary () {
     from=$1; shift
     echo "******************** BEG SUMMARY" 
     python - $from <<EOF
+#!/usr/bin/env python
 # read a full log and tries to extract the interesting stuff
 
 import sys,re
-m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*")
+m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*")
 m_installing_any=re.compile('\r  (Installing:[^\]]*]) ')
 m_installing_err=re.compile('\r  (Installing:[^\]]*])(..+)')
 m_installing_end=re.compile('Installed:.*')
-m_installing_doc=re.compile(".*such file or directory for /usr/share/info.*")
+m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
+m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
 
-def scan_log (filename):
+def summary (filename):
 
     try:
         if filename=="-":
@@ -54,28 +52,40 @@ def scan_log (filename):
             f=open(filename)
         echo=False
         for line in f.xreadlines():
+            # first off : discard warnings related to doc
+            if m_installing_doc1.match(line):
+                (begin,end)=m_installing_doc1.match(line).groups()
+                line=begin+end
+            if m_installing_doc2.match(line):
+                (begin,end)=m_installing_doc2.match(line).groups()
+                line=begin+end
+            # unconditionnally show these lines
             if m_show_line.match(line):
-                print line,
+                print '>>>',line,
+            # an 'installing' line with messages afterwards : needs to be echoed
             elif m_installing_err.match(line):
                 (installing,error)=m_installing_err.match(line).groups()
-                print installing
-                print error
+                print '>>>',installing
+                print '>>>',error
                 echo=True
+            # closing an 'installing' section
             elif m_installing_end.match(line):
                 echo=False
+            # any 'installing' line
             elif m_installing_any.match(line):
                 if echo: 
                     installing=m_installing_any.match(line).group(1)
-                    print installing
+                    print '>>>',installing
                 echo=False
+            # print lines when echo is true
             else:
-                if echo: print line,
+                if echo: print '>>>',line,
         f.close()
     except:
         print 'Failed to analyze',filename
 
 for arg in sys.argv[1:]:
-    scan_log(arg)
+    summary(arg)
 EOF
     echo "******************** END SUMMARY" 
 }
@@ -85,11 +95,12 @@ EOF
 function failure() {
     set -x
     WEBLOG=${WEBPATH}/${BASE}.log.txt
+    mkdir -p ${WEBPATH}
     cp $LOG ${WEBLOG}
     summary $LOG >> ${WEBLOG}
     (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 20k $WEBLOG) > ${WEBLOG}.ko
     if [ -n "$MAILTO" ] ; then
-       tail -c 20k ${WEBPATH}/${BASE}.log.txt | mail -s "Failures for build ${BASE}" $MAILTO
+       tail -c 20k ${WEBLOG} | mail -s "Failures for build ${BASE}" $MAILTO
     fi
     exit 1
 }
@@ -97,15 +108,44 @@ function failure() {
 function success () {
     set -x
     WEBLOG=${WEBPATH}/${BASE}.log.txt
+    mkdir -p ${WEBPATH}
     cp $LOG ${WEBLOG}
     summary $LOG >> ${WEBLOG}
     touch ${WEBLOG}.ok
     if [ -n "$MAILTO" ] ; then
-       (echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ) | mail -s "Successfull build for ${BASE}" $MAILTO
+       (echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ) | mail -s "Successful build for ${BASE}" $MAILTO
     fi
     exit 0
 }
 
+# parses ifconfig's output to find out ip address and mask
+# will then be passed to vserver as e.g. --interface 138.96.250.126/255.255.0.0
+# default is to use lo, that's enough for local mirrors
+# use -i eth0 in case your fedora mirror is on a separate box on the network
+function vserverIfconfig () {
+    ifname=$1; shift
+    local result="" 
+    line=$(ifconfig $ifname 2> /dev/null | grep 'inet addr')
+    if [ -n "$line" ] ; then
+       set $line
+       for word in "$@" ; do
+           addr=$(echo $word | sed -e s,[aA][dD][dD][rR]:,,)
+           mask=$(echo $word | sed -e s,[mM][aA][sS][kK]:,,)
+           if [ "$word" != "$addr" ] ; then
+               result="${addr}"
+           elif [ "$word" != "$mask" ] ; then
+               result="${result}/${mask}"
+           fi
+       done
+    fi
+    if [ -z "$result" ] ; then 
+       echo "vserverIfconfig failed to locate $ifname"
+       exit 1
+    else
+       echo $result
+    fi
+}
+
 # run in the vserver - do not manage success/failure, will be done from the root ctx
 function build () {
     set -x
@@ -123,12 +163,19 @@ function build () {
     show_env
     
     echo "Running make IN $(pwd)"
+    
+    # stuff our own variable settings
+    MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
+    MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
+    MAKEVARS=("NIGHTLY_BASE=${BASE}" "${MAKEVARS[@]}")
+    MAKEVARS=("NIGHTLY_PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
+
     # stage1
-    make -C /build "${MAKEOPTS[@]}" PLDISTROTAGS=${PLDISTROTAGS} PLDISTRO=${PLDISTRO} "${MAKEVARS[@]}" stage1=true 
+    make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true 
     # versions
-    make -C /build "${MAKEOPTS[@]}" PLDISTROTAGS=${PLDISTROTAGS} PLDISTRO=${PLDISTRO} "${MAKEVARS[@]}" NIGHTLY_BASE=${BASE} versions
+    make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
     # actual stuff
-    make -C /build "${MAKEOPTS[@]}" PLDISTROTAGS=${PLDISTROTAGS} PLDISTRO=${PLDISTRO} "${MAKEVARS[@]}" $MAKETARGETS
+    make -C /build $DRY_RUN "${MAKEVARS[@]}" $MAKETARGETS
 
 }
 
@@ -142,14 +189,13 @@ function runtest () {
     echo -n "============================== Starting $COMMAND:runtest on $(date)"
 
     ### the URL to the myplc package
-    rpm=$( (cd /vservers/$BASE/build/RPMS/i386 ; ls myplc-[0-9]*.rpm) )
+    rpm=$( find /vservers/$BASE/build/RPMS -name 'myplc-[0-9]*' )
     if [ ${#rpm[@]} != 1 ] ; then
        echo "$COMMAND: Cannot locate rpm for testing"
        failure
        exit 1
     fi
-    rpms_url=${TESTBUILDURL}${PLDISTRO}/${BASE}/RPMS/
-    url=${TESTBUILDURL}${PLDISTRO}/${BASE}/RPMS/i386/${rpm}
+    url=$(echo $rpm | sed -e "s,/vservers/$BASE/build,${TESTBUILDURL}${PLDISTRO}/${BASE},")
 
     # compute test directory name on test box
     testdir=test-${BASE}
@@ -157,15 +203,8 @@ function runtest () {
     ssh ${TESTBOXSSH} rm -rf ${testdir}
     # check it out
     ssh ${TESTBOXSSH} svn co ${TESTSVNPATH} ${testdir}
-    # store the myplc http url in the newly created test dir - for testing in chroot mode
-    echo ${url} | ssh ${TESTBOXSSH} "cat > ${testdir}/MYPLC-URL"
-    # store the build svn path in the newly created test dir - so it can perform myplc-init-vserver
-    echo ${SVNPATH} | ssh ${TESTBOXSSH} "cat > ${testdir}/BUILD-URL"
-    # store the rpms http url in the newly created test dir - for passing to myplc-init-vserver
-    echo ${rpms_url} | ssh ${TESTBOXSSH} "cat > ${testdir}/RPMS-URL"
-    # invoke test on testbox
-    ssh 2>&1 ${TESTBOXSSH} python -u ${testdir}/${TESTSCRIPT} ${url} 
-    # still missing - need to populate /var/www/html/install-rpms on the myplc
+    # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
+    ssh 2>&1 ${TESTBOXSSH} python -u ${testdir}/runtest --build ${SVNPATH} --url ${url} --all
        
     if [ "$?" != 0 ] ; then
        failure
@@ -181,7 +220,7 @@ function show_env () {
     echo BASE=$BASE
     echo SVNPATH=$SVNPATH
     echo MAKEVARS="${MAKEVARS[@]}"
-    echo MAKEOPTS="${MAKEOPTS[@]}"
+    echo DRY_RUN="$DRY_RUN"
     echo PLDISTROTAGS="$PLDISTROTAGS"
     echo TAGSRELEASE="$TAGSRELEASE"
     echo -n "(might be unexpanded)"
@@ -213,8 +252,10 @@ function usage () {
     echo " -m mailto"
     echo " -a makevar=value - space in values are not supported"
     echo " -w webpath - defaults to $DEFAULT_WEBPATH"
+    echo " -i ifname - defaults to $DEFAULT_IFNAME - set to e.g. eth0 for non-local mirrors"
     echo " -B : run build only"
     echo " -T : run test only"
+    echo " -x testsvnpath - defaults to $DEFAULT_TESTSVNPATH"
     echo " -v : be verbose"
     echo " -7 : uses weekday-@FCDISTRO@ as base"
     exit 1
@@ -230,12 +271,12 @@ function main () {
     
     # parse arguments
     MAKEVARS=()
-    MAKEOPTS=()
+    DRY_RUN=
     DO_BUILD=true
     DO_TEST=true
-    while getopts "nf:d:b:p:t:r:s:om:a:w:BTvh7" opt ; do
+    while getopts "nf:d:b:p:t:r:s:om:a:w:i:BTvh7" opt ; do
        case $opt in
-           n) DRY_RUN="true" ; MAKEOPTS=(${MAKEOPTS[@]} -n) ;;
+           n) DRY_RUN="-n" ;;
            f) FCDISTRO=$OPTARG ;;
            d) PLDISTRO=$OPTARG ;;
            p) PERSONALITY=$OPTARG ;;
@@ -247,8 +288,10 @@ function main () {
            m) MAILTO=$OPTARG ;;
            a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
            w) WEBPATH=$OPTARG ;;
+           i) IFNAME=$OPTARG ;;
            B) DO_TEST= ;;
            T) DO_BUILD= ; OVERWRITEMODE=true ;;
+           x) TESTSVNPATH=$OPTARG ;;
            v) set -x ;;
            7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
            h|*) usage ;;
@@ -265,14 +308,10 @@ function main () {
     [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
     [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
     [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
+    [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
     [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
+    [ -z "$TESTSVNPATH" ] && TESTSVNPATH="$DEFAULT_TESTSVNPATH"
 
-    # 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"
-    fi
     [ -n "$DRY_RUN" ] && MAILTO=""
        
     ### set BASE from DISTRO, if unspecified
@@ -335,7 +374,8 @@ function main () {
            svn export $SVNPATH $tmpdir
             # Create vserver
            cd $tmpdir
-           ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} ${BASE}
+           localip=$(vserverIfconfig $IFNAME)
+           ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} ${BASE} -- --interface $localip
            # cleanup
            cd -
            rm -rf $tmpdir