Add yardstick report for each task 17/39217/1
authorchenjiankun <chenjiankun1@huawei.com>
Mon, 14 Aug 2017 02:47:29 +0000 (02:47 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Mon, 14 Aug 2017 02:48:08 +0000 (02:48 +0000)
JIRA: YARDSTICK-784

Currently we have yardstick report in GUI.
But if users do not use GUI, they can't see this report.
So we need generate a report each task.

After run each test case, we can see report:
http://ip:port/report/report.html

Change-Id: Ic76cf57f55aa6680b91272e210135136f0225373
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
docker/nginx.sh
yardstick/benchmark/core/task.py
yardstick/common/constants.py
yardstick/common/html_template.py

index 26937d1..74009f5 100755 (executable)
@@ -26,6 +26,10 @@ server {
     location /gui/ {
         alias /etc/nginx/yardstick/gui/;
     }
+
+    location /report/ {
+        alias /tmp/;
+    }
 }
 EOF
 fi
index dd35bd4..ea3239e 100644 (file)
@@ -25,6 +25,7 @@ import errno
 import collections
 
 from six.moves import filter
+from jinja2 import Environment
 
 from yardstick.benchmark.contexts.base import Context
 from yardstick.benchmark.runners import base as base_runner
@@ -33,6 +34,7 @@ from yardstick.common.task_template import TaskTemplate
 from yardstick.common.utils import source_env
 from yardstick.common import utils
 from yardstick.common import constants
+from yardstick.common.html_template import report_template
 
 output_file_default = "/tmp/yardstick.out"
 config_file = '/etc/yardstick/yardstick.conf'
@@ -146,6 +148,7 @@ class Task(object):     # pragma: no cover
         result = self._get_format_result(testcases)
 
         self._do_output(output_config, result)
+        self._generate_reporting(result)
 
         total_end_time = time.time()
         LOG.info("total finished in %d secs",
@@ -158,6 +161,13 @@ class Task(object):     # pragma: no cover
         print("Done, exiting")
         return result
 
+    def _generate_reporting(self, result):
+        env = Environment()
+        with open(constants.REPORTING_FILE, 'w') as f:
+            f.write(env.from_string(report_template).render(result))
+
+        LOG.info('yardstick reporting generate in %s', constants.REPORTING_FILE)
+
     def _set_log(self):
         log_format = '%(asctime)s %(name)s %(filename)s:%(lineno)d %(levelname)s %(message)s'
         log_formatter = logging.Formatter(log_format)
index f80e104..fe394fd 100644 (file)
@@ -91,6 +91,7 @@ LOAD_IMAGES_SCRIPT = get_param('file.load_image_script',
 LOAD_IMAGES_SCRIPT = join(REPOS_DIR, LOAD_IMAGES_SCRIPT)
 DEFAULT_OUTPUT_FILE = get_param('file.output_file', '/tmp/yardstick.out')
 DEFAULT_HTML_FILE = get_param('file.html_file', '/tmp/yardstick.htm')
+REPORTING_FILE = get_param('file.reporting_file', '/tmp/report.html')
 
 # influxDB
 INFLUXDB_IP = get_param('influxdb.ip', SERVER_IP)
index 4b46e77..f030a2f 100644 (file)
@@ -131,3 +131,63 @@ $(function() {
 
 </body>
 </html>"""
+
+report_template = """
+<html>
+    <head>
+        <title>Yardstick Report</title>
+        <link href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css\
+/bootstrap.min.css" rel="stylesheet">
+    </head>
+    <div class="content">
+        <h3>Yardstick Report </h3>
+        <hr/>
+        <div>
+
+            <div>Task ID : {{result.task_id}} </div>
+            <div style="margin-top:5px;">Criteria :
+                <font> {{result.criteria}}</font>
+            </div>
+            <hr/>
+
+            <caption>Information</caption>
+            <table class="table table-striped">
+                <tr>
+                    <th>#</th>
+                    <th>key</th>
+                    <th>value</th>
+                </tr>
+                <tbody>
+                    {% for key, value in result.info.iteritems() %}
+                    <tr>
+                        <td>{{ loop.index }}</td>
+                        <td>{{key}}</td>
+                        <td>{{value}}</td>
+                    </tr>
+                    {% endfor %}
+                </tbody>
+            </table>
+            <hr/>
+
+            <caption>Test Cases</caption>
+            <table class="table table-striped">
+                <tr>
+                    <th>#</th>
+                    <th>key</th>
+                    <th>value</th>
+                </tr>
+                <tbody>
+                    {% for key, value in result.testcases.iteritems() %}
+                    <tr>
+                        <td>{{ loop.index }}</td>
+                        <td>{{key}}</td>
+                        <td>{{value.criteria}}</td>
+                    </tr>
+                    {% endfor %}
+                </tbody>
+            </table>
+
+        </div>
+    </div>
+</html>
+"""