Author: gnichols Date: 2011-03-11 13:16:04 +0000 (Fri, 11 Mar 2011) New Revision: 809
Added: trunk/v7/configfile.py Modified: trunk/tests/reboot/reboot.py trunk/v7/continuation.py trunk/v7/tags.py Log: 626970 - FEAT: kdump test needs to verify kdump
Modified: trunk/tests/reboot/reboot.py =================================================================== --- trunk/tests/reboot/reboot.py 2011-03-11 13:14:36 UTC (rev 808) +++ trunk/tests/reboot/reboot.py 2011-03-11 13:16:04 UTC (rev 809) @@ -14,7 +14,7 @@ # # Author: Greg Nichols gnichols@redhat.com
-import os, string, sys, time, syslog +import os, string, sys, time, syslog, re
from v7.tags import Constants, DeviceClass, TestTag from v7.test import Test @@ -23,6 +23,7 @@ from v7.environment import Environment from v7.documentbase import DocumentWrapper from v7.continuation import Continuation +from v7.configfile import ConfigFile
class RebootTest(Test): @@ -97,8 +98,10 @@ if not self.promptConfirm("Ready to restart?"): return False
- # set up restart, and log start time - self.continuation.setInitConfig(marker=self.Name()) + # set up restart, and log start time + method = Constants.reboot + if usePanic: method = Constants.panic + self.continuation.setInitConfig(self.Name(), method)
# we need a delay here to give v7 time to finish writing results.xml sys.stdout.flush() @@ -125,6 +128,55 @@ time.sleep(waitTime) print "Error: %s took too long" % mode return False + + def verifyKDumpImage(self): + # parse /etc/kdump.conf to find the location of the image file + configFile = ConfigFile("/etc/kdump.conf") + imageDirectory = configFile.getParameter("path") + if not imageDirectory: + imageDirectory = "/var/crash" + + # find the vmcore image file matching the timestamp + # vmcore directories are like this: 127.0.0.1-2011-03-10-13:18:27 + vmcoreDirectoryPattern = re.compile("(?P<ipaddr>[0-9]+.[0-9]+.[0-9]+)-(?P<date>[0-9]+-[0-9]+-[0-9]+)-(?P<time>[0-9]+:[0-9]+:[0-9]+)") + minimumDuration = None + directoryMatch = None + for (root,dirs,files) in os.walk(imageDirectory): + for dir in dirs: + match = vmcoreDirectoryPattern.search(dir) + if match: + timestamp = "%s %s" % (match.group("date"), match.group("time")) + duration = self.continuation.getDuration(timestamp) + print "%s took %s" % (dir, duration) + if not directoryMatch or (duration.seconds < minimumDuration): + minimumDuration = duration.seconds + directoryMatch = dir + # accept it if it's less than reboot time limit + if directoryMatch and (minimumDuration < self.rebootTimeLimit*60): + vmcorePath = os.path.join(imageDirectory, directoryMatch, "vmcore") + print "Found kdump image: " + vmcorePath + else: + print "Error: could not locate vmcore file" + if directoryMatch: + print "Closest match is " + os.path.join(imageDirectory, directoryMatch, "vmcore") + print "Reboot timestamp: " + self.continuation.getTimestamp() + return False + + # run crash to see if it's a valid image + try: + # just run crash on it and quit, then look for the return value + crash = Command("echo "q" | crash %s /usr/lib/debug/lib/modules/`uname -r`/vmlinux" % vmcorePath) + crash.echo() + # if we get here, it must be OK + print "kdump image %s verified"% vmcorePath + return True + except V7CommandException, exception: + print "Error: could not verify kdump image %s" % vmcorePath + print exception + crash.printErrors() + + return False +
def run(self): PASSED = 0 @@ -133,6 +185,8 @@ if self.incomplete: result = self.continuation.verify(marker=self.Name()) self.continuation.removeInitConfig() + if self.continuation.getMethod() == Constants.panic: + result = self.verifyKDumpImage() else: result = self.reboot()
Added: trunk/v7/configfile.py =================================================================== --- trunk/v7/configfile.py (rev 0) +++ trunk/v7/configfile.py 2011-03-11 13:16:04 UTC (rev 809) @@ -0,0 +1,63 @@ +# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material +# is made available to anyone wishing to use, modify, copy, or +# redistribute it subject to the terms and conditions of the GNU General +# Public License v.2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Author: Greg Nichols +# + +# parse simple configles of the form: + +# <parametername> <value(s)> + +class ConfigFile(): + + def __init__(self, filePath): + self.filePath = filePath + self.parameters = None + + def __parse(self): + file = open(self.filePath) + for line in file.readlines(): + # skip comment lines + if line.strip() and line.strip()[0] == "#": + continue + words = line.strip().split(" ") + if words[0]: + if not self.parameters: + self.parameters = dict() + self.parameters[words[0]] = " ".join(words[1:]) + file.close() + + def getParameter(self, name): + if not self.parameters: + self.__parse() + if self.parameters: + try: + return self.parameters["name"] + except KeyError: + pass + return None + + def dump(self): + if not self.parameters: + self.__parse() + if self.parameters: + for key in self.parameters: + print "%s = %s" % (key, self.parameters[key]) +if __name__ == "__main__": + try: + confFile = ConfigFile("/etc/rc.local") + confFile.dump() + except Exception, exception: + print exception + exit(1) + exit(0) \ No newline at end of file
Modified: trunk/v7/continuation.py =================================================================== --- trunk/v7/continuation.py 2011-03-11 13:14:36 UTC (rev 808) +++ trunk/v7/continuation.py 2011-03-11 13:16:04 UTC (rev 809) @@ -30,20 +30,26 @@ self.environment = environment self.documentWrapper = DocumentWrapper() self.rebootTimeLimit = 10 # minutes + self.method = None + self.timestamp = None
- def setInitConfig(self, marker): + def setInitConfig(self, marker, method=None): + if method: + self.method = method chkconfig = Command("chkconfig --add v7") chkconfig.echo() # get a timestamo, save it - theTime = time.gmtime(time.time()) - runTimeStamp = self.documentWrapper.timeToString(theTime) + theTime = time.localtime(time.time()) + self.timestamp = self.documentWrapper.timeToString(theTime) # save it off to the side timestamp = open(os.path.join(self.environment.getDataDirectory(), "bootprint"), "w") - timestamp.write(runTimeStamp + "\n") + timestamp.write(self.timestamp + "\n") + if self.method: + timestamp.write(self.method + "\n") timestamp.close() # mark the log with this run time - markerName = "%s-%s" % (marker, runTimeStamp) + markerName = "%s-%s" % (marker, self.timestamp) syslog.syslog(self.getSystemLogMarker(markerName, "begin", pid=False))
def removeInitConfig(self): @@ -56,16 +62,20 @@ runTimeStamp = None try: timestamp = open(os.path.join(self.environment.getDataDirectory(), "bootprint")) - runTimeStamp = timestamp.readline().strip() + self.timestamp = timestamp.readline().strip() + method = timestamp.readline() + if method: + self.method = method.strip() timestamp.close() - theTime = time.gmtime(time.time()) - duration = self.documentWrapper.duration(runTimeStamp, self.documentWrapper.timeToString(theTime)) + theTime = time.localtime(time.time()) + duration = self.documentWrapper.duration(self.timestamp, self.documentWrapper.timeToString(theTime)) print "reboot took " + duration - durationData = self.documentWrapper.durationData(runTimeStamp, self.documentWrapper.timeToString(theTime)) + print "method: " + self.method + durationData = self.documentWrapper.durationData(self.timestamp, self.documentWrapper.timeToString(theTime)) if durationData.seconds > self.rebootTimeLimit*60: print "Error: reboot took longer that %u minutes" % self.rebootTimeLimit return False - log = self.getSystemLog("%s-%s" % (marker, runTimeStamp.strip()), pid=False) + log = self.getSystemLog("%s-%s" % (marker, self.timestamp.strip()), pid=False) rebootCount = 0 for line in log.split('\n'): if self.systemLogBootMarker in line: @@ -90,3 +100,9 @@
return True
+ def getMethod(self): + return self.method + def getTimestamp(self): + return self.timestamp + def getDuration(self, timestamp): + return self.documentWrapper.durationData(self.timestamp, timestamp)
Modified: trunk/v7/tags.py =================================================================== --- trunk/v7/tags.py 2011-03-11 13:14:36 UTC (rev 808) +++ trunk/v7/tags.py 2011-03-11 13:16:04 UTC (rev 809) @@ -174,6 +174,8 @@ certification="certification" osqa="osqa" DEBUG="DEBUG" + reboot="reboot" + panic="panic"
class SystemFunction:
v7-commits@lists.stg.fedorahosted.org