Exemple #1
0
    def trends(self, api, *args, **kwargs):
        """Generate workloads trends HTML report."""

        tasks = kwargs.get("tasks", []) or list(args)

        if not tasks:
            print("ERROR: At least one task must be specified",
                  file=sys.stderr)
            return 1

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

        result = plot.trends(results)

        out = kwargs.get("out")
        if out:
            output_file = os.path.expanduser(out)

            with open(output_file, "w+") as f:
                f.write(result)
            if kwargs.get("open_it"):
                webbrowser.open_new_tab("file://" + os.path.realpath(out))
        else:
            print(result)
Exemple #2
0
    def trends(self, api, *args, **kwargs):
        """Generate workloads trends HTML report."""

        tasks = kwargs.get("tasks", []) or list(args)

        if not tasks:
            print("ERROR: At least one task must be specified",
                  file=sys.stderr)
            return 1

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

        result = plot.trends(results)

        out = kwargs.get("out")
        if out:
            output_file = os.path.expanduser(out)

            with open(output_file, "w+") as f:
                f.write(result)
            if kwargs.get("open_it"):
                webbrowser.open_new_tab("file://" + os.path.realpath(out))
        else:
            print(result)
Exemple #3
0
    def test_trends(self, mock_version_string, mock_get_template, mock_trends,
                    mock_task):
        task_dict = {
            "uuid": "task--uu--iiii-dd",
            "subtasks": [{
                "workloads": ["foo", "bar"]
            }]
        }

        trends = mock.Mock()
        trends.get_data.return_value = ["foo", "bar"]
        mock_trends.return_value = trends
        template = mock.Mock()
        template.render.return_value = "trends html"
        mock_get_template.return_value = template

        result = plot.trends([task_dict])

        self.assertEqual("trends html", result)
        self.assertEqual([
            mock.call("task--uu--iiii-dd", "foo"),
            mock.call("task--uu--iiii-dd", "bar")
        ], trends.add_result.mock_calls)
        mock_get_template.assert_called_once_with("task/trends.html")
        template.render.assert_called_once_with(version="42.0",
                                                data="[\"foo\", \"bar\"]",
                                                include_libs=False)
Exemple #4
0
 def generate(self):
     report = plot.trends(self.tasks_results, 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}
Exemple #5
0
    def trends(self, api, *args, **kwargs):
        """Generate workloads trends HTML report."""
        tasks = kwargs.get("tasks", []) or list(args)

        if not tasks:
            print(_("ERROR: At least one task must be specified"),
                  file=sys.stderr)
            return 1

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

            elif uuidutils.is_uuid_like(task_id):
                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"]
                    },
                    api.task.get_detailed(task_id)["results"])
            else:
                print(_("ERROR: Invalid UUID or file name passed: %s") %
                      task_id,
                      file=sys.stderr)
                return 1

            results.extend(task_results)

        result = plot.trends(results)

        out = kwargs.get("out")
        if out:
            output_file = os.path.expanduser(out)

            with open(output_file, "w+") as f:
                f.write(result)
            if kwargs.get("open_it"):
                webbrowser.open_new_tab("file://" + os.path.realpath(out))
        else:
            print(result)
Exemple #6
0
 def generate(self):
     report = plot.trends(self.tasks_results, 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}
Exemple #7
0
    def trends(self, *args, **kwargs):
        """Generate workloads trends HTML report."""
        tasks = kwargs.get("tasks", []) or list(args)

        if not tasks:
            print(_("ERROR: At least one task must be specified"),
                  file=sys.stderr)
            return 1

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

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

            results.extend(task_results)

        result = plot.trends(results)

        out = kwargs.get("out")
        if out:
            output_file = os.path.expanduser(out)

            with open(output_file, "w+") as f:
                f.write(result)
            if kwargs.get("open_it"):
                webbrowser.open_new_tab("file://" + os.path.realpath(out))
        else:
            print(result)
Exemple #8
0
    def test_trends(self, mock__extend_results, mock_get_template,
                    mock_trends):
        mock__extend_results.return_value = ["foo", "bar"]
        trends = mock.Mock()
        trends.get_data.return_value = ["foo", "bar"]
        mock_trends.return_value = trends
        template = mock.Mock()
        template.render.return_value = "trends html"
        mock_get_template.return_value = template

        self.assertEqual("trends html", plot.trends("tasks_results"))
        self.assertEqual([mock.call("foo"), mock.call("bar")],
                         trends.add_result.mock_calls)
        mock_get_template.assert_called_once_with("task/trends.html")
        template.render.assert_called_once_with(data="[\"foo\", \"bar\"]")
Exemple #9
0
def index():
  uuids = request.forms.getall('uuids')
  results = []
  for uuid in uuids:
    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.trends(results)
  return result
Exemple #10
0
    def test_trends(self, mock__extend_results, mock_get_template,
                    mock_trends):
        mock__extend_results.return_value = ["foo", "bar"]
        trends = mock.Mock()
        trends.get_data.return_value = ["foo", "bar"]
        mock_trends.return_value = trends
        template = mock.Mock()
        template.render.return_value = "trends html"
        mock_get_template.return_value = template

        self.assertEqual("trends html", plot.trends("tasks_results"))
        self.assertEqual([mock.call("foo"), mock.call("bar")],
                         trends.add_result.mock_calls)
        mock_get_template.assert_called_once_with("task/trends.html")
        template.render.assert_called_once_with(data="[\"foo\", \"bar\"]")
Exemple #11
0
    def trends(self, api, *args, **kwargs):
        """Generate workloads trends HTML report."""
        tasks = kwargs.get("tasks", []) or list(args)

        if not tasks:
            print(_("ERROR: At least one task must be specified"),
                  file=sys.stderr)
            return 1

        results = []
        for task_id in tasks:
            if os.path.exists(os.path.expanduser(task_id)):
                task_results = self._load_task_results_file(api, task_id)
            elif uuidutils.is_uuid_like(task_id):
                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"]
                    },
                    api.task.get_detailed(task_id=task_id)["results"])
            else:
                print(_("ERROR: Invalid UUID or file name passed: %s") %
                      task_id,
                      file=sys.stderr)
                return 1

            results.extend(task_results)

        result = plot.trends(results)

        out = kwargs.get("out")
        if out:
            output_file = os.path.expanduser(out)

            with open(output_file, "w+") as f:
                f.write(result)
            if kwargs.get("open_it"):
                webbrowser.open_new_tab("file://" + os.path.realpath(out))
        else:
            print(result)
Exemple #12
0
    def test_trends(self, mock_version_string, mock_get_template, mock_trends,
                    mock_task, mock_format_workload_config):
        task_dict = {"subtasks": [{"workloads": ["foo", "bar"]}]}

        trends = mock.Mock()
        trends.get_data.return_value = ["foo", "bar"]
        mock_trends.return_value = trends
        template = mock.Mock()
        template.render.return_value = "trends html"
        mock_get_template.return_value = template

        result = plot.trends([task_dict])

        self.assertEqual("trends html", result)
        self.assertEqual([
            mock.call("foo", mock_format_workload_config.return_value),
            mock.call("bar", mock_format_workload_config.return_value)
        ], trends.add_result.mock_calls)
        mock_get_template.assert_called_once_with("task/trends.html")
        template.render.assert_called_once_with(version="42.0",
                                                data="[\"foo\", \"bar\"]")
Exemple #13
0
    def test_trends(self, mock_version_string, mock_get_template, mock_trends,
                    mock_task):
        task_dict = {"uuid": "task--uu--iiii-dd",
                     "subtasks": [{"workloads": ["foo", "bar"]}]}

        trends = mock.Mock()
        trends.get_data.return_value = ["foo", "bar"]
        mock_trends.return_value = trends
        template = mock.Mock()
        template.render.return_value = "trends html"
        mock_get_template.return_value = template

        result = plot.trends([task_dict])

        self.assertEqual("trends html", result)
        self.assertEqual(
            [mock.call("task--uu--iiii-dd", "foo"),
             mock.call("task--uu--iiii-dd", "bar")],
            trends.add_result.mock_calls)
        mock_get_template.assert_called_once_with("task/trends.html")
        template.render.assert_called_once_with(version="42.0",
                                                data="[\"foo\", \"bar\"]")