integration: Support of PVP and PVVP integration TCs
[vswitchperf.git] / tools / opnfvdashboard / opnfvdashboard.py
1 """
2 vsperf2dashboard
3 """
4 # Copyright 2015 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
19 import os
20 import csv
21 import requests
22 import json
23 import logging
24
25 def results2opnfv_dashboard(results_path, int_data):
26     """
27     the method open the csv file with results and calls json encoder
28     """
29     testcases = os.listdir(results_path)
30     for test in testcases:
31         if not ".csv" in test:
32             continue
33         resfile = results_path + '/' + test
34         with open(resfile, 'r') as in_file:
35             reader = csv.DictReader(in_file)
36             _push_results(reader, int_data)
37
38 def _push_results(reader, int_data):
39     """
40     the method encodes results and sends them into opnfv dashboard
41     """
42     db_url = int_data['db_url']
43     url = db_url + "/results"
44     casename = ""
45     version_ovs = ""
46     version_dpdk = ""
47     version = ""
48     allowed_pkt = ["64", "128", "512", "1024", "1518"]
49     details = {"64": '', "128": '', "512": '', "1024": '', "1518": ''}
50
51     for row_reader in reader:
52         if allowed_pkt.count(row_reader['packet_size']) == 0:
53             logging.error("The framesize is not supported in opnfv dashboard")
54             continue
55
56         casename = _generate_test_name(row_reader['id'], int_data)
57         if "back2back" in row_reader['id']:
58             details[row_reader['packet_size']] = row_reader['b2b_frames']
59         else:
60             details[row_reader['packet_size']] = row_reader['throughput_rx_fps']
61
62     # Create version field
63     with open(int_data['pkg_list'], 'r') as pkg_file:
64         for line in pkg_file:
65             if "OVS_TAG" in line:
66                 version_ovs = line.replace(' ', '')
67                 version_ovs = version_ovs.replace('OVS_TAG?=', '')
68             if "DPDK_TAG" in line:
69                 if int_data['vanilla'] == False:
70                     version_dpdk = line.replace(' ', '')
71                     version_dpdk = version_dpdk.replace('DPDK_TAG?=', '')
72                 else:
73                     version_dpdk = "not used"
74     version = "OVS " + version_ovs.replace('\n', '') + " DPDK " + version_dpdk.replace('\n', '')
75
76     # Build body
77     body = {"project_name": "vsperf",
78             "case_name": casename,
79             "pod_name": int_data['pod'],
80             "installer": int_data['installer'],
81             "version": version,
82             "details": details}
83
84     myData = requests.post(url, json=body)
85     logging.info("Results for %s sent to opnfv, http response: %s", casename, myData)
86     logging.debug("opnfv url: %s", db_url)
87     logging.debug("the body sent to opnfv")
88     logging.debug(body)
89
90 def _generate_test_name(testcase, int_data):
91     """
92     the method generates testcase name for releng
93     """
94     cuse = int_data['cuse']
95     vanilla = int_data['vanilla']
96     res_name = ""
97
98     names = {'phy2phy_tput': ["tput_ovsdpdk", "tput_ovsdpdk", "tput_ovs"],
99              'back2back': ["b2b_ovsdpdk", "b2b_ovsdpdk", "b2b_ovs"],
100              'phy2phy_tput_mod_vlan': ["tput_mod_vlan_ovsdpdk", "tput_mod_vlan_ovsdpdk", "tput_mod_vlan_ovs"],
101              'phy2phy_cont': ["cont_ovsdpdk", "cont_ovsdpdk", "cont_ovs"],
102              'pvp_cont': ["pvp_cont_ovsdpdkuser", "pvp_cont_ovsdpdkcuse", "pvp_cont_ovsvirtio"],
103              'pvvp_cont': ["pvvp_cont_ovsdpdkuser", "pvvp_cont_ovsdpdkcuse", "pvvp_cont_ovsvirtio"],
104              'phy2phy_scalability': ["scalability_ovsdpdk", "scalability_ovsdpdk", "scalability_ovs"],
105              'pvp_tput': ["pvp_tput_ovsdpdkuser", "pvp_tput_ovsdpdkcuse", "pvp_tput_ovsvirtio"],
106              'pvp_back2back': ["pvp_b2b_ovsdpdkuser", "pvp_b2b_ovsdpdkcuse", "pvp_b2b_ovsvirtio"],
107              'pvvp_tput': ["pvvp_tput_ovsdpdkuser", "pvvp_tput_ovsdpdkcuse", "pvvp_tput_ovsvirtio"],
108              'pvvp_back2back': ["pvvp_b2b_ovsdpdkuser", "pvvp_b2b_ovsdpdkcuse", "pvvp_b2b_ovsvirtio"],
109              'phy2phy_cpu_load': ["cpu_load_ovsdpdk", "cpu_load_ovsdpdk", "cpu_load_ovs"],
110              'phy2phy_mem_load': ["mem_load_ovsdpdk", "mem_load_ovsdpdk", "mem_load_ovs"]}
111
112     for name, name_list in names.items():
113         if name != testcase:
114             continue
115         if vanilla == True:
116             res_name = name_list[2]
117         else:
118             if cuse == True:
119                 res_name = name_list[1]
120             else:
121                 res_name = name_list[0]
122         break
123
124     return res_name