示例#1
0
    def save_report(self, fname):
        """
        :type fname: str
        """
        try:
            if os.path.exists(fname):
                self.log.warning(
                    "File %s already exists, it will be overwritten", fname)
            else:
                dirname = os.path.dirname(fname)
                if dirname and not os.path.exists(dirname):
                    os.makedirs(dirname)

            testsuites = etree.Element("testsuites")
            for _, suite in iteritems(self.test_suites):
                testsuites.append(suite)
            etree_obj = etree.ElementTree(testsuites)

            self.log.info("Writing JUnit XML report into: %s", fname)
            with open(get_full_path(fname), 'wb') as _fds:
                etree_obj.write(_fds,
                                xml_declaration=True,
                                encoding="UTF-8",
                                pretty_print=True)
        except BaseException:
            raise TaurusInternalException("Cannot create file %s" % fname)
示例#2
0
    def __dump_xml(self, filename):
        self.log.info("Dumping final status as XML: %s", filename)
        root = etree.Element("FinalStatus")

        if self.first_ts < float("inf") and self.last_ts > 0:
            duration_elem = etree.Element("TestDuration")
            duration_elem.text = str(
                round(float(self.last_ts - self.first_ts), 3))
            root.append(duration_elem)

        report_info = get_bza_report_info(self.engine, self.log)
        if report_info:
            link, _ = report_info[0]
            report_element = etree.Element("ReportURL")
            report_element.text = link
            root.append(report_element)
        if self.last_sec:
            for label, kpiset in iteritems(
                    self.last_sec[DataPoint.CUMULATIVE]):
                root.append(self.__get_xml_summary(label, kpiset))

        with open(get_full_path(filename), 'wb') as fhd:
            tree = etree.ElementTree(root)
            tree.write(fhd,
                       pretty_print=True,
                       encoding="UTF-8",
                       xml_declaration=True)
示例#3
0
 def load(self, filename):
     try:
         self.tree = etree.ElementTree()
         self.tree.parse(filename)
         self.root = self.tree.getroot()
     except BaseException as exc:
         self.log.debug("Tsung: XML parsing error: %s", traceback.format_exc())
         raise TaurusInternalException("Tsung: XML parsing failed for file %s: %s" % (filename, exc))
示例#4
0
 def __init__(self, tsung_tool):
     self.log = logging.getLogger(self.__class__.__name__)
     self.root = etree.Element("tsung",
                               loglevel="notice",
                               version="1.0",
                               dumptraffic="protocol",
                               backend="text")
     self.tree = etree.ElementTree(self.root)
     self.tool = tsung_tool