aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick
diff options
context:
space:
mode:
authorPatrice Buriez <patrice.buriez@intel.com>2018-11-09 10:33:50 +0100
committerPatrice Buriez <patrice.buriez@intel.com>2018-11-22 20:13:31 +0100
commitf36ccab454aa8ba156c234706d2667d5cae4ef94 (patch)
treef8244c44d5e7cdf4b17edcac4d972e52a27a0ae4 /yardstick
parent5d66ab59d2c6ab5784c965392fa7a9e137efc9d2 (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')
-rw-r--r--yardstick/benchmark/core/report.py31
-rw-r--r--yardstick/common/html_template.py124
-rw-r--r--yardstick/common/report.html.j2121
3 files changed, 138 insertions, 138 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")
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 = """
-<html>
-<body>
-<head>
-<meta charset="utf-8">
-<meta name="viewport" content="width=device-width, initial-scale=1">
-<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7\
-/css/bootstrap.min.css">
-<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1\
-/jquery.min.js"></script>
-<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7\
-/js/bootstrap.min.js"></script>
-<script src="https://code.highcharts.com/highcharts.js"></script>
-<script src="jquery.min.js"></script>
-<script src="highcharts.js"></script>
-</head>
-<style>
-
-table{
- overflow-y: scroll;
- height: 360px;
- display: block;
- }
-
- header,h3{
- font-family:Frutiger;
- clear: left;
- text-align: center;
-}
-</style>
-<header class="jumbotron text-center">
- <h1>Yardstick User Interface</h1>
- <h4>Report of {{task_id}} Generated</h4>
-</header>
-
-<div class="container">
- <div class="row">
- <div class="col-md-4">
- <div class="table-responsive" >
- <table class="table table-hover" > </table>
- </div>
- </div>
- <div class="col-md-8" >
- <div id="container" ></div>
- </div>
- </div>
-</div>
-<script>
- var arr, tab, th, tr, td, tn, row, col, thead, tbody;
- arr={{table|safe}}
- tab = document.getElementsByTagName('table')[0];
- thead=document.createElement('thead');
- tr = document.createElement('tr');
- for(row=0;row<Object.keys(arr).length;row++)
- {
- th = document.createElement('th');
- tn = document.createTextNode(Object.keys(arr).sort()[row]);
- th.appendChild(tn);
- tr.appendChild(th);
- thead.appendChild(tr);
- }
- tab.appendChild(thead);
- tbody=document.createElement('tbody');
-
- for (col = 0; col < arr[Object.keys(arr)[0]].length; col++){
- tr = document.createElement('tr');
- for(row=0;row<Object.keys(arr).length;row++)
- {
- td = document.createElement('td');
- tn = document.createTextNode(arr[Object.keys(arr).sort()[row]][col]);
- td.appendChild(tn);
- tr.appendChild(td);
- }
- tbody.appendChild(tr);
- }
-tab.appendChild(tbody);
-
-</script>
-
-<script language="JavaScript">
-
-$(function() {
- $('#container').highcharts({
- title: {
- text: 'Yardstick test results',
- x: -20 //center
- },
- subtitle: {
- text: 'Report of {{task_id}} Task Generated',
- x: -20
- },
- xAxis: {
- title: {
- text: 'Timestamp'
- },
- categories:{{Timestamp|safe}}
- },
- yAxis: {
-
- plotLines: [{
- value: 0,
- width: 1,
- color: '#808080'
- }]
- },
- tooltip: {
- valueSuffix: ''
- },
- legend: {
- layout: 'vertical',
- align: 'right',
- verticalAlign: 'middle',
- borderWidth: 0
- },
- series: {{series|safe}}
- });
-});
-
-</script>
-
-
-</body>
-</html>"""
-
report_template = """
<html>
<head>
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 @@
+<!DOCTYPE html>
+<html>
+
+<!--
+ Copyright (c) 2017 Rajesh Kudaka <4k.rajesh@gmail.com>
+ Copyright (c) 2018 Intel Corporation.
+
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Apache License, Version 2.0
+ which accompanies this distribution, and is available at
+ http://www.apache.org/licenses/LICENSE-2.0
+-->
+
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
+ <script src="https://code.highcharts.com/highcharts.js"></script>
+
+ <style>
+ table {
+ overflow-y: scroll;
+ height: 360px;
+ display: block;
+ }
+ header {
+ font-family: Frutiger;
+ clear: left;
+ text-align: center;
+ }
+ </style>
+ </head>
+
+ <body>
+ <header class="jumbotron text-center">
+ <h1>Yardstick User Interface</h1>
+ <h4>Report of {{task_id}} Generated</h4>
+ </header>
+
+ <div class="container">
+ <div class="row">
+ <div class="col-md-4">
+ <div class="table-responsive">
+ <table class="table table-hover"></table>
+ </div>
+ </div>
+ <div class="col-md-8">
+ <div id="container"></div>
+ </div>
+ </div>
+ </div>
+
+ <script>
+ var arr, tab, th, tr, td, tn, row, col, thead, tbody;
+ arr = {{table|safe}};
+ tab = document.getElementsByTagName('table')[0];
+
+ thead = document.createElement('thead');
+ tr = document.createElement('tr');
+ for (col = 0; col < Object.keys(arr).length; col++) {
+ th = document.createElement('th');
+ tn = document.createTextNode(Object.keys(arr).sort()[col]);
+ th.appendChild(tn);
+ tr.appendChild(th);
+ thead.appendChild(tr);
+ }
+ tab.appendChild(thead);
+
+ tbody = document.createElement('tbody');
+ for (row = 0; row < arr[Object.keys(arr)[0]].length; row++) {
+ tr = document.createElement('tr');
+ for (col = 0; col < Object.keys(arr).length; col++) {
+ td = document.createElement('td');
+ tn = document.createTextNode(arr[Object.keys(arr).sort()[col]][row]);
+ td.appendChild(tn);
+ tr.appendChild(td);
+ }
+ tbody.appendChild(tr);
+ }
+ tab.appendChild(tbody);
+
+ $(function() {
+ $('#container').highcharts({
+ title: {
+ text: 'Yardstick test results',
+ x: -20, //center
+ },
+ subtitle: {
+ text: 'Report of {{task_id}} Task Generated',
+ x: -20,
+ },
+ xAxis: {
+ title: {
+ text: 'Timestamp',
+ },
+ categories: {{Timestamps|safe}},
+ },
+ yAxis: {
+ plotLines: [{
+ value: 0,
+ width: 1,
+ color: '#808080',
+ }],
+ },
+ tooltip: {
+ valueSuffix: '',
+ },
+ legend: {
+ layout: 'vertical',
+ align: 'right',
+ verticalAlign: 'middle',
+ borderWidth: 0,
+ },
+ series: {{series|safe}},
+ });
+ });
+ </script>
+ </body>
+</html>