Exemplo n.º 1
0
Arquivo: task.py Projeto: ugvddm/rally
    def plot2html(self, task_id, out=None, open_it=False):
        results = map(lambda x: {"key": x["key"], "result": x["data"]["raw"]}, db.task_result_get_all_by_uuid(task_id))

        output_file = out or ("%s.html" % task_id)
        with open(output_file, "w+") as f:
            f.write(plot.plot(results))

        if open_it:
            webbrowser.open_new_tab("file://" + os.path.realpath(output_file))
Exemplo n.º 2
0
    def plot2html(self, task_id=None, out=None, open_it=False):
        results = map(lambda x: {
            "key": x["key"],
            'result': x['data']['raw']
        }, db.task_result_get_all_by_uuid(task_id))

        output_file = out or ("%s.html" % task_id)
        with open(output_file, "w+") as f:
            f.write(plot.plot(results))

        if open_it:
            webbrowser.open_new_tab("file://" + os.path.realpath(output_file))
Exemplo n.º 3
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")
Exemplo n.º 4
0
    def test_plot(self, mock_proc_results, mock_utils):
        mock_render = mock.Mock(return_value="plot_html")
        mock_utils.get_template = mock.Mock(
            return_value=mock.Mock(render=mock_render))
        task_data = [{"name": "a"}, {"name": "b"}]
        task_source = "JSON"
        mock_proc_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_utils.get_template.assert_called_once_with("task/report.mako")
Exemplo n.º 5
0
    def report(self, task_id=None, out=None, open_it=False):
        """Generate HTML report file for specified task.

        :param task_id: int, task identifier
        :param out: str, output html file name
        :param open_it: bool, whether to open output file in web browser
        """
        results = map(lambda x: {"key": x["key"],
                                 "result": x["data"]["raw"]},
                      db.task_result_get_all_by_uuid(task_id))
        if out:
            out = os.path.expanduser(out)
        output_file = out or ("%s.html" % task_id)
        with open(output_file, "w+") as f:
            f.write(plot.plot(results))

        if open_it:
            webbrowser.open_new_tab("file://" + os.path.realpath(output_file))
Exemplo n.º 6
0
    def report(self, task_id=None, out=None, open_it=False):
        """Generate HTML report file for specified task.

        :param task_id: int, task identifier
        :param out: str, output html file name
        :param open_it: bool, whether to open output file in web browser
        """
        results = map(lambda x: {
            "key": x["key"],
            "result": x["data"]["raw"]
        }, db.task_result_get_all_by_uuid(task_id))
        if out:
            out = os.path.expanduser(out)
        output_file = out or ("%s.html" % task_id)
        with open(output_file, "w+") as f:
            f.write(plot.plot(results))

        if open_it:
            webbrowser.open_new_tab("file://" + os.path.realpath(output_file))
Exemplo n.º 7
0
    def test_plot(self, mock_proc_results, mock_dirname, mock_template,
                  mock_open):
        mock_dirname.return_value = "abspath"
        mock_open.return_value = mock_open
        mock_open.__enter__.return_value = mock_open
        mock_open.read.return_value = "some_template"

        templ = mock.MagicMock()
        templ.render.return_value = "output"
        mock_template.return_value = templ
        mock_proc_results.return_value = [{"name": "a"}, {"name": "b"}]

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

        self.assertEqual(result, templ.render.return_value)
        templ.render.assert_called_once_with(
            data=json.dumps(mock_proc_results.return_value))
        mock_template.assert_called_once_with(mock_open.read.return_value)
        mock_open.assert_called_once_with("%s/src/index.mako" %
                                          mock_dirname.return_value)
Exemplo n.º 8
0
    def test_plot(self, mock_proc_results, mock_dirname, mock_template, mock_open):
        mock_dirname.return_value = "abspath"
        mock_open.return_value = mock_open
        mock_open.__enter__.return_value = mock_open
        mock_open.read.return_value = "some_template"

        templ = mock.MagicMock()
        templ.render.return_value = "output"
        mock_template.return_value = templ
        mock_proc_results.return_value = [{"name": "a"}, {"name": "b"}]

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

        self.assertEqual(result, templ.render.return_value)
        templ.render.assert_called_once_with(
            data=json.dumps(mock_proc_results.return_value),
            tasks=map(lambda r: r["name"], mock_proc_results.return_value),
        )
        mock_template.assert_called_once_with(mock_open.read.return_value)
        mock_open.assert_called_once_with("%s/src/index.mako" % mock_dirname.return_value)
Exemplo n.º 9
0
    def report(self, tasks=None, out=None, open_it=False):
        """Generate HTML 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 html file name
        :param open_it: bool, whether to open output file in web browser
        """

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

        results = list()
        processed_names = dict()
        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, objects.task.TASK_RESULT_SCHEMA)
                        except jsonschema.ValidationError as e:
                            print(
                                _("ERROR: Invalid task result format in %s") %
                                task_file_or_uuid,
                                file=sys.stderr)
                            if logging.is_debug():
                                print(e, file=sys.stderr)
                            else:
                                print(e.message, 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"]
                    },
                    objects.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)

        output_file = os.path.expanduser(out)
        with open(output_file, "w+") as f:
            f.write(plot.plot(results))

        if open_it:
            webbrowser.open_new_tab("file://" + os.path.realpath(out))
Exemplo n.º 10
0
    def report(self, tasks=None, out=None, open_it=False):
        """Generate HTML 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 html file name
        :param open_it: bool, whether to open output file in web browser
        """

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

        results = list()
        processed_names = dict()
        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,
                                objects.task.TASK_RESULT_SCHEMA)
                        except jsonschema.ValidationError as e:
                            print(_("ERROR: Invalid task result format in %s")
                                  % task_file_or_uuid, file=sys.stderr)
                            if logging.is_debug():
                                print(e, file=sys.stderr)
                            else:
                                print(e.message, 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"]},
                    objects.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)

        output_file = os.path.expanduser(out)
        with open(output_file, "w+") as f:
            f.write(plot.plot(results))

        if open_it:
            webbrowser.open_new_tab("file://" + os.path.realpath(out))
Exemplo n.º 11
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 or html)
        """

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

        results = []
        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,
                                objects.task.TASK_RESULT_SCHEMA)
                        except jsonschema.ValidationError as e:
                            print(_("ERROR: Invalid task result format in %s")
                                  % task_file_or_uuid, file=sys.stderr)
                            if logging.is_debug():
                                print(e, file=sys.stderr)
                            else:
                                print(e.message, 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"]},
                    objects.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)

        output_file = os.path.expanduser(out)

        if out_format == "html":
            with open(output_file, "w+") as f:
                f.write(plot.plot(results))
            if open_it:
                webbrowser.open_new_tab("file://" + os.path.realpath(out))
        elif out_format == "junit":
            test_suite = junit.JUnit("Rally test suite")
            for result in results:
                if (isinstance(result["sla"], list) and
                   not all([sla["success"] for sla in result["sla"]])):
                    outcome = junit.JUnit.FAILURE
                else:
                    outcome = junit.JUnit.SUCCESS
                test_suite.add_test(result["key"]["name"],
                                    result["full_duration"],
                                    outcome=outcome)
            with open(output_file, "w+") as f:
                f.write(test_suite.to_xml())
        else:
            print(_("Invalid output format: %s") % out_format,
                  file=sys.stderr)
            return 1
Exemplo n.º 12
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 or html)
        """

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

        results = []
        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, objects.task.TASK_RESULT_SCHEMA)
                        except jsonschema.ValidationError as e:
                            print(
                                _("ERROR: Invalid task result format in %s") %
                                task_file_or_uuid,
                                file=sys.stderr)
                            if logging.is_debug():
                                print(e, file=sys.stderr)
                            else:
                                print(e.message, 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"]
                    },
                    objects.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)

        output_file = os.path.expanduser(out)

        if out_format == "html":
            with open(output_file, "w+") as f:
                f.write(plot.plot(results))
            if open_it:
                webbrowser.open_new_tab("file://" + os.path.realpath(out))
        elif out_format == "junit":
            test_suite = junit.JUnit("Rally test suite")
            for result in results:
                if (isinstance(result["sla"], list)
                        and not all([sla["success"]
                                     for sla in result["sla"]])):
                    outcome = junit.JUnit.FAILURE
                else:
                    outcome = junit.JUnit.SUCCESS
                test_suite.add_test(result["key"]["name"],
                                    result["full_duration"],
                                    outcome=outcome)
            with open(output_file, "w+") as f:
                f.write(test_suite.to_xml())
        else:
            print(_("Invalid output format: %s") % out_format, file=sys.stderr)
            return 1