pylint: Fixing pylint errors and warnings
[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_ovs = ""
44     version_dpdk = ""
45     version = ""
46     allowed_pkt = ["64", "128", "512", "1024", "1518"]
47     details = {"64": '', "128": '', "512": '', "1024": '', "1518": ''}
48
49     for row_reader in reader:
50         if allowed_pkt.count(row_reader['packet_size']) == 0:
51             logging.error("The framesize is not supported in opnfv dashboard")
52             continue
53
54         casename = _generate_test_name(row_reader['id'], int_data)
55         if "back2back" in row_reader['id']:
56             details[row_reader['packet_size']] = row_reader['b2b_frames']
57         else:
58             details[row_reader['packet_size']] = row_reader['throughput_rx_fps']
59
60     # Create version field
61     with open(int_data['pkg_list'], 'r') as pkg_file:
62         for line in pkg_file:
63             if "OVS_TAG" in line:
64                 version_ovs = line.replace(' ', '')
65                 version_ovs = version_ovs.replace('OVS_TAG?=', '')
66             if "DPDK_TAG" in line:
67                 if int_data['vanilla'] is False:
68                     version_dpdk = line.replace(' ', '')
69                     version_dpdk = version_dpdk.replace('DPDK_TAG?=', '')
70                 else:
71                     version_dpdk = "not used"
72     version = "OVS " + version_ovs.replace('\n', '') + " DPDK " + version_dpdk.replace('\n', '')
73
74     # Build body
75     body = {"project_name": "vsperf",
76             "case_name": casename,
77             "pod_name": int_data['pod'],
78             "installer": int_data['installer'],
79             "version": version,
80             "details": details}
81
82     my_data = requests.post(url, json=body)
83     logging.info("Results for %s sent to opnfv, http response: %s", casename, my_data)
84     logging.debug("opnfv url: %s", db_url)
85     logging.debug("the body sent to opnfv")
86     logging.debug(body)
87
88 def _generate_test_name(testcase, int_data):
89     """
90     the method generates testcase name for releng
91     """
92     vanilla = int_data['vanilla']
93     res_name = ""
94
95     names = {'phy2phy_tput': ["tput_ovsdpdk", "tput_ovs"],
96              'back2back': ["b2b_ovsdpdk", "b2b_ovs"],
97              'phy2phy_tput_mod_vlan': ["tput_mod_vlan_ovsdpdk", "tput_mod_vlan_ovs"],
98              'phy2phy_cont': ["cont_ovsdpdk", "cont_ovs"],
99              'pvp_cont': ["pvp_cont_ovsdpdkuser", "pvp_cont_ovsvirtio"],
100              'pvvp_cont': ["pvvp_cont_ovsdpdkuser", "pvvp_cont_ovsvirtio"],
101              'phy2phy_scalability': ["scalability_ovsdpdk", "scalability_ovs"],
102              'pvp_tput': ["pvp_tput_ovsdpdkuser", "pvp_tput_ovsvirtio"],
103              'pvp_back2back': ["pvp_b2b_ovsdpdkuser", "pvp_b2b_ovsvirtio"],
104              'pvvp_tput': ["pvvp_tput_ovsdpdkuser", "pvvp_tput_ovsvirtio"],
105              'pvvp_back2back': ["pvvp_b2b_ovsdpdkuser", "pvvp_b2b_ovsvirtio"],
106              'phy2phy_cpu_load': ["cpu_load_ovsdpdk", "cpu_load_ovs"],
107              'phy2phy_mem_load': ["mem_load_ovsdpdk", "mem_load_ovs"]}
108
109     for name, name_list in names.items():
110         if name != testcase:
111             continue
112         if vanilla is True:
113             res_name = name_list[1]
114         else:
115             res_name = name_list[0]
116         break
117
118     return res_name