Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 879977 Details for
Bug 1014199
hwcert web server submit traceback if cert ID is not set for an existing certification
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
patch fixing submit form
0002-1014199-hwcert-web-server-submit-traceback-if-cert-I.patch (text/plain), 18.83 KB, created by
Greg Nichols
on 2014-03-28 17:42:56 UTC
(
hide
)
Description:
patch fixing submit form
Filename:
MIME Type:
Creator:
Greg Nichols
Created:
2014-03-28 17:42:56 UTC
Size:
18.83 KB
patch
obsolete
>From 9b2807ac2a2e55ffdcf96f29ad4a8a1b255cd6ba Mon Sep 17 00:00:00 2001 >From: Greg Nichols <gnichols@redhat.com> >Date: Fri, 28 Mar 2014 13:40:46 -0400 >Subject: [PATCH 2/2] 1014199 - hwcert web server submit traceback if cert ID > is not set for an existing certification > >--- > hwcert/catalog.py | 220 ++++++++++++++++++++++++++++++++++++++++++++----- > hwcert/harness.py | 4 +- > server/cgi/submit.py | 73 ++++++++++++---- > server/cgi/template.py | 23 ++++++ > 4 files changed, 279 insertions(+), 41 deletions(-) > >diff --git a/hwcert/catalog.py b/hwcert/catalog.py >index 283d1ed..c598ceb 100644 >--- a/hwcert/catalog.py >+++ b/hwcert/catalog.py >@@ -26,8 +26,9 @@ from hwcert.tags import Tags, Constants > from hwcert.certificationtest import CertificationDocument, ResultsDocument > > class Catalog(Controller): >+ """ client-end of catalog - no ui or output """ > >- def __init__(self, environment, debug=Constants.off): >+ def __init__(self, environment, debug): > Controller.__init__(self, debug) > self.environment = environment > self.login = None >@@ -41,13 +42,53 @@ class Catalog(Controller): > if match and match.group("host") and match.group("protocol"): > return "%s://%s" % (match.group("protocol"), match.group("host")) > # otherwise >- print "Error: could not parse server hostname from catalog URL \"%s\"" % self.environment.getCatalogURL() > return None > > def isReachable(self): > """ check to see that the catalog server is reachable """ > try: > request = urllib2.urlopen(self.getCatalogServer()) >+ except Exception: >+ return False >+ return True >+ >+ def submitResultsFile(self, resultsFile): >+ """ submit xml results to the HW catalog >+ returns (submitted, success) >+ success - False if error occurred >+ """ >+ # open the file to get the certification ID >+ resultsDocument = ResultsDocument() >+ resultsDocument.load(resultsFile) >+ >+ if resultsDocument.getCertificationID() <= 0: >+ self.getCertificationID(resultsDocument) >+ >+ # if the results already has a cert ID, or if we can get a new one - submit it. >+ if resultsDocument.getCertificationID(): >+ return self.submitResults(resultsDocument) >+ >+ #otherwise >+ return False >+ >+ >+ >+class CatalogText(Catalog): >+ """ command-line UI for client catalog interaction """ >+ >+ def __init__(self, environment, debug=Constants.off): >+ Catalog.__init__(self, environment, debug) >+ >+ def getCatalogServer(self): >+ server = Catalog.getCatalogServer(self) >+ if not server: >+ print "Error: could not parse server hostname from catalog URL \"%s\"" % self.environment.getCatalogURL() >+ return server >+ >+ def isReachable(self): >+ """ check to see that the catalog server is reachable """ >+ try: >+ request = urllib2.urlopen(self.getCatalogServer()) > except Exception, e: > print "Could not reach catalog server %s" % self.getCatalogServer() > print e >@@ -55,6 +96,7 @@ class Catalog(Controller): > return True > > def getCertificationID(self, resultsDocument): >+ """ command-line UI for getting and existing cert, or opening a new one """ > if not self.isReachable(): > print "Could not reach the Red Hat Hardware Catalog %s" % self.getCatalogServer() > return False >@@ -119,26 +161,7 @@ class Catalog(Controller): > > return (False, False) > >- def submitResultsFile(self, resultsFile): >- """ submit xml results to the HW catalog >- returns (submitted, success) >- success - False if error occurred >- """ >- # open the file to get the certification ID >- resultsDocument = ResultsDocument() >- resultsDocument.load(resultsFile) >- >- if resultsDocument.getCertificationID() <= 0: >- self.getCertificationID(resultsDocument) >- >- # if the results already has a cert ID, or if we can get a new one - submit it. >- if resultsDocument.getCertificationID(): >- return self.submitResults(resultsDocument) > >- #otherwise >- return False >- >- > def submitResults(self, resultsDocument): > > if resultsDocument.getCertificationID() <= 0: >@@ -489,9 +512,162 @@ class Catalog(Controller): > print "Try: %s, id=%s" % (count, id) > > >+class CatalogWeb(Catalog): >+ >+ def __init__(self, environment, debug=Constants.off): >+ Catalog.__init__(self, environment, debug) >+ self.clearErrors() >+ >+ def getErrors(self): >+ return self.errors >+ >+ def getWarnings(self): >+ return self.warnings >+ >+ def clearErrors(self): >+ self.errors = list() >+ self.warnings = list() >+ >+ def setLogin(self, login, password): >+ self.login = login >+ self.password = password >+ >+ def getCatalogServer(self): >+ server = Catalog.getCatalogServer(self) >+ if not server: >+ errors.append("Error: could not parse server hostname from catalog URL \"%s\"" % self.environment.getCatalogURL()) >+ return server >+ >+ def isReachable(self): >+ """ check to see that the catalog server is reachable """ >+ try: >+ request = urllib2.urlopen(self.getCatalogServer()) >+ except Exception, exception: >+ errors.append("Error: could not reach catalog server %s (%s)" % (self.getCatalogServer(), exception)) >+ return False >+ return True >+ >+ def newCertification(self, resultsDocument): >+ """ open a new cert """ >+ self.clearErrors() >+ >+ if not resultsDocument.getSpecificationID(): >+ self.errors.append("Error: no specification ID is set") >+ return 0 # failed/quit >+ >+ # catalog expects i386 for 32-bit x86 >+ arch = resultsDocument.getHardware(Tags.arch) >+ if arch == Constants.i686: >+ arch = Constants.i386 >+ >+ # get the major RHEL version >+ rhelVersion = resultsDocument.getOS(Tags.release).split(".")[0] >+ rhelProduct = "Red Hat Enterprise Linux" >+ >+ parameters = { >+ "product":rhelProduct, >+ "version":rhelVersion, >+ "platform":arch, >+ "spec_id":resultsDocument.getSpecificationID(), >+ } >+ response = self.__open(parameters, "certification") >+ id = response["id"] >+ if id: >+ resultsDocument.setCertificationID(id) >+ else: >+ errors.append("Error: could not open certification") >+ return response >+ >+ >+ def newSpecification(self, resultsDocument): >+ """ open a new spec """ >+ self.clearErrors() >+ >+ parameters = { >+ "make":resultsDocument.getHardware(Tags.make), >+ "model":resultsDocument.getHardware(Tags.model), >+ "vendor":resultsDocument.getHardware(Tags.vendor), >+ "category":resultsDocument.getHardware(Tags.category), >+ "url":resultsDocument.getHardware(Tags.product_url) >+ } >+ response = self.__open(parameters, "specification") >+ id = response["id"] >+ if id: >+ resultsDocument.setSpecificationID(id) >+ else: >+ self.errors.append("Error: could not open a new specification.") >+ return response >+ >+ >+ def __open(self, parameters, thing): >+ >+ while True: >+ if not self.login or not self.password: >+ self.errors.append("Error: missing or invalid login/password") >+ return None >+ parameters["login"] = self.login >+ parameters["password"] = self.password >+ >+ serverProxy = xmlrpclib.ServerProxy(self.environment.getCatalogURL()) >+ try: >+ if thing == "certification": >+ response = serverProxy.Cert.create_cert(parameters) >+ elif thing == "specification": >+ response = serverProxy.Cert.create_spec(parameters) >+ else: >+ response = serverProxy.Cert.create(parameters) >+ if response and response['warning']: >+ self.warnings.append(response['warning']) >+ return response >+ >+ except xmlrpclib.Fault, error: >+ self.errors.append("Error: could not open a new %s" % thing) >+ if not self.handleRPCException(error): >+ return None >+ except Exception, exception: >+ self.errors.append("Error: could not open a new certification (%s)" % exception) >+ return None >+ >+ return None >+ >+ def submitCompressedResultsFile(self, resultsFile, certificationID): >+ self.clearErrors() >+ if not self.login or not self.password: >+ self.errors.append("Error: missing or invalid login/password") >+ return None >+ >+ certificationData = open(resultsFile, "rb").read().encode("base64") >+ >+ serverProxy = xmlrpclib.ServerProxy(self.environment.getCatalogURL()) >+ try: >+ params = {"login":self.login, >+ "password":self.password, >+ "certid":certificationID, >+ "filename":os.path.basename(resultsFile), >+ "desc":"test results", >+ "data":certificationData} >+ >+ return serverProxy.Cert.attachResult(params) >+ >+ except xmlrpclib.Fault, error: >+ self.errors.append("Error: could not submit certification results") >+ self.handleRPCException(error) >+ return False >+ except Exception, e: >+ self.errors.append("Error: could not submit certification results (%s)" % exception) >+ return False >+ >+ def handleRPCException(self, rpcException): >+ self.errors.append("Error: %s (%s)" % (rpcException.faultString, rpcException.faultCode)) >+ if rpcException.faultCode == 300: # bad login/password >+ self.password = None >+ self.login = None >+ >+ return False # don't retry >+ > if __name__ == "__main__": > >- catalog = Catalog(Environment(), debug = Constants.low) >+ catalog = CatalogText(Environment(), debug = Constants.low) > catalog.selfTestSearch() > > >diff --git a/hwcert/harness.py b/hwcert/harness.py >index 7680a44..5ba9c95 100644 >--- a/hwcert/harness.py >+++ b/hwcert/harness.py >@@ -35,7 +35,7 @@ from hwcert.redhatrelease import RedHatRelease > from hwcert.daemon import HwCertDaemon > from hwcert.log import Log > from hwcert.http import HwCertHttp >-from hwcert.catalog import Catalog >+from hwcert.catalog import CatalogText > from hwcert.localTestServer import LocalTestServer > > class HardwareTestHarness(Controller): >@@ -46,7 +46,7 @@ class HardwareTestHarness(Controller): > self.environment = Environment() > self.makeDirectoryPath(self.environment.getDataDirectory()) > self.redHatRelease = RedHatRelease() >- self.catalog = Catalog(self.environment, self.options.debug) >+ self.catalog = CatalogText(self.environment, self.options.debug) > self.certification = None > > def doVersion(self): >diff --git a/server/cgi/submit.py b/server/cgi/submit.py >index 72fff78..5bf3d05 100755 >--- a/server/cgi/submit.py >+++ b/server/cgi/submit.py >@@ -24,7 +24,7 @@ hwcertServerRoot = '/var/www/hwcert' > > from hwcert.environment import Environment > from hwcert.tags import Constants >-from hwcert.catalog import Catalog >+from hwcert.catalog import CatalogWeb > from hwcert.certificationtest import CertificationDocument, ResultsDocument > > from template import Template >@@ -40,27 +40,28 @@ def renderCertInfoForm(parameters): > <option value="new">new</option> > </select> > </td></tr> >- <tr><td>ID</td><td><input name="id"></td></tr> >- <tr><td>Catalog User Name</td><td><input name="username"></td></tr> >+ <tr><td>ID</td><td><input name="id" value="%s"></td></tr> >+ <tr><td>Catalog User Name</td><td><input name="username" value="%s"></td></tr> > <tr><td>Catalog Password</td><td><input name="password" type="password"></td></tr> > <tr><td> </td><td><input type="submit" value="Submit"></td></tr> > </table> > <input type="hidden" name="rpath" value="%s"> > </form> >- """ % parameters["rpath"] >+ """ % (parameters.get("id",""), parameters.get("username", ""), parameters["rpath"]) > > def renderSubmitForm(parameters, certificationID): >- """ >+ print """ > <form method="post"> > <input name="state" type="hidden" value="existing"> > <table> >- <tr><td>Catalog User Name</td><td><input name="username"></td></tr> >+ <tr><td>Catalog User Name</td><td><input name="username" value="%s"></td></tr> > <tr><td>Catalog Password</td><td><input name="password" type="password"></td></tr> >+ <tr><td> </td><td><input type="submit" value="Submit"></td></tr> > </table> > <input type="hidden" name="id" value="%s"> > <input type="hidden" name="rpath" value="%s"> > </form> >- """ % (certificationID, parameters["rpath"]) >+ """ % (parameters.get("username", ""), certificationID, parameters["rpath"]) > > """ Main Script ------------------------------------------------- """ > environment = Environment() >@@ -77,13 +78,22 @@ header = "Submit Test Results" > print "<h2>%s</h2>" % header > > # make sure catalog is reachable >-catalog =Catalog(environment, debug=Constants.low) >+catalog =CatalogWeb(environment, debug=Constants.low) > if catalog.isReachable(): > print """ Catalog: <a href="%s" target="blank">%s</a><br/> """ % (catalog.getCatalogServer(), catalog.getCatalogServer()) >+ >+ # validate parameters >+ valid = True >+ if "state" in parameters: >+ if "new" == parameters["state"] and not template.validateParameters({"username":"string", "password":"string"}): >+ valid = False >+ elif "existing" == parameters["state"] and not template.validateParameters({"username":"string", "password":"string", "id":"int"}): >+ valid = False >+ > # load up results and check certID > resultsDocument = ResultsDocument() > resultsDocument.load(os.path.join(parameters["rpath"])) >- if "state" not in parameters or not parameters["state"]: >+ if not valid or "state" not in parameters or not parameters["state"]: > > # display a summary? > >@@ -92,21 +102,50 @@ if catalog.isReachable(): > renderCertInfoForm(parameters) > else: > renderSubmitForm(parameters, resultsDocument.getCertificationID()) >+ > elif "new" == parameters["state"]: > success = False >+ catalog.setLogin(parameters["username"], parameters["password"]) > print "<pre>" >- certificationID = catalog.openCertification(resultsDocument, parameters["username"], parameters["password"]) >- if certificationID: >- success = catalog.submitCompressedResultsFile(parameters["rpath"], parameters["username"], parameters["password"], certificationID) >+ if not resultsDocument.getSpecificationID(): >+ response = catalog.newSpecification(resultsDocument) >+ if catalog.getErrors(): >+ for error in catalog.getErrors(): print error >+ else: >+ if catalog.getWarnings(): >+ for warning in catalog.getWarnings(): print warning >+ >+ if resultsDocument.getSpecificationID(): >+ response = catalog.newCertification(resultsDocument) >+ if catalog.getErrors(): >+ for error in catalog.getErrors(): print error >+ else: >+ if catalog.getWarnings(): >+ for warning in catalog.getWarnings(): print warning >+ response = catalog.submitCompressedResultsFile(parameters["rpath"], resultsDocument.getCertificationID()) >+ if catalog.getWarnings(): >+ for warning in catalog.getWarnings(): print warning > print "</pre>" >- if success: >- print """<br/>Created <a href="%s/show.cgi?id=%s">Certification %s</a><br/> """ % (self.getCatalogServer(), certificationID, certificationID) >+ if resultsDocument.getCertificationID(): >+ print """<br/>Created <a href="%s/show.cgi?id=%s">Certification %s</a><br/> """ % (catalog.getCatalogServer(), resultsDocument.getCertificationID(), resultsDocument.getCertificationID()) >+ # update the copy here >+ print "saved to %s" % os.path.join(parameters["rpath"]) >+ resultsDocument.compressToFile(os.path.join(parameters["rpath"])[:-3]) # remove the .gz >+ > elif "existing" == parameters["state"]: >+ catalog.setLogin(parameters["username"], parameters["password"]) > print "<pre>" >- success = catalog.submitCompressedResultsFile(parameters["rpath"], parameters["username"], parameters["password"], parameters["id"]) >+ success = catalog.submitCompressedResultsFile(parameters["rpath"], parameters["id"]) >+ if catalog.getErrors(): >+ for error in catalog.getErrors(): print error >+ else: >+ if catalog.getWarnings(): >+ for warning in catalog.getWarnings(): print warning > print "</pre>" >- if success: >- print """<br/>Submitted to: <a href="%s/show.cgi?id=%s">Certification %s</a><br/> """ % (self.getCatalogServer(), parameters["id"], parameters["id"]) >+ if not catalog.getErrors(): >+ print """<br/>Submitted to: <a href="%s/show.cgi?id=%s">Certification %s</a><br/> """ % (catalog.getCatalogServer(), parameters["id"], parameters["id"]) >+ >+ print "<a href=\"%s\">Back</a>" % os.environ.get("HTTP_REFERER", "") > template.writeFooter() > sys.stdout.flush() > >diff --git a/server/cgi/template.py b/server/cgi/template.py >index 492e6f4..bbfbd3a 100644 >--- a/server/cgi/template.py >+++ b/server/cgi/template.py >@@ -40,6 +40,29 @@ class Template: > > return self.parameters > >+ def validateParameters(self, requirements): >+ """ requirements are of the form {value:type}""" >+ valid = True >+ if not self.parameters: >+ self.getParameters() >+ for (value, type) in requirements.iteritems(): >+ if not value in self.parameters: >+ if valid: >+ print "<pre>" >+ print "Error: %s not set" % value >+ valid = False >+ elif requirements[value] == "int": >+ try: >+ int(self.parameters[value]) >+ except: >+ if valid: >+ print "<pre>" >+ print "Error: %s must be an integer" % value >+ valid = False >+ if not valid: >+ print "</pre>" >+ return valid >+ > def writeHeader(self): > print "Content-type: text/html"; > print """ >-- >1.8.5.3 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1014199
: 879977