diff options
author | Bill Peck <bpeck@redhat.com> | 2014-04-24 11:25:17 -0400 |
---|---|---|
committer | Bill Peck <bpeck@redhat.com> | 2014-04-24 11:25:17 -0400 |
commit | fd72e21ec43e80692350bc66ba58e6c8d643458f (patch) | |
tree | c83cae2f56d1bcc3c70538815a641b65eee7b1b0 | |
parent | 3ec769d65c138ad80a795e8f219a1559ca79be74 (diff) | |
download | tests-fd72e21ec43e80692350bc66ba58e6c8d643458f.tar.gz tests-fd72e21ec43e80692350bc66ba58e6c8d643458f.tar.xz tests-fd72e21ec43e80692350bc66ba58e6c8d643458f.zip |
First cut at reservesys task for restraint
-rw-r--r-- | distribution/reservesys/metadata | 7 | ||||
-rwxr-xr-x | distribution/reservesys/recipe_status | 39 | ||||
-rwxr-xr-x | distribution/reservesys/reservesys.sh | 220 |
3 files changed, 266 insertions, 0 deletions
diff --git a/distribution/reservesys/metadata b/distribution/reservesys/metadata new file mode 100644 index 0000000..e2efc2d --- /dev/null +++ b/distribution/reservesys/metadata @@ -0,0 +1,7 @@ +[General] +name=/distribution/reservesys + +[restraint] +enter_point=./reservesys.sh +dependencies=emacs;vim-enhanced;MTA;psmisc +max_time=24h diff --git a/distribution/reservesys/recipe_status b/distribution/reservesys/recipe_status new file mode 100755 index 0000000..d5d1e6a --- /dev/null +++ b/distribution/reservesys/recipe_status @@ -0,0 +1,39 @@ +#!/usr/bin/python + +import urllib2 +import sys +import getopt +import os +from xml.dom.minidom import parseString + +def main(): + recipe_url = None + + if ('RSTRNT_RECIPE_URL' in os.environ.keys()): + lab_controller = os.environ['RSTRNT_RECIPE_URL'] + + args = sys.argv[1:] + + try: + opts, args = getopt.getopt(args, 'r:', ['recipe_url=']) + except: + usage() + for opt, val in opts: + if opt in ('-r', '--recipeid'): + recipe_url = val + + if not recipe_url: + print "You must specify the recipe url with the -r flag" + sys.exit(1) + + response = urllib2.urlopen('%s' % recipe_url) + myrecipe = response.read() + job = parseString(myrecipe) + for recipe in job.getElementsByTagName('recipe') + \ + job.getElementsByTagName('guestrecipe'): + if recipe.getAttribute("result") != "Pass": + sys.exit(1) + +if __name__ == '__main__': + main() + sys.exit(0) diff --git a/distribution/reservesys/reservesys.sh b/distribution/reservesys/reservesys.sh new file mode 100755 index 0000000..798e7b1 --- /dev/null +++ b/distribution/reservesys/reservesys.sh @@ -0,0 +1,220 @@ +#!/bin/sh + +# +# Trap signal 15, when the user is done we will be killed +# If we timeout from either local or external watchdog +# we will have a warn/fail recorded anyway. +# +trap 'exit 0' 15 + +# Functions +RprtRslt() +{ + ONE=$1 + TWO=$2 + THREE=$3 + + # File the results in the database + rstrnt-report-result $ONE $TWO $THREE +} + +MOTD() +{ + FILE=/etc/motd + cp $FILE $FILE.orig + if selinuxenabled &>/dev/null ; then + restorecon $FILE.orig + fi + + local admonition= + if [ -n "$BEAKER_RESERVATION_POLICY_URL" ] ; then + admonition=" + Please ensure that you adhere to the reservation policy + for Beaker systems: + ${BEAKER_RESERVATION_POLICY_URL}" + fi + + cat <<END > $FILE +** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** + This System is reserved by $SUBMITTER. + + To return this system early. You can run the command: return2beaker.sh + Ensure you have your logs off the system before returning to Beaker + + To extend your reservation time. You can run the command: + extendtesttime.sh + This is an interactive script. You will be prompted for how many + hours you would like to extend the reservation.${admonition} + + You should verify the watchdog was updated succesfully after + you extend your reservation. + ${BEAKER}recipes/$RSTRNT_RECIPEID + + For ssh, kvm, serial and power control operations please look here: + ${BEAKER}view/$HOSTNAME + + For the default root password, see: + ${BEAKER}prefs/ + + Beaker Test information: + HOSTNAME=$HOSTNAME + JOBID=$RSTRNT_JOBID + RECIPEID=$RSTRNT_RECIPEID + DISTRO=$RSTRNT_OSDISTRO + ARCHITECTURE=$RSTRNT_OSARCH + + Job Whiteboard: $BEAKER_JOB_WHITEBOARD + + Recipe Whiteboard: $BEAKER_RECIPE_WHITEBOARD +** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** +END +} + +RETURNSCRIPT() +{ + SCRIPT=/usr/bin/return2beaker.sh + + echo "#!/bin/sh" > $SCRIPT + echo "killall reservesys.sh" >> $SCRIPT + echo "/bin/echo Going on..." >> $SCRIPT + + chmod 777 $SCRIPT +} + +EXTENDTESTTIME() +{ +SCRIPT2=/usr/bin/extendtesttime.sh + +cat > $SCRIPT2 <<-EOF +howmany() +{ +if [ -n "\$1" ]; then + RESPONSE="\$1" +else + echo "How many hours would you like to extend the reservation." + echo " Must be between 1 and 99 " + read RESPONSE +fi +validint "\$RESPONSE" 1 99 +echo "Extending reservation time \$RESPONSE" +EXTRESTIME=\$(echo \$RESPONSE)h +} + +validint() +{ +# validate first field. +number="\$1"; min="\$2"; max="\$3" + +if [ -z "\$number" ] ; then +echo "You didn't enter anything." +exit 1 +fi + +if [ "\${number%\${number#?}}" = "-" ] ; then # first char '-' ? +testvalue="\${number#?}" # all but first character +else +testvalue="\$number" +fi + +nodigits="\$(echo \$testvalue | sed 's/[[:digit:]]//g')" + +if [ ! -z "\$nodigits" ] ; then +echo "Invalid number format! Only digits, no commas, spaces, etc." +exit 1 +fi + +if [ ! -z "\$min" ] ; then +if [ "\$number" -lt "\$min" ] ; then +echo "Your value is too small: smallest acceptable value is \$min" +exit 1 +fi +fi +if [ ! -z "\$max" ] ; then +if [ "\$number" -gt "\$max" ] ; then +echo "Your value is too big: largest acceptable value is \$max" +exit 1 +fi +fi + +return 0 +} + +howmany "\$1" + +export RESULT_SERVER=$RESULT_SERVER +export HOSTNAME=$HOSTNAME +export JOBID=$JOBID +export TEST=$TEST +export TESTID=$TESTID +echo "FIXME - Implement extending watchdog time." +EOF + +chmod 777 $SCRIPT2 +} + +NOTIFY() +{ + /sbin/service sendmail start + local msg=$(mktemp) + +cat > $msg <<-EOF +To: $SUBMITTER +Subject: [Beaker Machine Reserved] $HOSTNAME +X-Beaker-test: $RSTRNT_TASKNAME + +EOF + cat /etc/motd >>$msg + cat $msg | sendmail -t + \rm -f $msg +} + +echo "***** Start of reservesys test *****" + +BUILD_() +{ + # build the /etc/motd file + echo "***** Building /etc/motd *****" + MOTD + + # send email to the submitter + echo "***** Sending email to $SUBMITTER *****" + NOTIFY + + # build /usr/bin/extendtesttime.sh script to allow user + # to extend the time time. + echo "***** Building /usr/bin/extendtesttime.sh *****" + EXTENDTESTTIME + + # build /usr/bin/return2beaker.sh script to allow user + # to return the system to Beaker early. + echo "***** Building /usr/bin/return2beaker.sh *****" + RETURNSCRIPT +} + +if [ -n "$RESERVEBY" ]; then + SUBMITTER=$RESERVEBY +fi + +# Only do initial setup once at beginning +if [ -n "$RSTRNT_REBOOTCOUNT" ]; then + if [ $RSTRNT_REBOOTCOUNT -eq 0 ]; then + if [ -n "$RESERVE_IF_FAIL" ]; then + ./recipe_status + if [ $? -eq 0 ]; then + RprtRslt $TEST PASS 0 + exit 0 + fi + fi + + BUILD_ + + RprtRslt $TEST PASS 0 + fi +fi + +# We stay running in restraint.. +while (true); do + sleep 5 +done + +echo "***** End of reservesys test *****" |