Author: gnichols
Date: 2012-03-23 14:52:31 +0000 (Fri, 23 Mar 2012)
New Revision: 1240
Modified:
trunk/v7/catalog.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-23 14:51:53 UTC (rev 1239)
+++ trunk/v7/catalog.py 2012-03-23 14:52:31 UTC (rev 1240)
@@ -24,12 +24,13 @@
from v7.controller import Controller
from v7.environment import Environment
from v7.tags import Tags, Constants
+from v7.certificationtest import CertificationDocument
class Catalog(Controller):
- def __init__(self):
+ def __init__(self, environment):
Controller.__init__(self)
- self.environment = Environment()
+ self.environment = environment
self.login = None
self.password = None
@@ -48,42 +49,71 @@
return False
return True
- def submit(self, certificationDocument):
+ def getCertificationID(self, resultsDocument):
+ if not self.isReachable():
+ print "Could not reach the Red Hat Hardware Catalog %s" % self.getCatalogServer()
+ answer = "existing"
+ else:
+ # otherwise
+ while True:
+ answers = ["new", "existing", "none"]
+ answer = self.ui.prompt("What certification is this system being tested for?", answers)
+ # let them type the ID right away
+ try:
+ int(answer)
+ resultsDocument.setCertificationID(answer)
+ return True
+ except ValueError:
+ pass
+
+ if answer not in answers:
+ print "Please enter one of the following: %s" % "".join(answers)
+ else:
+ break
+ if answer == "new":
+ return self.openCertification(resultsDocument)
+ if answer == "existing":
+ while True:
+ id = self.ui.prompt("Please enter the certification ID:")
+ try:
+ if id != "":
+ int(id)
+ resultsDocument.setCertificationID(id)
+ return True
+ except ValueError:
+ print "%s is not a valid ID, it must be an integer. Enter 0 if ID is unknown"
+ # otherwise
+ return False
+
+
+ def submit(self, resultsDocument):
+
if not self.ui.promptConfirm("\nWould you like to submit the results to the hardware catalog?"):
- return None
+ return True
- 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"
-
+ if resultsDocument.getCertificationID() <= 0:
+ self.getCertificationID(resultsDocument)
+
# opening the cert may have worked, or we had the certification number already.
- if certificationDocument.getCertificationID() > 0:
- self.submitResults(certificationDocument)
+ if resultsDocument.getCertificationID() > 0:
+ return self.submitResults(resultsDocument)
- def openCertification(self, certificationDocument):
+ return False
+ def openCertification(self, resultsDocument):
+
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)
+ hardware[tag] = resultsDocument.getHardware(tag)
# 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]
+ rhelVersion = resultsDocument.getOS(Tags.release).split(".")[0]
self.login = self.ui.prompt("Red Hat Catalog User Name: ")
self.password = self.ui.promptPassword("Password: ")
@@ -114,14 +144,14 @@
print e
return None
- certificationDocument.setCertificationID(response["id"])
+ resultsDocument.setCertificationID(response["id"])
return response["id"]
- def submitResults(self, certificationDocument):
+ def submitResults(self, resultsDocument):
- if certificationDocument.getCertificationID() <= 0:
- print "Error: The certification ID: %s is not valid." % certificationDocument.getCertificationID()
+ if resultsDocument.getCertificationID() <= 0:
+ print "Error: The certification ID: %s is not valid." % resultsDocument.getCertificationID()
return False
if not self.login or not self.password:
@@ -129,28 +159,34 @@
self.password = self.ui.promptPassword("Password: ")
file = "results.xml"
- certificationDocument.compressToFile(file)
+ resultsDocument.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(),
+ "certid":resultsDocument.getCertificationID(),
+ "filename":resultsDocument.getVerboseFileName(),
"desc":"test results",
"data":certificationData}
response = serverProxy.Cert.attachResult(params)
print "results uploaded."
+ # copy over to certification.xml to save the certification ID
+ certificationDocument = CertificationDocument()
+ certificationDocument.copy(resultsDocument)
+ certificationDocument.save(self.environment.getCertificationPath())
+ return True
+
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
+ return False
except Exception, e:
print "Error: could not submit certification results:"
print e
- return None
+ return False
\ No newline at end of file
Modified: trunk/v7/hardwaretest.py
===================================================================
--- trunk/v7/hardwaretest.py 2012-03-23 14:51:53 UTC (rev 1239)
+++ trunk/v7/hardwaretest.py 2012-03-23 14:52:31 UTC (rev 1240)
@@ -65,6 +65,7 @@
self.command = None
self.virtualization = None
self.redHatRelease = RedHatRelease()
+ self.catalog = Catalog(self.environment)
self.commands = {'plan': self.doPlan,
'verify': self.doVerify,
@@ -244,6 +245,8 @@
self.certification.getHardware(Tags.make),
self.certification.getHardware(Tags.model))
self.getOSInfo()
+ if self.options.mode != Constants.auto:
+ self.catalog.getCertificationID(self.certification)
# save the certification info off to certification.xml
certificationDocument = CertificationDocument()
@@ -993,12 +996,13 @@
return self.__submit()
def __submit(self):
+ success = True
if self.certification and self.certification.getNumberOfTestRuns() > 0:
if self.options.mode != Constants.auto:
# optionally submit results to the catalog
- catalog = Catalog()
- if catalog.isReachable():
- catalog.submit(self.certification)
+ if self.catalog.isReachable():
+ if not self.catalog.submit(self.certification):
+ return False
report = Report(self.options, self.certification)
if report.WriteResultsRPM(self.environment.getLogDirectory()):