示例#1
0
    def generate(self):
        results = self._generate()
        test_suite = junit.JUnit("Rally test suite")
        for result in results:
            if isinstance(result["sla"], list):
                message = ",".join([
                    sla["detail"] for sla in result["sla"]
                    if not sla["success"]
                ])
            if message:
                outcome = junit.JUnit.FAILURE
            else:
                outcome = junit.JUnit.SUCCESS
            test_suite.add_test(result["key"]["name"], result["full_duration"],
                                outcome, message)
        result = test_suite.to_xml()

        if self.output_destination:
            return {
                "files": {
                    self.output_destination: result
                },
                "open": "file://" + os.path.abspath(self.output_destination)
            }
        else:
            return {"print": result}
示例#2
0
    def generate(self):
        test_suite = junit.JUnit("Rally test suite")
        for task in self.tasks_results:
            for workload in itertools.chain(
                    *[s["workloads"] for s in task["subtasks"]]):
                w_sla = workload["sla_results"].get("sla", [])

                message = ",".join([sla["detail"] for sla in w_sla
                                    if not sla["success"]])
                if message:
                    outcome = junit.JUnit.FAILURE
                else:
                    outcome = junit.JUnit.SUCCESS
                test_suite.add_test(workload["name"],
                                    workload["full_duration"], outcome,
                                    message)

        result = test_suite.to_xml()

        if self.output_destination:
            return {"files": {self.output_destination: result},
                    "open": "file://" + os.path.abspath(
                        self.output_destination)}
        else:
            return {"print": result}
示例#3
0
 def test_invalid_outcome(self):
     j = junit.JUnit("test")
     self.assertRaises(ValueError,
                       j.add_test,
                       "Foo.Bar",
                       1.23,
                       outcome=1024)
示例#4
0
    def test_basic_testsuite(self):
        j = junit.JUnit("test")
        j.add_test("Foo.Bar", 3.14, outcome=junit.JUnit.SUCCESS)
        j.add_test("Foo.Baz",
                   13.37,
                   outcome=junit.JUnit.FAILURE,
                   message="fail_message")
        j.add_test("Eggs.Spam", 42.00, outcome=junit.JUnit.ERROR)

        expected = """
<testsuite errors="1" failures="1" name="test" tests="3" time="58.51">
<testcase classname="Foo" name="Bar" time="3.14" />
<testcase classname="Foo" name="Baz" time="13.37">
<failure message="fail_message" /></testcase>
<testcase classname="Eggs" name="Spam" time="42.00">
<error message="" /></testcase></testsuite>"""
        self.assertEqual(expected.replace("\n", ""), j.to_xml())
示例#5
0
    def report(self,
               api,
               tasks=None,
               out=None,
               open_it=False,
               out_format="html"):
        """Generate report file for specified task.

        :param task_id: UUID, task identifier
        :param tasks: list, UUIDs od tasks or pathes files with tasks results
        :param out: str, output file name
        :param open_it: bool, whether to open output file in web browser
        :param out_format: output format (junit, html or html_static)
        """

        tasks = isinstance(tasks, list) and tasks or [tasks]

        results = []
        message = []
        processed_names = {}
        for task_file_or_uuid in tasks:
            if os.path.exists(os.path.expanduser(task_file_or_uuid)):
                with open(os.path.expanduser(task_file_or_uuid),
                          "r") as inp_js:
                    tasks_results = json.load(inp_js)
                    for result in tasks_results:
                        try:
                            jsonschema.validate(result,
                                                api.task.TASK_RESULT_SCHEMA)
                        except jsonschema.ValidationError as e:
                            print(
                                _("ERROR: Invalid task result format in %s") %
                                task_file_or_uuid,
                                file=sys.stderr)
                            print(six.text_type(e), file=sys.stderr)
                            return 1

            elif uuidutils.is_uuid_like(task_file_or_uuid):
                tasks_results = map(
                    lambda x: {
                        "key": x["key"],
                        "sla": x["data"]["sla"],
                        "hooks": x["data"].get("hooks", []),
                        "result": x["data"]["raw"],
                        "load_duration": x["data"]["load_duration"],
                        "full_duration": x["data"]["full_duration"],
                        "created_at": x["created_at"]
                    },
                    api.task.get_detailed(task_file_or_uuid)["results"])
            else:
                print(_("ERROR: Invalid UUID or file name passed: %s") %
                      task_file_or_uuid,
                      file=sys.stderr)
                return 1

            for task_result in tasks_results:
                if task_result["key"]["name"] in processed_names:
                    processed_names[task_result["key"]["name"]] += 1
                    task_result["key"]["pos"] = processed_names[
                        task_result["key"]["name"]]
                else:
                    processed_names[task_result["key"]["name"]] = 0
                results.append(task_result)

        if out_format.startswith("html"):
            result = plot.plot(results,
                               include_libs=(out_format == "html_static"))
        elif out_format == "junit":
            test_suite = junit.JUnit("Rally test suite")
            for result in results:
                if isinstance(result["sla"], list):
                    message = ",".join([
                        sla["detail"] for sla in result["sla"]
                        if not sla["success"]
                    ])
                if message:
                    outcome = junit.JUnit.FAILURE
                else:
                    outcome = junit.JUnit.SUCCESS
                test_suite.add_test(result["key"]["name"],
                                    result["full_duration"], outcome, message)
            result = test_suite.to_xml()
        else:
            print(_("Invalid output format: %s") % out_format, file=sys.stderr)
            return 1

        if out:
            output_file = os.path.expanduser(out)

            with open(output_file, "w+") as f:
                f.write(result)
            if open_it:
                webbrowser.open_new_tab("file://" + os.path.realpath(out))
        else:
            print(result)
示例#6
0
    def _old_report(self,
                    api,
                    tasks=None,
                    out=None,
                    open_it=False,
                    out_format="html"):
        """Generate report file for specified task.

        :param tasks: list, UUIDs of tasks or pathes files with tasks results
        :param out: str, output file name
        :param open_it: bool, whether to open output file in web browser
        :param out_format: output format (junit, html or html_static)
        """

        tasks = isinstance(tasks, list) and tasks or [tasks]

        results = []
        message = []
        processed_names = {}
        for task_file_or_uuid in tasks:
            if os.path.exists(os.path.expanduser(task_file_or_uuid)):
                results.extend(
                    self._load_task_results_file(api, task_file_or_uuid))
            elif uuidutils.is_uuid_like(task_file_or_uuid):
                results.append(
                    api.task.get(task_id=task_file_or_uuid, detailed=True))
            else:
                print("ERROR: Invalid UUID or file name passed: %s" %
                      task_file_or_uuid,
                      file=sys.stderr)
                return 1

        for task in results:
            for workload in itertools.chain(
                    *[s["workloads"] for s in task["subtasks"]]):
                if workload["name"] in processed_names:
                    processed_names[workload["name"]] += 1
                    workload["position"] = processed_names[workload["name"]]
                else:
                    processed_names[workload["name"]] = 0

        if out_format.startswith("html"):
            result = plot.plot(results,
                               include_libs=(out_format == "html-static"))
        elif out_format == "junit-xml":
            test_suite = junit.JUnit("Rally test suite")
            for task in results:
                for workload in itertools.chain(
                        *[s["workloads"] for s in task["subtasks"]]):
                    w_sla = workload["sla_results"].get("sla", [])
                    if w_sla:
                        message = ",".join([
                            sla["detail"] for sla in w_sla
                            if not sla["success"]
                        ])
                    if message:
                        outcome = junit.JUnit.FAILURE
                    else:
                        outcome = junit.JUnit.SUCCESS
                    test_suite.add_test(workload["name"],
                                        workload["full_duration"], outcome,
                                        message)
            result = test_suite.to_xml()
        else:
            print("Invalid output format: %s" % out_format, file=sys.stderr)
            return 1

        if out:
            output_file = os.path.expanduser(out)

            with open(output_file, "w+") as f:
                f.write(result)
            if open_it:
                webbrowser.open_new_tab("file://" + os.path.realpath(out))
        else:
            print(result)
示例#7
0
    def test_empty_testsuite(self):
        j = junit.JUnit("test")
        expected = """
<testsuite errors="0" failures="0" name="test" tests="0" time="0.00" />"""
        self.assertEqual(expected.replace("\n", ""), j.to_xml())