Author: gnichols
Date: 2012-03-02 13:47:46 +0000 (Fri, 02 Mar 2012)
New Revision: 1184
Modified:
trunk/v7/certificationtest.py
trunk/v7/environment.py
trunk/v7/hardwaretest.py
Log:
799118 - FEAT: v7 should preserve SUT hardware information when results are removed
Modified: trunk/v7/certificationtest.py
===================================================================
--- trunk/v7/certificationtest.py 2012-03-02 13:44:03 UTC (rev 1183)
+++ trunk/v7/certificationtest.py 2012-03-02 13:47:46 UTC (rev 1184)
@@ -24,16 +24,98 @@
import deviceclassdocument
import version
+class CertificationDocument(DocumentBase):
+ """ CertificationDocument represents the certification in progress on the SUT """
-class CertificationDocument(DocumentBase):
-
def __init__(self, topElement=None, document=None, debugging=False):
DocumentBase.__init__(self)
self.element = topElement
self.document = document
+ self.Debugging = debugging
+
+ def new(self):
+ self._new(topElement=Tags.certification_test, stylesheet="/v7/css/results.css")
+ hardwareElement = self.findOrCreateElement(self.document.documentElement, Tags.hardware)
+ certificationElement = self.findOrCreateElement(self.document.documentElement, Tags.certification)
+
+ def copy(self, original):
+ self._new(topElement=Tags.certification_test, stylesheet="/v7/css/results.css")
+ self.element = self.findOrCreateElement(self.document, Tags.certification_test)
+ hardware = self.document.importNode(original.findOrCreateElement(original.document.documentElement, Tags.hardware), True)
+ self.element.appendChild(hardware)
+ certification = self.document.importNode(original.findOrCreateElement(original.document.documentElement, Tags.certification), True)
+ self.element.appendChild(certification)
+
+
+ def setHardware(self, tag, value):
+ hardwareElement = self.findOrCreateElement(self.document.documentElement, Tags.hardware)
+ element = self.findOrCreateElement(hardwareElement, tag)
+ self.setTextNode(element, value)
+
+ def getHardware(self, tag):
+ hardwareElement = self.findOrCreateElement(self.document.documentElement, Tags.hardware)
+ element = self.findOrCreateElement(hardwareElement, tag)
+ textNode = self.getTextNode(element)
+ # YK: return "unknown" if can not find such hardware info
+ if textNode:
+ if textNode.data:
+ if textNode.data.isspace():
+ return "unknown"
+ else:
+ return textNode.data
+ else:
+ return "unknown"
+ else:
+ return "unknown"
+
+
+
+ def setOS(self, tag, value):
+ certificationElement = self.findOrCreateElement(self.document.documentElement, Tags.certification)
+ osElement = self.findOrCreateElement(certificationElement, Tags.os)
+ element = self.findOrCreateElement(osElement, tag)
+ self.setTextNode(element, value)
+
+ def getOS(self, tag):
+ certificationElement = self.findOrCreateElement(self.document.documentElement, Tags.certification)
+ osElement = self.findOrCreateElement(certificationElement, Tags.os)
+ element = self.findOrCreateElement(osElement, tag)
+ return self.getTextNode(element).data
+
+ def setCertificationID(self, id):
+ certificationElement = self.findOrCreateElement(self.document.documentElement, Tags.certification)
+ certificationElement.setAttribute(Attributes.id, id)
+
+ def getCertificationID(self):
+ certificationElement = self.findOrCreateElement(self.document.documentElement, Tags.certification)
+ return certificationElement.getAttribute(Attributes.id)
+
+ def getOSProductShortName(self):
+ longName = self.getOS(Tags.product)
+ if "Red Hat Enterprise Linux" in longName:
+ return "RHEL"
+
+ #otherwise
+ return longName
+
+ def getName(self):
+ # name is: v7-<vendor>-<model>-<os><release>_<arch>
+ name = "v7-%s-%s-%s%s_%s" % (self.getHardware(Tags.vendor), self.getHardware(Tags.model), self.getOS(Tags.name), self.getOS(Tags.release), self.getHardware(Tags.arch))
+ return name.replace(" ", "_")
+
+ def getVersion(self):
+ return self.document.documentElement.getAttribute(Attributes.v7_version)
+ def getRelease(self):
+ return self.document.documentElement.getAttribute(Attributes.v7_release)
+
+
+class ResultsDocument(CertificationDocument):
+ """ ResultsDocument represents the certification test results """
+
+ def __init__(self, topElement=None, document=None, debugging=False):
+ CertificationDocument.__init__(self, topElement, document, debugging)
self.currentTestElement = None
- self.Debugging = debugging
if self.element and self.document:
self._wrap()
@@ -49,6 +131,10 @@
certificationElement = self.findOrCreateElement(self.document.documentElement, Tags.certification)
self.deviceClasses = deviceclassdocument.InitDeviceClasses(self.element, self.document)
+ def copy(self, orginal):
+ CertificationDocument.copy(self, orginal)
+ self.deviceClasses = deviceclassdocument.BuildDeviceClasses(self.document)
+
def load(self, filename):
DocumentBase.load(self, filename)
self.deviceClasses = dict()
@@ -102,29 +188,8 @@
def getTestServer(self):
return self.getHardware(Tags.test_server)
-
-
- def setHardware(self, tag, value):
- hardwareElement = self.findOrCreateElement(self.document.documentElement, Tags.hardware)
- element = self.findOrCreateElement(hardwareElement, tag)
- self.setTextNode(element, value)
+
- def getHardware(self, tag):
- hardwareElement = self.findOrCreateElement(self.document.documentElement, Tags.hardware)
- element = self.findOrCreateElement(hardwareElement, tag)
- textNode = self.getTextNode(element)
- # YK: return "unknown" if can not find such hardware info
- if textNode:
- if textNode.data:
- if textNode.data.isspace():
- return "unknown"
- else:
- return textNode.data
- else:
- return "unknown"
- else:
- return "unknown"
-
def getDeviceClass(self, deviceClassName):
return self.deviceClasses[deviceClassName]
@@ -137,26 +202,8 @@
print "%s registered device %s" % (name, device.getUDI())
pass
- def setOS(self, tag, value):
- certificationElement = self.findOrCreateElement(self.document.documentElement, Tags.certification)
- osElement = self.findOrCreateElement(certificationElement, Tags.os)
- element = self.findOrCreateElement(osElement, tag)
- self.setTextNode(element, value)
+
- def getOS(self, tag):
- certificationElement = self.findOrCreateElement(self.document.documentElement, Tags.certification)
- osElement = self.findOrCreateElement(certificationElement, Tags.os)
- element = self.findOrCreateElement(osElement, tag)
- return self.getTextNode(element).data
-
- def getOSProductShortName(self):
- longName = self.getOS(Tags.product)
- if "Red Hat Enterprise Linux" in longName:
- return "RHEL"
-
- #otherwise
- return longName
-
def appendTest(self, test):
try:
deviceClass = self.deviceClasses[test.getDeviceClass()].appendTest(test)
@@ -286,10 +333,7 @@
tests.append(test)
return tests
- def getVersion(self):
- return self.document.documentElement.getAttribute(Attributes.v7_version)
- def getRelease(self):
- return self.document.documentElement.getAttribute(Attributes.v7_release)
+
def getTest(self, testName, udi = None, recursive=False):
if recursive:
@@ -370,10 +414,7 @@
return {'count':count,'run':runCount, 'neverPassed':neverPassedCount, 'neverFailed':neverFailedCount, 'start':start}
- def getName(self):
- # name is: v7-<vendor>-<model>-<os><release>_<arch>
- name = "v7-%s-%s-%s%s_%s" % (self.getHardware(Tags.vendor), self.getHardware(Tags.model), self.getOS(Tags.name), self.getOS(Tags.release), self.getHardware(Tags.arch))
- return name.replace(" ", "_")
+
def getSubTestsGroupedByNameAndParent(self):
subTestsByNameAndParent = list()
@@ -387,7 +428,7 @@
def getSubCertifications(self, run):
subCertifications = list()
for subCertificationElement in run.getChildElements(Tags.certification_test):
- subCertifications.append(CertificationDocument(subCertificationElement, run.document))
+ subCertifications.append(ResultsDocument(subCertificationElement, run.document))
return subCertifications
def getSubTests(self, subCertifications):
@@ -411,7 +452,7 @@
attachmentElement.parentNode.removeChild(attachmentElement)
if __name__ == "__main__":
- doc = CertificationDocument()
+ doc = ResultsDocument()
doc.load("/var/v7/results.xml")
doc.deleteAttachments()
doc.save("test.xml")
Modified: trunk/v7/environment.py
===================================================================
--- trunk/v7/environment.py 2012-03-02 13:44:03 UTC (rev 1183)
+++ trunk/v7/environment.py 2012-03-02 13:47:46 UTC (rev 1184)
@@ -30,6 +30,7 @@
self.defaultServerDirectory = "/var/www/v7"
self.defaultExport = "export"
self.defaultDatabaseName = "results.xml"
+ self.defaultCertificationName = "certification.xml"
self.defaultTaskFile = "tasks"
self.defaultLockFile = "/var/lock/subsys/v7"
self.defaultStoreDirectory = "/var/v7/store"
@@ -68,6 +69,7 @@
element = self.findOrCreateElement(filesystemElement, Tags.data_directory)
self.setTextNode(element, self.defaultDataDirectory)
element.setAttribute(Attributes.database_name, self.defaultDatabaseName)
+ element.setAttribute(Attributes.certification_name, self.defaultCertificationName)
element.setAttribute(Attributes.task_file, self.defaultTaskFile)
element.setAttribute(Attributes.lock_file, self.defaultLockFile)
@@ -181,6 +183,10 @@
dataDirectoryElement = self.findOrCreateElement(self._getFilesystemElement(), Tags.data_directory)
return dataDirectoryElement.getAttribute(Attributes.database_name)
+ def getCertificationFileName(self):
+ dataDirectoryElement = self.findOrCreateElement(self._getFilesystemElement(), Tags.data_directory)
+ return dataDirectoryElement.getAttribute(Attributes.certification_name)
+
def getLockFile(self):
dataDirectoryElement = self.findOrCreateElement(self._getFilesystemElement(), Tags.data_directory)
return dataDirectoryElement.getAttribute(Attributes.lock_file)
@@ -192,6 +198,9 @@
def getResultsPath(self):
return "%s/%s" % (self.getDataDirectory(), self.getResultsFileName())
+ def getCertificationPath(self):
+ return "%s/%s" % (self.getDataDirectory(), self.getCertificationFileName())
+
def getTaskFilePath(self):
return "%s/%s" % (self.getDataDirectory(), self.getTaskFile())
Modified: trunk/v7/hardwaretest.py
===================================================================
--- trunk/v7/hardwaretest.py 2012-03-02 13:44:03 UTC (rev 1183)
+++ trunk/v7/hardwaretest.py 2012-03-02 13:47:46 UTC (rev 1184)
@@ -31,7 +31,7 @@
from v7.controller import Controller
from v7.tags import Tags, Attributes, Constants, TestTag
from v7.environment import Environment
-from v7.certificationtest import CertificationDocument
+from v7.certificationtest import ResultsDocument, CertificationDocument
from v7.testdocument import TestDocument
from v7.test import TestParameters
from v7.report import Report
@@ -85,7 +85,7 @@
"\tcertify - execute the remaining tests from the certification test plan\n"\
"\tprint \t- print certification test results\n"\
"\tsubmit \t- submit certification test results\n"\
- "\tclean \t- remove all results and temporary files\n"\
+ "\tclean [results | all] \t- remove all results and temporary files\n"\
"\trun \t- run specific certification tests\n"\
"\tcontinue \t- continue a test run\n"\
"\tversion\t- prints the version of v7\n"\
@@ -114,11 +114,11 @@
action="store_true", dest="enable", default=False,
help="Re-enable a test")
parser.add_option("-d", "--model",
- action="store_true", dest="model", default=False,
- help="Edit model and vendor information")
- parser.add_option("-s", "--rhts",
- action="store_true", dest="rhts", default=False,
- help="report test results to RHTS")
+ action="store_true", dest="certification", default=False,
+ help="Edit model and vendor information (deprecated)")
+ parser.add_option("-c", "--certification",
+ action="store_true", dest="certification", default=False,
+ help="Edit certification, model and vendor information")
parser.add_option("-a", "--add",
action="store_true", dest="add", default=False,
help="Add a test")
@@ -131,9 +131,6 @@
parser.add_option("-l", "--last",
action="store_true", dest="latest", default=False,
help="Show only the latest test run")
- parser.add_option("-k", "--kudzu",
- action="store_true", dest="kudzu", default=False,
- help="Use kudzu to discover additional devices for plan")
parser.add_option("-v", "--device",
action="store", type="string", dest="device",
help="The logical device to be tested.")
@@ -151,7 +148,8 @@
self.options.tag = [TestTag.certification]
if len(self.args) > 2 or (len(self.args) == 2
- and not (self.args[0] == "server" and self.args[1] in ["start", "stop", "status", "daemon"])):
+ and not (self.args[0] == "server" and self.args[1] in ["start", "stop", "status", "daemon"])
+ and not (self.args[0] == Constants.clean and self.args[1] in [Constants.results, Constants.all])):
parser.error("Invalid command")
exit(1)
@@ -222,7 +220,7 @@
def load(self, silent=False):
try:
- self.certification = CertificationDocument(self.Debugging)
+ self.certification = ResultsDocument(self.Debugging)
self.certification.load(self.environment.getResultsPath())
except IOError:
self.certification = None
@@ -231,16 +229,36 @@
print "loaded results %s" % self.environment.getResultsPath()
def doDiscover(self):
- self.certification = CertificationDocument(self.Debugging)
- self.certification.new()
+ self.certification = ResultsDocument(self.Debugging)
+
+ # try and recover old hardware and os info
+ if os.path.exists(self.environment.getCertificationPath()):
+ certificationDocument = CertificationDocument()
+ certificationDocument.load(self.environment.getCertificationPath())
+ self.certification.copy(certificationDocument)
+ else:
+ self.certification.new()
+ self.getBiosInfo()
+ print "Hardware: %s %s %s" % (self.certification.getHardware(Tags.vendor),
+ self.certification.getHardware(Tags.make),
+ self.certification.getHardware(Tags.model))
+ self.getOSInfo()
+
+ # save the certification info off to certification.xml
+ certificationDocument = CertificationDocument()
+ certificationDocument.copy(self.certification)
+ certificationDocument.save(self.environment.getCertificationPath())
+
if self.testServer:
self.checkTestServer(self.testServer)
self.certification.setTestServer(self.testServer)
- self.getBiosInfo()
- print "Hardware: %s %s %s" % (self.certification.getHardware(Tags.vendor),
- self.certification.getHardware(Tags.make),
- self.certification.getHardware(Tags.model))
+ self.certification.setDiscoverTime(self.getCurrentUTCTime())
+ self.certification.save(self.environment.getResultsPath())
+
+ return True
+
+ def getOSInfo(self):
self.certification.setOS(Tags.name, self.redHatRelease.getCodeName())
if self.redHatRelease.getVersionPointUpdate():
self.certification.setOS(Tags.release, self.redHatRelease.getVersionPointUpdate())
@@ -256,10 +274,9 @@
hostname = socket.gethostname()
if hostname:
self.certification.setOS(Tags.hostname, hostname)
- self.certification.setDiscoverTime(self.getCurrentUTCTime())
- self.certification.save(self.environment.getResultsPath())
- print "saved configuration to %s" % self.environment.getResultsPath()
- return True
+
+ # set the certification id to blank for now
+ self.certification.setCertificationID(0)
def checkVirtualization(self):
# use the method introduced in
@@ -321,8 +338,8 @@
self.checkTestServer(self.options.server)
self.setServerOnTests()
- if self.options.model:
- self.editModel()
+ if self.options.certification:
+ self.editCertification()
self.certification.save(self.environment.getResultsPath())
print "saved test plan to %s" % self.environment.getResultsPath()
@@ -763,10 +780,6 @@
run.setSummary(summary)
run.getResultsAttachments(self.environment, outputFilePath)
-
-
- if self.options.rhts:
- self.reportToRHTS(test, run.getSummary(), outputFilePath)
except OSError, e:
print "Test error: %s" % e
@@ -1054,8 +1067,20 @@
return False
def doClean(self):
+ subcommand = Constants.results
+ try:
+ subcommand = self.args[1]
+ except IndexError:
+ pass
+ if subcommand not in [Constants.results, Constants.all]:
+ print "Error: invalid option %s, should be %s or %s" % (subcommand, Constants.results, Constants.all)
+ return False
+
+
if self.ui.promptConfirm("Are you sure you want to delete all test results?"):
self.removeLogFiles()
+ if subcommand == Constants.all and self.ui.promptConfirm("Also remove certification data?"):
+ self.removeCertificationFiles()
return True
@@ -1329,19 +1354,8 @@
print "removing V7 results..."
os.system("rm -f %s" % self.environment.getResultsPath())
- def reportToRHTS(self, test, result, outputFilePath):
- try:
- rhtsTestName = os.environ["TEST"]
- except KeyError:
- rhtsTestName = "v7"
- returnCode = 2 # 0 = PASS, 1 = WARN, 2 = FAIL
- if result == Constants.PASS:
- returnCode = 0
- elif result == Constants.WARN:
- returnCode = 1
- rhtsCommand = "rhts-report-result %s/%s %u %s" % (rhtsTestName, test.getName(), returnCode, outputFilePath)
- print rhtsCommand
- os.system(rhtsCommand)
+ def removeCertificationFiles(self):
+ os.system("rm -f %s" % self.environment.getCertificationPath())
def getLock(self):
if os.path.exists(self.environment.getLockFile()):
@@ -1369,7 +1383,7 @@
print "Error: HAL daemons \"%s\" is not running - please start it." % daemon
print e
- def editModel(self):
+ def editCertification(self):
editable = [Tags.vendor, Tags.make, Tags.model]
for tag in editable:
value = self.certification.getHardware(tag)
@@ -1378,5 +1392,19 @@
value = self.ui.prompt("Please enter the %s:" % tag, answers)
if len(value) > 0:
self.certification.setHardware(tag, value)
+
+ certificationID = self.certification.getCertificationID()
+ answers = None
+ if certificationID:
+ answers = list()
+ answers.append(certificationID)
+ value = self.ui.prompt("Please enter the certification ID:", answers)
+ if len(value) > 0:
+ self.certification.setCertificationID(value)
+
+ # copy over to certification.xml
+ certificationDocument = CertificationDocument()
+ certificationDocument.copy(self.certification)
+ certificationDocument.save(self.environment.getCertificationPath())