Author: gnichols Date: 2010-06-10 15:48:02 +0000 (Thu, 10 Jun 2010) New Revision: 536
Modified: trunk/tests/reboot/reboot.py Log: 568526 - FEAT: add a reboot test
Modified: trunk/tests/reboot/reboot.py =================================================================== --- trunk/tests/reboot/reboot.py 2010-06-10 15:47:25 UTC (rev 535) +++ trunk/tests/reboot/reboot.py 2010-06-10 15:48:02 UTC (rev 536) @@ -21,23 +21,27 @@ from v7.command import Command, V7CommandException from v7.controller import Controller from v7.environment import Environment +from v7.documentbase import DocumentWrapper
class RebootTest(Test):
def __init__(self): Test.__init__(self, name="reboot") - self.interactive = True + self.interactive = False # will prompt in --mode normal, but runs ok in --mode auto self.deviceClass = DeviceClass.system self.v7Controller = Controller() self.environment = Environment() + self.documentWrapper = DocumentWrapper() # used for time utilities + self.rebootTimeLimit = 10 # minutes + self.priority = 1001 # run last
def setInitConfig(self): chkconfig = Command("chkconfig --add v7") chkconfig.echo() # get a timestamo, save it theTime = time.gmtime(time.time()) - runTimeStamp = time.strftime(Constants.DATETIMEFORMAT, theTime) + runTimeStamp = self.documentWrapper.timeToString(theTime) # save it off to the side timestamp = open(os.path.join(self.environment.getDataDirectory(), "bootprint"), "w") timestamp.write(runTimeStamp + "\n") @@ -50,49 +54,55 @@ chkconfig = Command("chkconfig --del v7") chkconfig.echo()
- def reboot(self): + def verifyKDump(self): # if kdump is set up, use it + print "Checking kdump configuration" + + # these checks aren't required, leaving them for diagnostic purposes kernelBootParams = Command("cat /proc/cmdline") kdump = None try: - kdump = kernelBootParams.getString(regex="crashkernel=(?P<kdump>[^\ ]+", regexGroup="kdump") - if kdump: - print "Found crashkernel=%s boot parameter - using kdump" % kdump - try: - Command("chkconfig kdump on").echo() - Command("service kdump start").echo() - except V7Exception, e: - print "Error: could not start kdump service" - print e - return False - + kernelBootParams = Command("cat /proc/cmdline") + kdump = kernelBootParams.getString(regex=".+ crashkernel=(?P<kdump>[^\ ]+)", regexGroup="kdump") + print "Found crashkernel=%s boot parameter" % kdump except: - print "Note: kdump not configured" + print "Warning: "crashkernel" is not set in boot parameters" + + try: + panicRebootTimeout = Command("cat /proc/sys/kernel/panic") + timeout = panicRebootTimeout.getInteger() + if timeout > 0: + print "Kernel panic reboot timeout is %u" % timeout + else: + print "Warning: Panic reboot is disabled (/proc/sys/kernel/panic is set to 0)" + except V7CommandException, e: + print "Warning: could not read /proc/sys/kernel/panic" + + print "Checking kdump service" + try: + kdump = Command("service kdump status") + kdump.getString("is operational") + print "kdump is running" + except V7CommandException, e: + print "kdump is not running - can not test it" + print e + return False + + return True
- if kdump: - print "The test will now cause a kernel panic to exercise kdump" - if self.getMode() != Constants.auto: - if not self.promptConfirm("Ready to restart?"): - return False - try: - Command("echo 1 > /proc/sys/kernel/sysrq").echo() - Command("echo "c" > /proc/sysrq-trigger").echo() - except V7Exception, e: - print "Error: could not cause kernel panic" - print e + + def reboot(self): + print "The system must be restarted for this test" + if self.getMode() != Constants.auto: + if not self.promptConfirm("Ready to restart?"): return False - else: # reboot - print "The system must be restarted for this test" - if self.getMode() != Constants.auto: - if not self.promptConfirm("Ready to restart?"): - return False - rebootCommand = Command("shutdown -r 0") - try: - rebootCommand.echo() - except Exception, e: - print "Error: reboot failed" - print e - return False + rebootCommand = Command("shutdown -r 0") + try: + rebootCommand.echo() + except Exception, e: + print "Error: reboot failed" + print e + return False
# wait here for reboot waitTime = 60 #sec @@ -101,13 +111,40 @@ print "Error: Shutdown took too long" return False
+ def causePanic(self): + print "The test will now cause a kernel panic to exercise kdump" + if self.getMode() != Constants.auto: + if not self.promptConfirm("Ready to restart?"): + return False + try: + Command("echo 1 > /proc/sys/kernel/sysrq").echo() + Command("echo "c" > /proc/sysrq-trigger").echo() + except V7CommandException, e: + print "Error: could not cause kernel panic" + print e + return False + + # wait here for panic - shouldn't ever get here + waitTime = 60 #sec + print "Waiting for panic..." + time.sleep(waitTime) + print "Error: panic did not occur?" + return False + def verifyContinuation(self): # get the log, verify rboot happened runTimeStamp = None try: timestamp = open(os.path.join(self.environment.getDataDirectory(), "bootprint")) - runTimeStamp = timestamp.readline() + runTimeStamp = timestamp.readline().strip() timestamp.close() + theTime = time.gmtime(time.time()) + duration = self.documentWrapper.duration(runTimeStamp, self.documentWrapper.timeToString(theTime)) + print "reboot took " + duration + durationData = self.documentWrapper.durationData(runTimeStamp, self.documentWrapper.timeToString(theTime)) + if durationData.seconds > self.rebootTimeLimit*60: + print "Error: reboot took longer that %u minutes" % self.rebootTimeLimit + return False log = self.v7Controller.getSystemLog("%s-%s" % (self.Name(), runTimeStamp.strip()), pid=False) print "Reboot log:\n---------------------------------------------------------" print log @@ -129,7 +166,10 @@ self.removeInitConfig() else: self.setInitConfig() - result = self.reboot() + if self.verifyKDump(): + result = self.causePanic() + else: + result = self.reboot()
if result: return PASSED
v7-commits@lists.stg.fedorahosted.org