3 # Copyright (c) 2015 Orange
4 # morgan.richomme@orange.com
6 # This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # This script is used to get data from test DB
13 # and format them into a json format adapted for a dashboard
19 from vPing2Dashboard import format_vPing_for_dashboard
24 """ describes the test criteria platform """
31 self.installer = 'all'
33 def setCriteria(self, project, testcase, pod_id,
34 duration, version, installer):
35 self.project = project
36 self.testcase = testcase
38 self.duration = duration
39 self.version = version
40 self.installer = installer
42 def format_criteria(self, name):
43 if(name == 'all' or name == 0):
46 if(type(name) == int):
47 return "-" + str(name)
52 pod_name = self.format_criteria(self.pod_id)
53 version_name = self.format_criteria(self.version)
54 installer_name = self.format_criteria(self.installer)
55 duration_name = self.format_criteria(self.duration)
57 fileName = "result-" + self.project + "-" + self.testcase + \
58 pod_name + version_name + installer_name + \
59 duration_name + ".json"
61 print "Impossible to format json file name"
66 # retrieve the list of pods
67 url = db_url + "/pods"
69 headers = {'Content-Type': 'application/json'}
72 db_data = requests.get(url, headers=headers)
73 # Get result as a json object
74 pods_data = json.loads(db_data.text)
76 pods = pods_data['pods']
79 # cast int becase otherwise API retrieve 1.0
80 # TODO check format with API
81 pods_table.append(int(pod['_id']))
83 pods_table.append(0) # 0 means all the pods here
86 print "Error retrieving the list of PODs"
90 def get_versions(db_url):
91 # retrieve the list of versions
92 # TODO not supported in API yet
93 url = db_url + "/versions"
95 headers = {'Content-Type': 'application/json'}
98 db_data = requests.get(url, headers=headers)
99 # Get result as a json object
100 versions_data = json.loads(db_data.text)
102 versions = versions_data['versions']
105 for version in versions:
106 versions_table.append(version['version'])
108 versions_table.append('all')
110 return versions_table
112 print "Error retrieving the list of OPNFV versions"
116 def get_installers(db_url):
117 # retrieve the list of installers
118 # TODO not supported in API yet
119 url = db_url + "/installers"
121 headers = {'Content-Type': 'application/json'}
124 db_data = requests.get(url, headers=headers)
125 # Get result as a json object
126 installers_data = json.loads(db_data.text)
128 installers = installers_data['installers']
130 installers_table = []
131 for installer in installers:
132 installers_table.append(installer['installer'])
134 installers_table.append('all')
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_id":pod_id, "testcase":testcase}
184 # filter_date = days # data from now - days
186 # test_project = test_criteria.project
187 testcase = test_criteria.testcase
188 # duration_frame = test_criteria.duration
189 # version = test_criteria.version
190 # installer_type = test_criteria.installer
191 pod_id = test_criteria.pod_id
195 pod_criteria = "&pod=" + str(pod_id)
197 # TODO complete params (installer type, testcase, version )
198 # need API to be up to date
199 # we assume that criteria could be used at the API level
200 # no need to processing on date for instance
201 params = {"pod_id": pod_id}
204 headers = {'Content-Type': 'application/json'}
206 url = db_url + "/results?case=" + testcase + pod_criteria
208 # Send Request to Test DB
209 myData = requests.get(url, data=json.dumps(params), headers=headers)
210 # Get result as a json object
211 myNewData = json.loads(myData.text)
214 myDataResults = myNewData['test_results']
219 def generateJson(test_name, test_case, db_url):
221 # test_version = 'Arno master'
222 # test_installer = 'fuel'
223 # test_retention = 30
225 pods = get_pods(db_url)
226 versions = ['ArnoR1', 'ArnoSR1', 'all'] # not available in the API yet
227 installers = ['fuel', 'foreman', 'all'] # not available in the API yet
228 test_durations = [90, 365, 'all'] # not available through the API yet
233 for version in versions:
235 for installer in installers:
236 # all the retention time
237 for test_duration in test_durations:
239 criteria = TestCriteria()
240 criteria.setCriteria(test_name, test_case, pod,
241 test_duration, version, installer)
242 format_data_for_dashboard(criteria)
245 def format_data_for_dashboard(criteria):
247 # Depending on the use case, json for dashboarding is customized
248 # depending on the graph you want to show
250 if (criteria.testcase == "vPing"):
251 format_vPing_for_dashboard(criteria)