Merge "docs: Update E release notes"
[vswitchperf.git] / tools / opnfvdashboard / opnfvdashboard.py
1 """
2 vsperf2dashboard
3 """
4 # Copyright 2015-2017 Intel Corporation.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #   http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 import os
19 import csv
20 import logging
21 import requests
22
23 def results2opnfv_dashboard(results_path, int_data):
24     """
25     the method open the csv file with results and calls json encoder
26     """
27     testcases = os.listdir(results_path)
28     for test in testcases:
29         if not ".csv" in test:
30             continue
31         resfile = results_path + '/' + test
32         with open(resfile, 'r') as in_file:
33             reader = csv.DictReader(in_file)
34             _push_results(reader, int_data)
35
36 def _push_results(reader, int_data):
37     """
38     the method encodes results and sends them into opnfv dashboard
39     """
40     db_url = int_data['db_url']
41     url = db_url + "/results"
42     casename = ""
43     version_vswitch = ""
44     version_dpdk = ""
45     version = ""
46     allowed_pkt = ["64", "128", "512", "1024", "1518"]
47     details = {"64": '', "128": '', "512": '', "1024": '', "1518": ''}
48     test_start = None
49     test_stop = None
50     vswitch = None
51
52     for row_reader in reader:
53         if allowed_pkt.count(row_reader['packet_size']) == 0:
54             logging.error("The framesize is not supported in opnfv dashboard")
55             continue
56
57         # test execution time includes all frame sizes, so start & stop time
58         # is the same (repeated) for every framesize in CSV file
59         if test_start is None:
60             test_start = row_reader['start_time']
61             test_stop = row_reader['stop_time']
62             # CI job executes/reports TCs per vswitch type
63             vswitch = row_reader['vswitch']
64
65         casename = "{}_{}".format(row_reader['id'], row_reader['vswitch'].lower())
66         if "back2back" in row_reader['id']:
67             details[row_reader['packet_size']] = row_reader['b2b_frames']
68         else:
69             details[row_reader['packet_size']] = row_reader['throughput_rx_fps']
70
71     # Create version field
72     with open(int_data['pkg_list'], 'r') as pkg_file:
73         for line in pkg_file:
74             if "OVS_TAG" in line and vswitch.startswith('Ovs'):
75                 version_vswitch = line.replace(' ', '')
76                 version_vswitch = "OVS " + version_vswitch.replace('OVS_TAG?=', '')
77             if "VPP_TAG" in line and vswitch.startswith('Vpp'):
78                 version_vswitch = line.replace(' ', '')
79                 version_vswitch = "VPP " + version_vswitch.replace('VPP_TAG?=', '')
80             if "DPDK_TAG" in line:
81                 # DPDK_TAG is not used by VPP, it downloads its onw DPDK version
82                 if vswitch == "OvsDpdkVhost":
83                     version_dpdk = line.replace(' ', '')
84                     version_dpdk = " DPDK {}".format(
85                         version_dpdk.replace('DPDK_TAG?=', ''))
86     version = version_vswitch.replace('\n', '') + version_dpdk.replace('\n', '')
87
88     # Build body
89     body = {"project_name": "vsperf",
90             "scenario": "vsperf",
91             "start_date": test_start,
92             "stop_date": test_stop,
93             "case_name": casename,
94             "pod_name": int_data['pod'],
95             "installer": int_data['installer'],
96             "version": version,
97             "build_tag": int_data['build_tag'],
98             "criteria": int_data['criteria'],
99             "details": details}
100
101     my_data = requests.post(url, json=body)
102     logging.info("Results for %s sent to opnfv, http response: %s", casename, my_data)
103     logging.debug("opnfv url: %s", db_url)
104     logging.debug("the body sent to opnfv")
105     logging.debug(body)