makefile: Remove obsolete copy operations
[vswitchperf.git] / tools / report / report.py
index 806aecb..7d99101 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2015 Intel Corporation.
+# Copyright 2015-2016 Intel Corporation.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -24,14 +24,14 @@ import jinja2
 import logging
 
 from core.results.results_constants import ResultsConstants
-from conf import settings
+from conf import settings as S
 from tools import systeminfo
 
-_TEMPLATE_FILE = 'report.jinja'
+_TEMPLATE_FILES = ['report.jinja', 'report_rst.jinja']
 _ROOT_DIR = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
 
 
-def _get_env():
+def _get_env(result):
     """
     Get system configuration.
 
@@ -48,75 +48,104 @@ def _get_env():
     env = {
         'os': systeminfo.get_os(),
         'kernel': systeminfo.get_kernel(),
-        'nic': systeminfo.get_nic(),
+        'nics': systeminfo.get_nic(),
         'cpu': systeminfo.get_cpu(),
         'cpu_cores': systeminfo.get_cpu_cores(),
         'memory' : systeminfo.get_memory(),
         'platform': systeminfo.get_platform(),
+        'vsperf': systeminfo.get_version('vswitchperf'),
+        'traffic_gen': systeminfo.get_version(S.getValue('TRAFFICGEN')),
+        'vswitch': systeminfo.get_version(S.getValue('VSWITCH')),
     }
 
+    if S.getValue('VSWITCH').lower().count('dpdk'):
+        env.update({'dpdk': systeminfo.get_version('dpdk')})
+
+    if result[ResultsConstants.DEPLOYMENT].count('v'):
+        env.update({'vnf': systeminfo.get_version(S.getValue('VNF')),
+                    'guest_image': S.getValue('GUEST_IMAGE'),
+                    'loopback_app': list(map(systeminfo.get_version, S.getValue('GUEST_LOOPBACK'))),
+                   })
+
     return env
 
 
-def generate(input_file, tc_results, tc_stats):
+def generate(input_file, tc_results, tc_stats, test_type='performance'):
     """Generate actual report.
 
-    Generate a Markdown-formatted file using results of tests and some
+    Generate a Markdown and RST formatted files using results of tests and some
     parsed system info.
 
     :param input_file: Path to CSV results file
+    :param tc_results: A list of dictionaries with detailed test results.
+        Each dictionary represents test results for one of specified packet
+        sizes.
+    :param tc_stats: System statistics collected during testcase execution.
+        These statistics are overall statistics for all specified packet
+        sizes.
+    :test_type: Specifies type of the testcase. Supported values are
+        'performance' and 'integration'.
 
     :returns: Path to generated report
     """
-    output_file = '.'.join([os.path.splitext(input_file)[0], 'md'])
-
+    output_files = [('.'.join([os.path.splitext(input_file)[0], 'md'])),
+                    ('.'.join([os.path.splitext(input_file)[0], 'rst']))]
     template_loader = jinja2.FileSystemLoader(searchpath=_ROOT_DIR)
     template_env = jinja2.Environment(loader=template_loader)
-    template = template_env.get_template(_TEMPLATE_FILE)
 
     tests = []
     try:
         for result in tc_results:
             test_config = {}
-            for tc_conf in settings.getValue('PERFORMANCE_TESTS'):
-                if tc_conf['Name'] == result[ResultsConstants.ID]:
-                    test_config = tc_conf
-                    break
-
-            # remove id and deployment from results but store their values
-            tc_id = result[ResultsConstants.ID]
-            tc_deployment = result[ResultsConstants.DEPLOYMENT]
-            del result[ResultsConstants.ID]
-            del result[ResultsConstants.DEPLOYMENT]
+            if test_type == 'performance':
+                for tc_conf in S.getValue('PERFORMANCE_TESTS'):
+                    if tc_conf['Name'] == result[ResultsConstants.ID]:
+                        test_config = tc_conf
+                        break
+            elif test_type == 'integration':
+                for tc_conf in S.getValue('INTEGRATION_TESTS'):
+                    if tc_conf['Name'] == result[ResultsConstants.ID]:
+                        test_config = tc_conf
+                        break
+            else:
+                logging.error("Unsupported test type '%s'. Test details are not known.", test_type)
 
             # pass test results, env details and configuration to template
             tests.append({
-                'ID': tc_id.upper(),
-                'id': tc_id,
-                'deployment': tc_deployment,
+                'ID': result[ResultsConstants.ID].upper(),
+                'id': result[ResultsConstants.ID],
+                'deployment': result[ResultsConstants.DEPLOYMENT],
                 'conf': test_config,
                 'result': result,
-                'env': _get_env(),
+                'env': _get_env(result),
                 'stats': tc_stats
             })
 
+            # remove id and deployment from results before rendering
+            # but after _get_env() is called; tests dict has its shallow copy
+            del result[ResultsConstants.ID]
+            del result[ResultsConstants.DEPLOYMENT]
+
         template_vars = {
             'tests': tests,
         }
-
-        output_text = template.render(template_vars)
-        with open(output_file, 'w') as file_:
-            file_.write(output_text)
-            logging.info('Test report written to "%s"', output_file)
+        i = 0
+        for output_file in output_files:
+            template = template_env.get_template(_TEMPLATE_FILES[i])
+            output_text = template.render(template_vars) #pylint: disable=no-member
+            with open(output_file, 'w') as file_:
+                file_.write(output_text)
+                logging.info('Test report written to "%s"', output_file)
+            i += 1
 
     except KeyError:
         logging.info("Report: Ignoring file (Wrongly defined columns): %s",
                      (input_file))
         raise
-    return output_file
+    return output_files
 
 
 if __name__ == '__main__':
-    settings.load_from_dir('conf')
+    S.load_from_dir('conf')
     OUT = generate(sys.argv[1], '', '')
     print('Test report written to "%s"...' % OUT)