From f36ccab454aa8ba156c234706d2667d5cae4ef94 Mon Sep 17 00:00:00 2001 From: Patrice Buriez Date: Fri, 9 Nov 2018 10:33:50 +0100 Subject: Generate report from a file instead of string ``$ yardstick report generate ...`` now renders a template stored in a file instead of from an imported string Instead of using Django, templating is done by jinja2, as this is used in other parts of Yardstick. JIRA: YARDSTICK-1367 Topic: report/html_table (2 of 11) Change-Id: Iaff53e7e28903e46164ce0977f6b8adbe04d23d7 Signed-off-by: Emma Foley Signed-off-by: Patrice Buriez --- yardstick/benchmark/core/report.py | 31 +++++----- yardstick/common/html_template.py | 124 ------------------------------------- yardstick/common/report.html.j2 | 121 ++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 138 deletions(-) create mode 100644 yardstick/common/report.html.j2 (limited to 'yardstick') diff --git a/yardstick/benchmark/core/report.py b/yardstick/benchmark/core/report.py index d0bf4ea5c..a43efecb7 100644 --- a/yardstick/benchmark/core/report.py +++ b/yardstick/benchmark/core/report.py @@ -14,20 +14,13 @@ import ast import re import uuid +import jinja2 from api.utils import influx - -from django.conf import settings -from django.template import Context -from django.template import Template - from oslo_utils import encodeutils from oslo_utils import uuidutils from yardstick.common import constants as consts -from yardstick.common.html_template import template from yardstick.common.utils import cliargs -settings.configure() - class Report(object): """Report commands. @@ -113,12 +106,22 @@ class Report(object): series['data'] = values temp_series.append(series) - Template_html = Template(template) - Context_html = Context({"series": temp_series, - "Timestamp": self.Timestamp, - "task_id": self.task_id, - "table": table_vals}) + template_dir = consts.YARDSTICK_ROOT_PATH + "yardstick/common" + template_environment = jinja2.Environment( + autoescape=False, + loader=jinja2.FileSystemLoader(template_dir), + trim_blocks=False) + + context = { + "series": temp_series, + "Timestamps": self.Timestamp, + "task_id": self.task_id, + "table": table_vals, + } + + template_html = template_environment.get_template("report.html.j2") + with open(consts.DEFAULT_HTML_FILE, "w") as file_open: - file_open.write(Template_html.render(Context_html)) + file_open.write(template_html.render(context)) print("Report generated. View /tmp/yardstick.htm") diff --git a/yardstick/common/html_template.py b/yardstick/common/html_template.py index e17c76637..c15dd8238 100644 --- a/yardstick/common/html_template.py +++ b/yardstick/common/html_template.py @@ -8,130 +8,6 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################# -template = """ - - - - - - - - - - - - - -
-

Yardstick User Interface

-

Report of {{task_id}} Generated

-
- -
-
-
-
-
-
-
-
-
-
-
-
- - - - - - -""" - report_template = """ diff --git a/yardstick/common/report.html.j2 b/yardstick/common/report.html.j2 new file mode 100644 index 000000000..ab76510ca --- /dev/null +++ b/yardstick/common/report.html.j2 @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + +
+

Yardstick User Interface

+

Report of {{task_id}} Generated

+
+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + + -- cgit 1.2.3-korg