From: Dan S. <dan...@us...> - 2005-10-27 16:56:09
|
Update of /cvsroot/ltp/xmtest/lib/XmTestReport In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9013/lib/XmTestReport Added Files: OSReport.py ProgReport.py Report.py ResultReport.py utils.py xmtest.py.in Log Message: More added files --- NEW FILE: ResultReport.py --- #!/usr/bin/python """ ResultReport.py - Handles the gathering and xml-formatting of xm-test results Copyright (C) International Business Machines Corp., 2005 Author: Dan Smith <da...@us...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; under version 2 of the License. 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import utils import re class Test: def __init__(self, name, state): self.vars = {} self.vars["name"] = name self.vars["state"] = state self.vars["log"] = "NO LOG SUPPLIED" def setLog(self, log): self.vars["log"] = log def __str__(self): string = "<test>\n" for k in self.vars.keys(): string += " " + utils.tagify(k, self.vars[k]) + "\n" string += "</test>\n" return string class TestGroup: def __init__(self, name): self.name = name self.tests = [] def addTest(self, test): self.tests.append(test) def __str__(self): string = "<group>\n" string += " <name>%s</name>\n" % self.name for t in self.tests: string += str(t) string += "</group>\n" return string class ResultSet: def __init__(self): self.groups = [] def addGroup(self, group): self.groups.append(group) def __str__(self): string = "<results>\n" for g in self.groups: string += str(g) string += "</results>\n" return string class ResultParser: def __init__(self): self.groups = {} self.resultSet = None def __isImportant(self, line): if re.search("^[Mm]ak(e|ing)", line): return False if re.search("^===", line): return False if re.search("^All [0-9]+ tests", line): return False if re.search("^[0-9]+ of [0-9]+ tests", line): return False if re.search("^cp [0-9]+_", line): return False if re.search("^chmod \+x [0-9]+_", line): return False return True def parse(self, fileName): output = file(fileName); contents = output.read() lines = contents.split("\n") currentLog = "" for l in lines: match = re.match("^(PASS|FAIL|XPASS|XFAIL|SKIP): ([0-9]+)_([^_]+)_([^\.]+)\.test$", l) if match: # End of current test; build object testStatus = match.group(1) testNumber = match.group(2) testGroup = match.group(3) testName = match.group(4) if not testGroup in self.groups.keys(): self.groups[testGroup] = TestGroup(testGroup) test = Test("%s_%s" % (testNumber, testName), testStatus) test.setLog(currentLog) self.groups[testGroup].addTest(test) currentLog = "" else: if self.__isImportant(l): currentLog += l + "\n" self.resultSet = ResultSet() for g in self.groups: self.resultSet.addGroup(self.groups[g]) return self.resultSet if __name__ == "__main__": import sys r = ResultParser() print str(r.parse(sys.argv[1])) --- NEW FILE: OSReport.py --- #!/usr/bin/python """ OSReport.py - Handles the gathering and xml-formatting of operating system environment information. Copyright (C) International Business Machines Corp., 2005 Author: Dan Smith <da...@us...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; under version 2 of the License. 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import utils import posix import re import os import commands import sys class Machine: def __parseInfoLine(self, line): if ":" in line: name, value = line.split(":", 1) name = name.strip() value = value.strip() name = re.sub(" ", "_", name) return name, value else: return None, None def __getCpuInfo(self, values): cpuinfo = file("/proc/cpuinfo") if not cpuinfo: return "Unable to read /proc/cpuinfo" lines = cpuinfo.readlines() for l in lines: name, value = self.__parseInfoLine(l) if name in values.keys(): values[name] = value return values def __getXenInfo(self, values): status, output = commands.getstatusoutput("xm info") if status != 0: self.errors += 1 return values lines = output.split("\n") for l in lines: name, value = self.__parseInfoLine(l) if name in values.keys(): values[name] = value return values def __init__(self): self.values = {} self.errors = 0 cpuValues = {"model_name" : "Unknown", "flags" : "Unknown"} xenValues = {"nr_cpus" : "Unknown", "nr_nodes" : "Unknown", "sockets_per_node" : "Unknown", "cores_per_socket" : "Unknown", "threads_per_core" : "Unknown", "cpu_mhz" : "Unknown", "memory" : "Unknown"} xen = self.__getXenInfo(xenValues) cpu = self.__getCpuInfo(cpuValues) for k in xen.keys(): self.values[k] = xen[k] if xen[k] == "Unknown": self.errors += 1 for k in cpu.keys(): self.values[k] = cpu[k] if cpu[k] == "Unknown": self.errors += 1 def __str__(self): string = "<machine>\n" for k in self.values.keys(): string += " " + utils.tagify(k, self.values[k]) + "\n" string += "</machine>\n" return string class OperatingSystem: def __redhatStyleRelease(self): rFile = None if os.access("/etc/redhat-release", os.R_OK): rFile = file("/etc/redhat-release") if os.access("/etc/SuSe-release", os.R_OK): rFile = file("/etc/SuSe-release") if os.access("/etc/mandrake-release", os.R_OK): rFile = file("/etc/mandrake-release") if not rFile: return None, None rLine = rFile.readline() rFile.close() match = re.match("^([^0-9]+)([0-9]+).*$", rLine) if match: return match.group(1), match.group(2) else: return None, None def __lsbStyleRelease(self): if os.access("/etc/lsb-release", os.R_OK): rFile = file("/etc/lsb-release") else: rFile = None if not rFile: return None, None lines = rFile.readlines() vendor = None version = None for l in lines: match = re.match("^DISTRIB_ID=(.*)$", l) if match: vendor = match.group(1) match = re.match("^DISTRIB_RELEASE=(.*)$", l) if match: version = match.group(1) return vendor, version def __init__(self): self.values = {} self.errors = 0 # Try to resolve the vendor and version information # for the distro we're running on vendor = None version = None for r in [self.__redhatStyleRelease, self.__lsbStyleRelease]: vendor, version = r() if vendor and version: break self.values["vendor"] = vendor or "Unknown vendor" self.values["version"] = version or "Unknown version" self.values["name"], nodename, release, version, self.values["arch"] = posix.uname() for k in self.values.keys(): if not self.values[k]: self.errors += 1 def __str__(self): string = "<os>\n" for k in self.values.keys(): string += " " + utils.tagify(k, self.values[k]) + "\n" string += "</os>\n" return string class OSReport: def __init__(self): self.reports = {} self.reports["os"] = OperatingSystem() self.reports["machine"] = Machine() self.errors = 0 for k in self.reports.keys(): self.errors += self.reports[k].errors def __str__(self): string = "" for k in self.reports.keys(): string += str(self.reports[k]) return string if __name__ == "__main__": r = OSReport() print str(r) sys.exit(r.errors) --- NEW FILE: xmtest.py.in --- #!/usr/bin/python XM_TEST_VERSION = "@PACKAGE_VERSION@" --- NEW FILE: Report.py --- #!/usr/bin/python """ Report.py - Handles the coordination of xm-test xml-reporting modules Copyright (C) International Business Machines Corp., 2005 Author: Dan Smith <da...@us...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; under version 2 of the License. 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import OSReport import ProgReport import ResultReport import utils import sys import os import xml.dom.minidom import httplib import urllib REPORT_HOST = "xmtest.dague.org" REPORT_URL = "/cgi-bin/report-results"; class XmTestReport: def __init__(self, files): self.files = files def __getContactInfo(self): if os.access("contact_info", os.R_OK): c = file("contact_info") line = c.readline() line = line.strip() return line else: return "no...@no..." def __stringify(self, fileName): f = file(fileName) str = f.read() f.close() return str def __str__(self): string = "<testname>xm-test</testname>\n" string += "<user>%s</user>\n" % self.__getContactInfo() for f in self.files: string += self.__stringify(f) return string # Taken from example in Python Cookbook def encodeForm(fieldList): body = [] boundary = "-------XmTestReportingXML" for name in fieldList.keys(): body.append('--' + boundary) body.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (name, "%s.txt" % name)) body.append('Content-Type: text/plain') body.append('') body.append(fieldList[name]) body.append('') body.append("--" + boundary + "--") body.append('') textBody = "\r\n".join(body) return 'multipart/form-data; boundary=%s' % boundary, textBody def postResults(results): conn = httplib.HTTPConnection(REPORT_HOST) type, body = encodeForm({"log" : results}) headers = {"content-type" : type} # DEBUG OUTPUT # print "BODY\n%s\nBODY\n" % body # print "%s\n" % type # print headers conn.request("POST", REPORT_URL, body, headers) resp = conn.getresponse() if resp.status == 200: print >>sys.stderr, "Your results have been submitted successfully!" else: print >>sys.stderr, "Unable to submit results:" print >>sys.stderr, "[http://%s%s] said %i: %s" % (REPORT_HOST, REPORT_URL, resp.status, resp.reason) data = resp.read() print >>sys.stderr, data if __name__ == "__main__": if len(sys.argv) <= 1: print "Usage: Report.py [opt] <outputfiles...>" print "Where:" print "-d : don't submit, just dump XML" print "-D : do submit and dump XML" sys.exit(1) submit = True dump = False files = [] for a in sys.argv[1:]: if a == "-d": submit = False dump = True elif a == "-D": dump = True submit = True else: if not os.access(a, os.R_OK): print "Unable to access file: %s" % a sys.exit(1) else: files.append(a) report = XmTestReport(files) xmlout = "<xml>\n%s</xml>\n" % report if dump: print xmlout if submit: postResults(xmlout) --- NEW FILE: utils.py --- #!/usr/bin/python """ utils.py - Utilities for reporting xm-test results Copyright (C) International Business Machines Corp., 2005 Author: Dan Smith <da...@us...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; under version 2 of the License. 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ from xml.sax.saxutils import escape def tagify(tag, string): return "<%s>%s</%s>" % (tag, escape(string.strip()), tag) --- NEW FILE: ProgReport.py --- #!/usr/bin/python """ ProgReport.py - Handles the gathering and xml-formatting of supporting program information Copyright (C) International Business Machines Corp., 2005 Author: Dan Smith <da...@us...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; under version 2 of the License. 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import utils import commands import re import distutils.sysconfig import sys from xmtest import XM_TEST_VERSION class Prog: def __init__(self, name, version): self.vars = {} self.vars["name"] = name self.vars["version"] = version def __str__(self): string = "<prog>\n" for k in self.vars.keys(): string += " " + utils.tagify(k, self.vars[k]) + "\n" string += "</prog>\n" return string class UnknownProg(Prog): def __init__(self, name): Prog.__init__(self, name, "Unknown Version") class ProgFactory: def getXen(self): status, output = commands.getstatusoutput("xm info") if status != 0: return UnknownProg("xen") for l in output.split("\n"): match = re.match("^([a-z_]+)[ ]*: (.*)$", l) if match and match.group(1) == "xen_changeset": return Prog("xen", match.group(2)) return UnknownProg("xen") def getXmTest(self): return Prog("xm-test", XM_TEST_VERSION) def getPython(self): return Prog("python", distutils.sysconfig.get_python_version()) class ProgReport: def __init__(self): self.progs = [] self.errors = 0 f = ProgFactory() self.progs.append(f.getXen()) self.progs.append(f.getXmTest()) self.progs.append(f.getPython()) for p in self.progs: if isinstance(p, UnknownProg): self.errors += 1 def __str__(self): string = "<progs>\n" for p in self.progs: string += str(p) string += "</progs>\n" return string if __name__ == "__main__": r = ProgReport() print str(r) sys.exit(r.errors) |