diff options
author | Patrice Buriez <patrice.buriez@intel.com> | 2018-11-09 10:33:50 +0100 |
---|---|---|
committer | Patrice Buriez <patrice.buriez@intel.com> | 2018-11-22 20:13:31 +0100 |
commit | f36ccab454aa8ba156c234706d2667d5cae4ef94 (patch) | |
tree | f8244c44d5e7cdf4b17edcac4d972e52a27a0ae4 /yardstick/benchmark/core/report.py | |
parent | 5d66ab59d2c6ab5784c965392fa7a9e137efc9d2 (diff) |
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 <emma.l.foley@intel.com>
Signed-off-by: Patrice Buriez <patrice.buriez@intel.com>
Diffstat (limited to 'yardstick/benchmark/core/report.py')
-rw-r--r-- | yardstick/benchmark/core/report.py | 31 |
1 files changed, 17 insertions, 14 deletions
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") |