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@--test-@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
12 DEFAULT_SVNPATH="http://svn.planet-lab.org/svn/build/trunk"
13 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
15 DEFAULT_BUILDREPO="http://build.planet-lab.org/install-rpms/archive/"
16 DEFAULT_REPOURL="@BUILDREPO@/@PLDISTRO@/@FCDISTRO@/@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@/RPMS"
18 # 10.1 subnet allocated for testing at Princeton
19 DEFAULT_IPPREFIX16="10.1"
22 DEFAULT_TESTVSERVER_DEV=0
25 TESTSVNPATH="http://svn.planet-lab.org/svn/tests/trunk/system/"
28 # assuming vserver runs in UTC
29 DATE=$(date +'%Y.%m.%d')
31 # Notify recipient of failure or success, manage various stamps
34 WEBLOG=${WEBPATH}/${BASE}.test-log.txt
36 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 20k $WEBLOG) > ${WEBLOG}.ko
37 if [ -n "$MAILTO" ] ; then
38 tail -c 20k ${WEBLOG} | mail -s "Failures for test ${BASE}" $MAILTO
45 WEBLOG=${WEBPATH}/${BASE}.test-log.txt
48 if [ -n "$MAILTO" ] ; then
49 (echo "$PLDISTRO ($BASE) tests for $FCDISTRO completed on $(date)" ) | mail -s "Successful test for ${BASE}" $MAILTO
54 function show_env () {
56 echo FCDISTRO=$FCDISTRO
57 echo PLDISTRO=$PLDISTRO
60 echo MAKEVARS="${MAKEVARS[@]}"
61 echo MAKEOPTS="${MAKEOPTS[@]}"
62 echo PLDISTROTAGS="$PLDISTROTAGS"
63 echo TAGSRELEASE="$TAGSRELEASE"
64 echo -n "(might be unexpanded)"
65 echo WEBPATH="$WEBPATH"
66 if [ -d /vservers ] ; then
67 echo PLDISTROTAGS="$PLDISTROTAGS"
69 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
70 cat /build/$PLDISTROTAGS
71 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
77 ### set BASE from DISTRO, if unspecified
78 echo "Usage: $COMMAND [option] make-targets"
79 echo "This is $REVISION"
80 echo "Supported options"
81 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
82 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
83 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
84 echo " -b base - defaults to $DEFAULT_BASE"
85 echo " @NAME@ replaced as appropriate, which currently defaults to $BASE"
86 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
87 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
88 echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
89 echo " -s svnpath - where to fetch the build module"
90 echo " -o : overwrite - re-run in base directory, do not create vserver"
92 echo " -a makevar=value - space in values are not supported"
93 echo " -u repourl -- defaults to $DEFAULT_REPOURL"
94 echo " @NAME@ replaced as appropriate, which currently defaults to $REPOURL"
95 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
96 echo " @NAME@ replaced as appropriate, which currently defaults to $WEBPATH"
97 echo " -j ip address ; use this to give the vserver an explicit IP address; also see -i."
98 echo " -i /16 ip subnet for auto IP address selection within the subnet -- defaults to $DEFAULT_IPPREFIX16"
99 echo " This is only used when no explicit IP address is specified."
100 echo " -v : be verbose"
101 echo " -7 : uses weekday-@FCDISTRO@ as base -- defaults to $(date +%a|tr A-Z a-z)-$FCDISTRO"
109 # preserve arguments for passing them again later
111 for arg in "$@"; do argv=(${argv[@]} "$arg") ; done
114 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
115 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
116 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
117 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
118 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
119 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
120 [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
121 [ -z "$BUILDREPO" ] && BUILDREPO="$DEFAULT_BUILDREPO"
122 [ -z "$REPOURL" ] && REPOURL="$DEFAULT_REPOURL"
123 [ -z "$IPPREFIX16" ] && IPPREFIX16="$DEFAULT_IPPREFIX16"
124 [ -z "$TESTVSERVER_DEV" ] && TESTVSERVER_DEV="$DEFAULT_TESTVSERVER_DEV"
129 while getopts "nf:d:b:p:t:r:s:om:a:u:w:i:j:vh7" opt ; do
131 n) DRY_RUN="true" ; MAKEOPTS=(${MAKEOPTS[@]} -n) ; MAILTO="";;
132 f) FCDISTRO=$OPTARG ;;
133 d) PLDISTRO=$OPTARG ;;
135 p) PERSONALITY=$OPTARG ;;
136 t) PLDISTROTAGS=$OPTARG ;;
137 r) TAGSRELEASE=$OPTARG ;;
138 s) SVNPATH=$OPTARG ;;
139 o) OVERWRITEMODE=true ;;
141 a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
142 u) REPOURL=$OPTARG ;;
143 w) WEBPATH=$OPTARG ;;
144 i) IPPREFIX16=$OPTARG ;;
145 j) TESTVSERVER_IP=$OPTARG ;;
147 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
152 shift $(($OPTIND - 1))
155 ### set BASE from DISTRO, if unspecified
156 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
157 BASE=$(echo ${BASE} | sed $sedargs)
158 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
159 REPOURL=$(echo ${REPOURL} | sed $sedargs)
160 sedargs="-e s,@BUILDREPO@,${BUILDREPO},g"
161 REPOURL=$(echo ${REPOURL} | sed $sedargs)
164 # create vserver: check it does not exist yet
166 while [ -d /vservers/${BASE}${i} ] ; do
167 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
168 [ -z ${i} ] && BASE=${BASE}-n
170 if [ $i -gt 100 ] ; then
171 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
177 # manage LOG - beware it might be a symlink so nuke it first
178 LOG=/vservers/${BASE}.log.txt
182 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
185 ### extract the whole build - much simpler
186 tmpdir=/tmp/$COMMAND-$$
187 svn export $SVNPATH $tmpdir
190 ./vtest-init-vserver.sh -i eth${TESTVSERVER_DEV} -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} ${BASE} ${REPOURL}
196 rm -f /etc/vservers/${BASE}/interfaces/0/*
197 if [ -z "$TESTVSERVER_IP" ] ; then
198 xid=$(cat /etc/vservers/${BASE}/context)
199 TESTVSERVER_IP=$(python -c "context=int($xid); print '%s.%d.%d' % ($IPPREFIX16,(context&0xff00)>>8,context&0xff)")
201 mkdir -p /etc/vservers/${BASE}/interfaces/0
202 echo "${TESTVSERVER_IP}" > /etc/vservers/${BASE}/interfaces/0/ip
203 echo "eth${TESTVSERVER_DEV}" > /etc/vservers/${BASE}/interfaces/0/dev
204 vserver ${BASE} start
205 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
207 # The log inside the vserver contains everything
208 LOG2=/vservers/${BASE}/log.txt
209 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
211 echo "==================== END VSERVER Transcript of vserver creation" ; \
212 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
213 ### not too nice : nuke the former log, symlink it to the new one
214 rm $LOG; ln -s $LOG2 $LOG
219 svn cat ${TESTSVNPATH}/selftest > /vservers/${BASE}/selftest
220 vserver ${BASE} exec chmod +x /selftest
221 vserver ${BASE} exec /selftest ${BASE}.$(hostname) ${TESTVSERVER_IP}