Author: gnichols
Date: 2011-07-07 18:44:54 +0000 (Thu, 07 Jul 2011)
New Revision: 983
Added:
trunk/tests/kdump/
trunk/tests/kdump/Makefile
trunk/tests/kdump/kdump.py
Modified:
trunk/tests/reboot/reboot.py
Log:
718290 - Can the kdump variation of the reboot test be moved to be the kdump test?
Added: trunk/tests/kdump/Makefile
===================================================================
--- trunk/tests/kdump/Makefile (rev 0)
+++ trunk/tests/kdump/Makefile 2011-07-07 18:44:54 UTC (rev 983)
@@ -0,0 +1,30 @@
+# V7
+TOPLEVEL_NAMESPACE=/V7
+
+# The name of the package under test:
+PACKAGE_NAME=v7
+
+# The path of the test below the package:
+RELATIVE_PATH=kdump
+
+# Version of the Test. Used with make tag.
+export TESTVERSION=1.0
+
+# The compiled namespace of the test.
+export TEST=$(TOPLEVEL_NAMESPACE)/$(PACKAGE_NAME)/$(RELATIVE_PATH)
+
+.PHONY: all install download clean
+
+FILES=kdump.py
+
+run: $(FILES) build
+
+build: $(BUILT_FILES)
+ chmod a+x ./kdump.py
+
+clean:
+ rm -f $(BUILT_FILES)
+
+# Include Common Makefile
+include $(DESTDIR)/usr/share/v7/lib/v7-make.include
+
Added: trunk/tests/kdump/kdump.py
===================================================================
--- trunk/tests/kdump/kdump.py (rev 0)
+++ trunk/tests/kdump/kdump.py 2011-07-07 18:44:54 UTC (rev 983)
@@ -0,0 +1,301 @@
+#!/usr/bin/python
+# Copyright (c) 2008 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 <gnichols(a)redhat.com>
+
+import os, string, sys, time, syslog, re
+
+from v7.tags import Constants, DeviceClass, TestTag
+from v7.test import Test
+from v7.command import Command, V7CommandException
+from v7.controller import Controller
+from v7.environment import Environment
+from v7.documentbase import DocumentWrapper
+from v7.continuation import Continuation
+from v7.configfile import ConfigFile
+
+
+class KDumpTest(Test):
+
+ def __init__(self):
+ Test.__init__(self, name="kdump")
+ self.interactive = False # will prompt in --mode normal, but runs ok in --mode auto
+ self.deviceClass = DeviceClass.system
+ self.environment = Environment()
+ self.continuation = Continuation(self.environment)
+ self.rebootTimeLimit = self.environment.getRebootTimelimit()
+ self.priority = 1001 # run last
+ self.coreCollector = "makedumpfile -d 31"
+ self.kdumpConfigPath = "/etc/kdump.conf"
+
+ def getRequiredRPMs(self):
+ rpms = ["kernel-debug", "kernel-debuginfo", "kexec-tools"]
+ return rpms
+
+ def plan(self, devices):
+ tests = list()
+ # plan kdump twice: once on storage (local disk) and once over network
+ for dumpMethod in [Constants.nfs, Constants.local]:
+ test = self.makeCopy()
+ test.setLogicalDeviceName(dumpMethod)
+ tests.append(test)
+ return tests
+
+ def verify(self):
+ if self.getLogicalDeviceName() == Constants.nfs and (self.getTestServer() == None or self.getTestServer() == "unknown"):
+ print "kdump test for %s failed verification: No test server was set." % self.getLogicalDeviceName()
+ return False
+ return True
+
+
+ def tags(self):
+ # nanny-prompting in --mode normal, will run --mode auto
+ return [TestTag.noninteractive, TestTag.certification]
+
+ def configureKDump(self):
+ # if kdump is set up, use it
+ print "Checking kdump configuration"
+ verified = True
+ # log kexec-tools installation
+ try:
+ kexecRPM = Command("rpm -q kexec-tools").getString()
+ print "kexec-tools installed: " + kexecRPM
+ except:
+ pass
+
+ # check crashkernel on kernel command line
+ kernelBootParams = Command("cat /proc/cmdline")
+ kdump = None
+ try:
+ kernelBootParams = Command("cat /proc/cmdline")
+ kdump = kernelBootParams.getString(regex=".+ crashkernel=(?P<kdump>[^\ ]+)", regexGroup="kdump")
+ print "Found crashkernel=%s boot parameter" % kdump
+ except:
+ print "Error: \"crashkernel\" is not set in boot parameters"
+ verified = False
+
+ # check kernel panic timeout, and set to 1sec if necessary
+ try:
+ procPanicTimeout = "/proc/sys/kernel/panic"
+ getPanic = Command("cat " + procPanicTimeout)
+ timeout = getPanic.getInteger()
+ print "Kernel panic reboot timeout is %u" % timeout
+ if timeout is 0:
+ print "Setting to 1 sec."
+ setPanic = Command("echo 1 > " + procPanicTimeout)
+ setPanic.echo()
+ if getPanic.getInteger() is not 1:
+ print "Error: could not set panic timeout"
+ verifited = False
+ except V7CommandException, e:
+ print "Error: could not set " + procPanicTimeout
+ print e
+ verified = False
+
+ # configure kdump to use makedumpfile -d 31
+ try:
+ configFile = ConfigFile(self.kdumpConfigPath)
+ coreCollector = configFile.getParameter("core_collector")
+ net = configFile.getParameter("net")
+ except IOError, exception:
+ print "Error: %s" % exception
+ return False
+
+ restart = False
+ if not coreCollector:
+ print "Adding core_collector = %s to %s" % (self.coreCollector, self.kdumpConfigPath)
+ configFile.addParameter("core_collector", self.coreCollector)
+ restart = True
+ else:
+ print "core_collector currently set to \"" + coreCollector + "\""
+
+ if net:
+ if self.getLogicalDeviceName() == Constants.local:
+ print "removing net setting for local disk dump"
+ configFile.removeParameter("net")
+ restart = True
+ else:
+ print "Network Dump set to %s" % net
+ elif self.getLogicalDeviceName() == Constants.nfs:
+ if self.getTestServer() and self.getTestServer() != "unknown":
+ net = "%s:/var/v7/export" % self.getTestServer()
+ print "Adding net %s to %s" % (net, self.kdumpConfigPath)
+ configFile.addParameter("net", net)
+ restart = True
+ else:
+ print "Error: v7 test server not set for network kdump"
+ return False
+
+
+ if restart:
+ configFile.save()
+ print "restarting kdump with new configuration..."
+ try:
+ Command("service kdump stop").echo()
+ Command("service kdump start").echo()
+ except V7CommandException, exception:
+ print "Error: kdump restart failed"
+ print exception
+ exception.command.printErrors()
+ verified = False
+
+
+ print "Checking kdump service"
+ try:
+ kdump = Command("service kdump status")
+ kdump.getString("is operational")
+ print "kdump is running"
+ except V7CommandException, e:
+ print "Error: kdump is not running - can not test it"
+ print e
+ verified = False
+
+ return verified
+
+
+ def panic(self):
+ self.markOutput("initialize")
+ if not self.configureKDump():
+ return False
+
+ # otherwise
+ 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
+
+ # set up restart, and log start time
+ self.continuation.setInitConfig(self.Name(), Constants.panic)
+
+ # we need a delay here to give v7 time to finish writing results.xml
+ self.closeOutput()
+ sys.stdout.flush()
+ self.waitForLull()
+
+ try:
+ Command("echo 1 > /proc/sys/kernel/sysrq").echo()
+ Command("echo \"c\" > /proc/sysrq-trigger").echo()
+ except Exception, e:
+ print "Error: attempt to cause kernel panic failed"
+ print e
+ return False
+
+ # wait here for reboot
+ waitTime = 60 #sec
+ print "Waiting for kernel panic..."
+ time.sleep(waitTime)
+ print "Error: The kernel panic took too long"
+ return False
+
+ def verifyKDumpImage(self):
+ imageDirectory = self.getImageDirectory()
+ if not imageDirectory:
+ return False
+
+ # 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
+ # using -s to supress startup output, then "sys" command for a summary, then "q" to quit the interpreter
+ crash = Command("echo \"sys\nq\" | crash -s %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 getImageDirectory(self):
+ # parse /etc/kdump.conf to find the location of the image file
+ configFile = ConfigFile(self.kdumpConfigPath)
+ imageDirectory = configFile.getParameter("path")
+ if not imageDirectory:
+ imageDirectory = "/var/crash"
+
+ # if nfs network dump, mount the filesystem
+ net = configFile.getParameter("net")
+ if net:
+ print "Attempting to mount net setting %s as nfs." % net
+ try:
+ localPath = "v7-net"
+ Command("mkdir %s" % localPath).echo()
+ Command("mount %s %s" % (net, localPath)).echo()
+ if os.path.isabs(imageDirectory):
+ imageDirectory = localPath + imageDirectory
+ else:
+ imageDirectory = os.path.join(localPath, imageDirectory)
+ except V7CommandException, exception:
+ print "Error: could not mount nfs image directory"
+ print exception
+ print exception.command.printErrors()
+ return None
+
+ print "Looking for vmcore image directories under " + imageDirectory
+ return imageDirectory
+
+
+ def run(self):
+ PASSED = 0
+ FAILED = 1
+
+ if self.incomplete and self.continuation.isInitialized():
+ self.markOutput("verify")
+ result = self.continuation.verify(marker=self.Name())
+ self.continuation.removeInitConfig()
+ if self.continuation.getMethod() == Constants.panic:
+ result = self.verifyKDumpImage()
+ self.closeOutput()
+ else:
+ result = self.panic()
+
+ if result: return PASSED
+
+ # otherwise
+ return FAILED
+
+
+if __name__ == "__main__":
+ test = RebootTest()
+ returnValue = test.do(sys.argv)
+ sys.exit(returnValue)
Modified: trunk/tests/reboot/reboot.py
===================================================================
--- trunk/tests/reboot/reboot.py 2011-07-07 18:44:08 UTC (rev 982)
+++ trunk/tests/reboot/reboot.py 2011-07-07 18:44:54 UTC (rev 983)
@@ -38,148 +38,21 @@
self.priority = 1001 # run last
self.coreCollector = "makedumpfile -d 31"
self.kdumpConfigPath = "/etc/kdump.conf"
-
- def getRequiredRPMs(self):
- rpms = ["kernel-debug", "kernel-debuginfo", "kexec-tools"]
- return rpms
- def plan(self, devices):
- tests = list()
- # plan reboot twice: once on storage (local disk) and once over network
- for dumpMethod in [Constants.nfs, Constants.local]:
- test = self.makeCopy()
- test.setLogicalDeviceName(dumpMethod)
- tests.append(test)
- return tests
-
- def verify(self):
- if self.getLogicalDeviceName() == Constants.nfs and (self.getTestServer() == None or self.getTestServer() == "unknown"):
- print "Reboot test for %s failed verification: No test server was set." % self.getLogicalDeviceName()
- return False
- return True
-
-
def tags(self):
return [TestTag.noninteractive, TestTag.certification]
- def configureKDump(self):
- # if kdump is set up, use it
- print "Checking kdump configuration"
- verified = True
- # log kexec-tools installation
- try:
- kexecRPM = Command("rpm -q kexec-tools").getString()
- print "kexec-tools installed: " + kexecRPM
- except:
- pass
-
- # check crashkernel on kernel command line
- kernelBootParams = Command("cat /proc/cmdline")
- kdump = None
- try:
- kernelBootParams = Command("cat /proc/cmdline")
- kdump = kernelBootParams.getString(regex=".+ crashkernel=(?P<kdump>[^\ ]+)", regexGroup="kdump")
- print "Found crashkernel=%s boot parameter" % kdump
- except:
- print "Warning: \"crashkernel\" is not set in boot parameters"
- verified = False
-
- # check kernel panic timeout, and set to 1sec if necessary
- try:
- procPanicTimeout = "/proc/sys/kernel/panic"
- getPanic = Command("cat " + procPanicTimeout)
- timeout = getPanic.getInteger()
- print "Kernel panic reboot timeout is %u" % timeout
- if timeout is 0:
- print "Setting to 1 sec."
- setPanic = Command("echo 1 > " + procPanicTimeout)
- setPanic.echo()
- if getPanic.getInteger() is not 1:
- print "Error: could not set panic timeout"
- verifited = False
- except V7CommandException, e:
- print "Warning: could not set " + procPanicTimeout
- print e
- verified = False
-
- # configure kdump to use makedumpfile -d 31
- try:
- configFile = ConfigFile(self.kdumpConfigPath)
- coreCollector = configFile.getParameter("core_collector")
- net = configFile.getParameter("net")
- except IOError, exception:
- print "Error: %s" % exception
- return False
-
- restart = False
- if not coreCollector:
- print "Adding core_collector = %s to %s" % (self.coreCollector, self.kdumpConfigPath)
- configFile.addParameter("core_collector", self.coreCollector)
- restart = True
- else:
- print "core_collector currently set to \"" + coreCollector + "\""
-
- if net:
- if self.getLogicalDeviceName() == Constants.local:
- print "removing net setting for local disk dump"
- configFile.removeParameter("net")
- restart = True
- else:
- print "Network Dump set to %s" % net
- elif self.getLogicalDeviceName() == Constants.nfs:
- if self.getTestServer() and self.getTestServer() != "unknown":
- net = "%s:/var/v7/export" % self.getTestServer()
- print "Adding net %s to %s" % (net, self.kdumpConfigPath)
- configFile.addParameter("net", net)
- restart = True
- else:
- print "Error: v7 test server not set for network dump"
- return False
-
-
- if restart:
- configFile.save()
- print "restarting kdump with new configuration..."
- try:
- Command("service kdump stop").echo()
- Command("service kdump start").echo()
- except V7CommandException, exception:
- print "Error: kdump restart failed"
- print exception
- exception.command.printErrors()
- verified = False
-
-
- print "Checking kdump service"
- try:
- kdump = Command("service kdump status")
- kdump.getString("is operational")
- print "kdump is running"
- except V7CommandException, e:
- print "Warning: kdump is not running - can not test it"
- print e
- verified = False
-
- return verified
-
-
+
def reboot(self):
self.markOutput("initialize")
- usePanic = self.configureKDump()
-
- if usePanic:
- print "The test will now cause a kernel panic to exercise kdump"
- else:
- print "The system must be restarted for this test"
+ print "The system must be restarted for this test"
if self.getMode() != Constants.auto:
if not self.promptConfirm("Ready to restart?"):
return False
# set up restart, and log start time
- method = Constants.reboot
- if usePanic: method = Constants.panic
- self.continuation.setInitConfig(self.Name(), method)
+ self.continuation.setInitConfig(self.Name(), Constants.reboot)
# we need a delay here to give v7 time to finish writing results.xml
self.closeOutput()
@@ -187,103 +60,19 @@
self.waitForLull()
try:
- if usePanic:
- Command("echo 1 > /proc/sys/kernel/sysrq").echo()
- Command("echo \"c\" > /proc/sysrq-trigger").echo()
- else:
- Command("shutdown -r 0").echo()
+ Command("shutdown -r 0").echo()
except Exception, e:
- print "Error: reboot failed"
+ print "Error: attempt to reboot failed"
print e
return False
# wait here for reboot
waitTime = 60 #sec
- if usePanic:
- mode = "kernel panic"
- else:
- mode = "shutdown"
- print "Waiting for %s..." % mode
+ print "Waiting for shutdown..." % mode
time.sleep(waitTime)
- print "Error: %s took too long" % mode
+ print "Error: shutdown took too long" % mode
return False
-
- def verifyKDumpImage(self):
- imageDirectory = self.getImageDirectory()
- if not imageDirectory:
- return False
-
- # 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
- # using -s to supress startup output, then "sys" command for a summary, then "q" to quit the interpreter
- crash = Command("echo \"sys\nq\" | crash -s %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 getImageDirectory(self):
- # parse /etc/kdump.conf to find the location of the image file
- configFile = ConfigFile(self.kdumpConfigPath)
- imageDirectory = configFile.getParameter("path")
- if not imageDirectory:
- imageDirectory = "/var/crash"
-
- # if nfs network dump, mount the filesystem
- net = configFile.getParameter("net")
- if net:
- print "Attempting to mount net setting %s as nfs." % net
- try:
- localPath = "v7-net"
- Command("mkdir %s" % localPath).echo()
- Command("mount %s %s" % (net, localPath)).echo()
- if os.path.isabs(imageDirectory):
- imageDirectory = localPath + imageDirectory
- else:
- imageDirectory = os.path.join(localPath, imageDirectory)
- except V7CommandException, exception:
- print "Error: could not mount nfs image directory"
- print exception
- print exception.command.printErrors()
- return None
-
- print "Looking for vmcore image directories under " + imageDirectory
- return imageDirectory
-
-
def run(self):
PASSED = 0
FAILED = 1
@@ -292,8 +81,6 @@
self.markOutput("verify")
result = self.continuation.verify(marker=self.Name())
self.continuation.removeInitConfig()
- if self.continuation.getMethod() == Constants.panic:
- result = self.verifyKDumpImage()
self.closeOutput()
else:
result = self.reboot()