1 # Copyright 2015 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 vSwitch Characterization Report Generation.
18 Generate reports in format defined by X.
26 from core.results.results_constants import ResultsConstants
27 from conf import settings
28 from tools import systeminfo
30 _TEMPLATE_FILE = 'report.jinja'
31 _ROOT_DIR = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
36 Get system configuration.
38 :returns: Return a dictionary of the test environment.
39 The following is an example return value:
40 {'kernel': '3.10.0-229.4.2.el7.x86_64',
42 'cpu': ' CPU 2.30GHz',
43 'platform': '[2 sockets]',
49 'os': systeminfo.get_os(),
50 'kernel': systeminfo.get_kernel(),
51 'nic': systeminfo.get_nic(),
52 'cpu': systeminfo.get_cpu(),
53 'cpu_cores': systeminfo.get_cpu_cores(),
54 'memory' : systeminfo.get_memory(),
55 'platform': systeminfo.get_platform(),
61 def generate(input_file, tc_results, tc_stats):
62 """Generate actual report.
64 Generate a Markdown-formatted file using results of tests and some
67 :param input_file: Path to CSV results file
69 :returns: Path to generated report
71 output_file = '.'.join([os.path.splitext(input_file)[0], 'md'])
73 template_loader = jinja2.FileSystemLoader(searchpath=_ROOT_DIR)
74 template_env = jinja2.Environment(loader=template_loader)
75 template = template_env.get_template(_TEMPLATE_FILE)
79 for result in tc_results:
81 for tc_conf in settings.getValue('PERFORMANCE_TESTS'):
82 if tc_conf['Name'] == result[ResultsConstants.ID]:
86 # remove id and deployment from results but store their values
87 tc_id = result[ResultsConstants.ID]
88 tc_deployment = result[ResultsConstants.DEPLOYMENT]
89 del result[ResultsConstants.ID]
90 del result[ResultsConstants.DEPLOYMENT]
92 # pass test results, env details and configuration to template
96 'deployment': tc_deployment,
107 output_text = template.render(template_vars)
108 with open(output_file, 'w') as file_:
109 file_.write(output_text)
110 logging.info('Test report written to "%s"', output_file)
113 logging.info("Report: Ignoring file (Wrongly defined columns): %s",
119 if __name__ == '__main__':
120 settings.load_from_dir('conf')
121 OUT = generate(sys.argv[1], '', '')
122 print('Test report written to "%s"...' % OUT)