1 # copyrighi (c) 2015 Orange
3 # morgan.richomme@orange.com
5 # This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # This script is used to get data from test DB
12 # and format them into a json format adapted for a dashboard
18 from vPing2Dashboard import format_vPing_for_dashboard
23 """ describes the test criteria platform """
30 self.installer = 'all'
32 def setCriteria(self, project, testcase, pod_name,
33 duration, version, installer):
34 self.project = project
35 self.testcase = testcase
36 self.pod_name = pod_name
37 self.duration = duration
38 self.version = version
39 self.installer = installer
41 def format_criteria(self, name):
42 if(name == 'all' or name == 0):
45 if(type(name) == int):
46 return "_" + str(name)
51 pod_name = self.format_criteria(self.pod_name)
52 version_name = self.format_criteria(self.version)
53 installer_name = self.format_criteria(self.installer)
54 duration_name = self.format_criteria(self.duration)
56 fileName = "result_" + self.project + "_" + self.testcase + \
57 pod_name + version_name + installer_name + \
58 duration_name + ".json"
60 print "Impossible to format json file name"
65 # retrieve the list of pods
66 url = db_url + "/pods"
68 headers = {'Content-Type': 'application/json'}
71 db_data = requests.get(url, headers=headers)
72 # Get result as a json object
73 pods_data = json.loads(db_data.text)
75 pods = pods_data['pods']
78 # cast int becase otherwise API retrieve 1.0
79 # TODO check format with API
80 pods_table.append(pod['name'])
82 pods_table.append('all')
85 print "Error retrieving the list of PODs"
89 def get_versions(db_url):
90 # retrieve the list of versions
91 # TODO not supported in API yet
92 url = db_url + "/results"
94 headers = {'Content-Type': 'application/json'}
97 db_data = requests.get(url, headers=headers)
98 # Get result as a json object
99 versions_data = json.loads(db_data.text)
101 versions = versions_data['test_results']
103 for version in versions:
104 if (version['version'] is not None):
105 versions_table.append(version['version'])
107 versions_table.append('all')
108 versions_table = sorted(set(versions_table))
109 return versions_table
111 print "Error retrieving the list of OPNFV versions"
115 def get_installers(db_url):
116 # retrieve the list of installers
117 # TODO not supported in API yet
118 url = db_url + "/results"
120 headers = {'Content-Type': 'application/json'}
123 db_data = requests.get(url, headers=headers)
124 # Get result as a json object
125 installers_data = json.loads(db_data.text)
127 installers = installers_data['test_results']
129 installers_table = []
130 for installer in installers:
131 if (installer['installer'] is not None):
132 installers_table.append(installer['installer'])
134 installers_table.append('all')
135 installers_table = sorted(set(installers_table))
136 return installers_table
138 print "Error retrieving the list of OPNFV installers"
142 def get_testcases(db_url, project):
143 # retrieve the list of pods
144 url = db_url + "/test_projects/" + project + "/cases"
146 headers = {'Content-Type': 'application/json'}
149 db_data = requests.get(url, headers=headers)
150 # Get result as a json object
151 testcases_data = json.loads(db_data.text)
153 testcases = testcases_data['test_cases']
155 for testcase in testcases:
156 testcases_table.append(testcase['name'])
158 testcases_table.append('all')
160 return testcases_table
162 print "Error retrieving the list of testcases"
166 def get_results(db_url, test_criteria):
168 # use param to filter request to result DB
169 # if not precised => no filter
176 # - timeframe (last 30 days, 365 days, since beginning of the project)
178 # - vPing tests since 2 months
179 # - Tempest tests on LF POD2 fuel based / Arno stable since the beginning
180 # - yardstick tests on any POD since 30 days
181 # - Qtip tests on dell-test1 POD
183 # params = {"pod_name":pod, "testcase":testcase}
184 # filter_date = days # data from now - days
186 test_project = test_criteria.project
187 testcase = test_criteria.testcase
188 period = test_criteria.duration
189 version = test_criteria.version
190 installer = test_criteria.installer
191 pod = test_criteria.pod_name
193 # TODO complete params (installer type, testcase, version )
194 # need API to be up to date
195 # we assume that criteria could be used at the API level
196 # no need to processing on date for instance
197 # params = {"pod_name": pod_name}
200 headers = {'Content-Type': 'application/json'}
203 # if criteria is all => remove criteria
204 url = db_url + "/results?project=" + test_project + "&case=" + testcase
208 if (installer != "all"):
209 url += "&installer=" + installer
210 if (version != "all"):
211 url += "&version=" + version
212 url += "&period=" + str(period)
214 # Send Request to Test DB
215 myData = requests.get(url, headers=headers)
217 # Get result as a json object
218 myNewData = json.loads(myData.text)
221 myDataResults = myNewData['test_results']
226 def generateJson(test_name, test_case, db_url):
227 # pod_id = "opnfv-jump-1'
228 # test_version = 'Arno master'
229 # test_installer = 'fuel'
230 # test_retention = 30
232 pods = get_pods(db_url)
233 versions = get_versions(db_url)
234 installers = get_installers(db_url)
236 test_durations = [90, 365, 0] # 0 means since the beginning
241 for version in versions:
243 for installer in installers:
244 # all the retention time
245 for test_duration in test_durations:
247 criteria = TestCriteria()
248 criteria.setCriteria(test_name, test_case, pod,
249 test_duration, version, installer)
250 format_data_for_dashboard(criteria)
253 def format_data_for_dashboard(criteria):
255 # Depending on the use case, json for dashboarding is customized
256 # depending on the graph you want to show
258 if (criteria.testcase == "vPing"):
259 format_vPing_for_dashboard(criteria)