Пример #1
0
    def test_plot(self, mock_version_string, mock_get_template,
                  mock__process_workloads, mock__make_source, **ddt_kwargs):
        task_dict = {
            "title":
            "",
            "description":
            "",
            "subtasks": [{
                "title": "",
                "description": "",
                "workloads": ["foo", "bar"]
            }]
        }
        mock__make_source.return_value = "source"
        mock__process_workloads.return_value = "scenarios"
        mock_get_template.return_value.render.return_value = "tasks_html"

        html = plot.plot([task_dict], **ddt_kwargs)

        self.assertEqual("tasks_html", html)
        mock_get_template.assert_called_once_with("task/report.html")
        mock__process_workloads.assert_called_once_with(["foo", "bar"])
        if "include_libs" in ddt_kwargs:
            mock_get_template.return_value.render.assert_called_once_with(
                version="42.0",
                data="\"scenarios\"",
                source="\"source\"",
                include_libs=ddt_kwargs["include_libs"])
        else:
            mock_get_template.return_value.render.assert_called_once_with(
                version="42.0",
                data="\"scenarios\"",
                source="\"source\"",
                include_libs=False)
Пример #2
0
 def test_plot(self, mock_dumps, mock_get_template, mock_objects,
               mock__process_tasks, **ddt_kwargs):
     mock__process_tasks.return_value = "source", "scenarios"
     mock_get_template.return_value.render.return_value = "tasks_html"
     mock_objects.Task.extend_results.return_value = ["extended_result"]
     tasks_results = [
         {"key": "foo_key", "sla": "foo_sla", "result": "foo_result",
          "full_duration": "foo_full_duration",
          "load_duration": "foo_load_duration"}]
     html = plot.plot(tasks_results, **ddt_kwargs)
     self.assertEqual(html, "tasks_html")
     generic_results = [
         {"id": None, "created_at": None, "updated_at": None,
          "task_uuid": None, "key": "foo_key",
          "data": {"raw": "foo_result",
                   "full_duration": "foo_full_duration",
                   "sla": "foo_sla",
                   "load_duration": "foo_load_duration"}}]
     mock_objects.Task.extend_results.assert_called_once_with(
         generic_results)
     mock_get_template.assert_called_once_with("task/report.html")
     mock__process_tasks.assert_called_once_with(["extended_result"])
     if "include_libs" in ddt_kwargs:
         mock_get_template.return_value.render.assert_called_once_with(
             data="json_scenarios", source="json_source",
             include_libs=ddt_kwargs["include_libs"])
     else:
         mock_get_template.return_value.render.assert_called_once_with(
             data="json_scenarios", source="json_source",
             include_libs=False)
Пример #3
0
 def test_plot(self, mock_dumps, mock_get_template, mock_objects,
               mock__process_tasks):
     mock__process_tasks.return_value = "source", "scenarios"
     mock_get_template.return_value.render.return_value = "tasks_html"
     mock_objects.Task.extend_results.return_value = ["extended_result"]
     tasks_results = [{
         "key": "foo_key",
         "sla": "foo_sla",
         "result": "foo_result",
         "full_duration": "foo_full_duration",
         "load_duration": "foo_load_duration"
     }]
     html = plot.plot(tasks_results)
     self.assertEqual(html, "tasks_html")
     generic_results = [{
         "id": None,
         "created_at": None,
         "updated_at": None,
         "task_uuid": None,
         "key": "foo_key",
         "data": {
             "raw": "foo_result",
             "full_duration": "foo_full_duration",
             "sla": "foo_sla",
             "load_duration": "foo_load_duration"
         }
     }]
     mock_objects.Task.extend_results.assert_called_once_with(
         generic_results)
     mock_get_template.assert_called_once_with("task/report.mako")
     mock__process_tasks.assert_called_once_with(["extended_result"])
     mock_get_template.return_value.render.assert_called_once_with(
         data="json_scenarios", source="json_source")
Пример #4
0
    def generate(self):
        report = plot.plot(self._generate_results(),
                           include_libs=self.INCLUDE_LIBS)

        if self.output_destination:
            return {"files": {self.output_destination: report},
                    "open": "file://" + os.path.abspath(
                        self.output_destination)}
        else:
            return {"print": report}
Пример #5
0
def index(uuid):
  results = []
  task_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"]},
                    rapi.task.get(uuid).get_results())
  results.extend(task_results)
  result = plot.plot(results, include_libs=("html_static"))
  return result
Пример #6
0
    def generate(self):
        results = self._generate()
        report = plot.plot(results, include_libs=self.INCLUDE_LIBS)

        if self.output_destination:
            return {
                "files": {
                    self.output_destination: report
                },
                "open": "file://" + os.path.abspath(self.output_destination)
            }
        else:
            return {"print": report}
Пример #7
0
    def test_plot(self, mock__process_results, mock_ui_utils):
        mock_render = mock.Mock(return_value="plot_html")
        mock_ui_utils.get_template = mock.Mock(return_value=mock.Mock(
            render=mock_render))
        task_data = [{"name": "a"}, {"name": "b"}]
        task_source = "JSON"
        mock__process_results.return_value = (task_source, task_data)

        result = plot.plot(["abc"])

        self.assertEqual(result, "plot_html")
        mock_render.assert_called_once_with(data=json.dumps(task_data),
                                            source=json.dumps(task_source))
        mock_ui_utils.get_template.assert_called_once_with("task/report.mako")
Пример #8
0
    def test_plot(self, mock__process_results, mock_ui_utils):
        mock_render = mock.Mock(return_value="plot_html")
        mock_ui_utils.get_template = mock.Mock(
            return_value=mock.Mock(render=mock_render))
        task_data = [{"name": "a"}, {"name": "b"}]
        task_source = "JSON"
        mock__process_results.return_value = (task_source, task_data)

        result = plot.plot(["abc"])

        self.assertEqual(result, "plot_html")
        mock_render.assert_called_once_with(
            data=json.dumps(task_data),
            source=json.dumps(task_source)
        )
        mock_ui_utils.get_template.assert_called_once_with("task/report.mako")
Пример #9
0
 def test_plot(self, mock_version_string, mock_dumps, mock_get_template,
               mock__extend_results, mock__process_tasks, **ddt_kwargs):
     mock__process_tasks.return_value = "source", "scenarios"
     mock_get_template.return_value.render.return_value = "tasks_html"
     mock__extend_results.return_value = ["extended_result"]
     html = plot.plot("tasks_results", **ddt_kwargs)
     self.assertEqual(html, "tasks_html")
     mock__extend_results.assert_called_once_with("tasks_results")
     mock_get_template.assert_called_once_with("task/report.html")
     mock__process_tasks.assert_called_once_with(["extended_result"])
     if "include_libs" in ddt_kwargs:
         mock_get_template.return_value.render.assert_called_once_with(
             version="42.0", data="json_scenarios", source="json_source",
             include_libs=ddt_kwargs["include_libs"])
     else:
         mock_get_template.return_value.render.assert_called_once_with(
             version="42.0", data="json_scenarios", source="json_source",
             include_libs=False)
Пример #10
0
 def test_plot(self, mock_version_string, mock_dumps, mock_get_template,
               mock__extend_results, mock__process_tasks, **ddt_kwargs):
     mock__process_tasks.return_value = "source", "scenarios"
     mock_get_template.return_value.render.return_value = "tasks_html"
     mock__extend_results.return_value = ["extended_result"]
     html = plot.plot("tasks_results", **ddt_kwargs)
     self.assertEqual(html, "tasks_html")
     mock__extend_results.assert_called_once_with("tasks_results")
     mock_get_template.assert_called_once_with("task/report.html")
     mock__process_tasks.assert_called_once_with(["extended_result"])
     if "include_libs" in ddt_kwargs:
         mock_get_template.return_value.render.assert_called_once_with(
             version="42.0", data="json_scenarios", source="json_source",
             include_libs=ddt_kwargs["include_libs"])
     else:
         mock_get_template.return_value.render.assert_called_once_with(
             version="42.0", data="json_scenarios", source="json_source",
             include_libs=False)
Пример #11
0
    def generate(self):
        results = []
        processed_names = {}
        for task in self.tasks_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
            results.append(task)

        report = plot.plot(results, include_libs=self.INCLUDE_LIBS)

        if self.output_destination:
            return {"files": {self.output_destination: report},
                    "open": "file://" + os.path.abspath(
                        self.output_destination)}
        else:
            return {"print": report}
Пример #12
0
    def test_plot(self, mock_version_string, mock_get_template,
                  mock__process_workloads, mock__make_source, **ddt_kwargs):
        task_dict = {"title": "", "description": "",
                     "subtasks": [{"title": "", "description": "",
                                   "workloads": ["foo", "bar"]}]}
        mock__make_source.return_value = "source"
        mock__process_workloads.return_value = "scenarios"
        mock_get_template.return_value.render.return_value = "tasks_html"

        html = plot.plot([task_dict], **ddt_kwargs)

        self.assertEqual("tasks_html", html)
        mock_get_template.assert_called_once_with("task/report.html")
        mock__process_workloads.assert_called_once_with(["foo", "bar"])
        if "include_libs" in ddt_kwargs:
            mock_get_template.return_value.render.assert_called_once_with(
                version="42.0", data="\"scenarios\"",
                source="\"source\"",
                include_libs=ddt_kwargs["include_libs"])
        else:
            mock_get_template.return_value.render.assert_called_once_with(
                version="42.0", data="\"scenarios\"",
                source="\"source\"", include_libs=False)
Пример #13
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)
Пример #14
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)
Пример #15
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)):
                tasks_results = self._load_task_results_file(
                    api, task_file_or_uuid)
            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_id=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-xml":
            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)
Пример #16
0
    def report(self, 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"],
                        "result": x["data"]["raw"],
                        "load_duration": x["data"]["load_duration"],
                        "full_duration": x["data"]["full_duration"]
                    },
                    api.Task.get(task_file_or_uuid).get_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)
Пример #17
0
    def report(self, 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"],
                               "result": x["data"]["raw"],
                               "load_duration": x["data"]["load_duration"],
                               "full_duration": x["data"]["full_duration"]},
                    api.Task.get(task_file_or_uuid).get_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)
 def plot(self, task):
     return plot.plot(self.results(task))