Author: gnichols
Date: 2012-03-22 18:35:38 +0000 (Thu, 22 Mar 2012)
New Revision: 1235
Modified:
trunk/v7/catalog.py
trunk/v7/certificationtest.py
trunk/v7/hardwaretest.py
Log:
782189 - FEAT: v7 should be able to upload a result directly to a hwcert.
Modified: trunk/v7/catalog.py
===================================================================
--- trunk/v7/catalog.py 2012-03-21 14:23:27 UTC (rev 1234)
+++ trunk/v7/catalog.py 2012-03-22 18:35:38 UTC (rev 1235)
@@ -23,49 +23,87 @@
from v7.controller import Controller
from v7.environment import Environment
-from v7.tags import Tags
+from v7.tags import Tags, Constants
class Catalog(Controller):
def __init__(self):
Controller.__init__(self)
self.environment = Environment()
+ self.login = None
+ self.password = None
+ def getCatalogServer(self):
+ catalogServer = self.environment.getCatalogURL()
+ # get just the server URL by stripping off the end of the URL (find the / at least 7 characters from the left).
+ return catalogServer[0:catalogServer.index('/', 7)]
+
def isReachable(self):
""" check to see that the catalog server is reachable """
- catalogServer = self.environment.getCatalogURL()
- # get just the server URL by stripping off the end of the URL (find the / at least 7 characters from the left).
- catalogServer = catalogServer[0:catalogServer.index('/', 7)]
try:
- request = urllib2.urlopen(catalogServer)
+ request = urllib2.urlopen(self.getCatalogServer())
except Exception, e:
print "Could not reach catalog server %s" % catalogServer
print e
return False
return True
+
+ def submit(self, certificationDocument):
+ if not self.ui.promptConfirm("\nWould you like to submit the results to the hardware catalog?"):
+ return None
+
+ if certificationDocument.getCertificationID() <= 0:
+ while True:
+ id = self.ui.prompt("Please enter the certification ID (ID|new)")
+ if id == "new":
+ self.openCertification(certificationDocument)
+ break
+ else:
+ try:
+ int(id) # make sure it's an integer
+ certificationDocument.setCertificationID(id)
+ break
+ except ValueError:
+ print "%s is not a valid ID, it must be an integer"
+
+ # opening the cert may have worked, or we had the certification number already.
+ if certificationDocument.getCertificationID() > 0:
+ self.submitResults(certificationDocument)
+
def openCertification(self, certificationDocument):
- if not self.ui.promptConfirm("\nWould you like to open a new certification request?"):
- return None
-
tags = [Tags.make, Tags.model, Tags.vendor, Tags.category, Tags.product_url, Tags.arch]
hardware = dict()
for tag in tags:
hardware[tag] = certificationDocument.getHardware(tag)
- # get the RHEL version
- rhelVersion = certificationDocument.getOS(Tags.release)
+ # catalog expects i386 for 32-bit x86
+ if hardware[Tags.arch] == Constants.i686:
+ hardware[Tags.arch] = Constants.i386
+
+ # get the major RHEL version
+ rhelVersion = certificationDocument.getOS(Tags.release).split(".")[0]
- login = self.ui.prompt("Red Hat Catalog User Name: ")
- password = self.ui.promptPassword("Password: ")
+ self.login = self.ui.prompt("Red Hat Catalog User Name: ")
+ self.password = self.ui.promptPassword("Password: ")
serverProxy = xmlrpclib.ServerProxy(self.environment.getCatalogURL())
try:
- certificationID = serverProxy.Cert.create(login, password,
- hardware[Tags.make], hardware[Tags.model], hardware[Tags.vendor], rhelVersion,
- hardware[Tags.arch], hardware[Tags.category], hardware[Tags.product_url])
+ params = {"login":self.login,
+ "password":self.password,
+ "make":hardware[Tags.make],
+ "model":hardware[Tags.model],
+ "vendor":hardware[Tags.vendor],
+ "version":rhelVersion,
+ "platform":hardware[Tags.arch],
+ "category":hardware[Tags.category],
+ "url":hardware[Tags.product_url]}
+ response = serverProxy.Cert.create(params)
+ print "created certification ID %s" % response["id"]
+ print "%s/show.cgi?id=%s" % (self.getCatalogServer(), response["id"])
+
except xmlrpclib.Fault, error:
print "Error: could not open a new certification:"
print " Fault code: %d" % error.faultCode
@@ -76,6 +114,43 @@
print e
return None
- certificationDocument.setCertificationID(certificationID)
+ certificationDocument.setCertificationID(response["id"])
- return certificationID
+ return response["id"]
+
+ def submitResults(self, certificationDocument):
+
+ if certificationDocument.getCertificationID() <= 0:
+ print "Error: The certification ID: %s is not valid." % certificationDocument.getCertificationID()
+ return False
+
+ if not self.login or not self.password:
+ self.login = self.ui.prompt("Red Hat Catalog User Name: ")
+ self.password = self.ui.promptPassword("Password: ")
+
+ file = "results.xml"
+ certificationDocument.compressToFile(file)
+ certificationData = open(file + ".gz", "rb").read().encode("base64")
+
+ serverProxy = xmlrpclib.ServerProxy(self.environment.getCatalogURL())
+ try:
+ params = {"login":self.login,
+ "password":self.password,
+ "certid":certificationDocument.getCertificationID(),
+ "filename":certificationDocument.getVerboseFileName(),
+ "desc":"test results",
+ "data":certificationData}
+
+ response = serverProxy.Cert.attachResult(params)
+ print "results uploaded."
+
+ except xmlrpclib.Fault, error:
+ print "Error: could not submit certification results:"
+ print " Fault code: %s" % error.faultCode
+ print " Fault string: %s" % error.faultString
+ return None
+ except Exception, e:
+ print "Error: could not submit certification results:"
+ print e
+ return None
+
\ No newline at end of file
Modified: trunk/v7/certificationtest.py
===================================================================
--- trunk/v7/certificationtest.py 2012-03-21 14:23:27 UTC (rev 1234)
+++ trunk/v7/certificationtest.py 2012-03-22 18:35:38 UTC (rev 1235)
@@ -105,7 +105,7 @@
return longName
def getName(self):
- # name is: v7-<vendor>-<model>-<os><release>_<arch>
+ """ 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(" ", "_")
@@ -456,6 +456,17 @@
for attachmentElement in self.document.getElementsByTagName(Tags.attachment):
attachmentElement.parentNode.removeChild(attachmentElement)
+ def getVerboseFileName(self):
+ """ v7-results-<hostname>-<run timestamp>.xml """
+ filename = "v7-results"
+ hostname = self.getOS(Tags.hostname)
+ if hostname:
+ filename += "-%s" % hostname
+ runTime = self.getRunTime()
+ if runTime:
+ filename += "-%s" % self.timeStringToTimestamp(runTime)
+ filename += ".xml"
+ return filename
if __name__ == "__main__":
doc = ResultsDocument()
doc.load("/var/v7/results.xml")
Modified: trunk/v7/hardwaretest.py
===================================================================
--- trunk/v7/hardwaretest.py 2012-03-21 14:23:27 UTC (rev 1234)
+++ trunk/v7/hardwaretest.py 2012-03-22 18:35:38 UTC (rev 1235)
@@ -995,14 +995,10 @@
def __submit(self):
if self.certification and self.certification.getNumberOfTestRuns() > 0:
if self.options.mode != Constants.auto:
- # offer to open a certification in the catalog if there's no id on the results
+ # optionally submit results to the catalog
catalog = Catalog()
if catalog.isReachable():
- if self.certification.getCertificationID() <= 0:
- catalog.openCertification(self.certification)
- # opening the cert may have worked, or we had the certification number already.
- if self.certification.getCertificationID() > 0:
- catalog.submitResults(self.certification)
+ catalog.submit(self.certification)
report = Report(self.options, self.certification)
if report.WriteResultsRPM(self.environment.getLogDirectory()):
@@ -1044,15 +1040,7 @@
self.makeDirectoryPath(path)
serverPath.append(value)
- savedFilename = "v7-results"
- hostname = self.certification.getOS(Tags.hostname)
- if hostname:
- savedFilename += "-%s" % hostname
- runTime = self.certification.getRunTime()
- print "run time: %s" % runTime
- if runTime:
- savedFilename += "-%s" % self.certification.timeStringToTimestamp(runTime)
- savedFilename += ".xml"
+ savedFilename = self.certification.getVerboseFileName()
print "Saving current results to:"
savedFilePath = os.path.join(path, savedFilename)
print savedFilePath