3 # This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 from urllib2 import Request, urlopen, URLError
14 def getApiResults(case, installer, scenario, version):
15 results = json.dumps([])
16 # to remove proxy (to be removed at the end for local test only)
17 # proxy_handler = urllib2.ProxyHandler({})
18 # opener = urllib2.build_opener(proxy_handler)
19 # urllib2.install_opener(opener)
20 # url = "http://127.0.0.1:8000/results?case=" + case + \
21 # "&period=30&installer=" + installer
22 url = (reportingConf.URL_BASE + "?case=" + case +
23 "&period=" + str(reportingConf.PERIOD) + "&installer=" + installer +
24 "&scenario=" + scenario + "&version=" + version +
25 "&last=" + str(reportingConf.NB_TESTS))
26 request = Request(url)
29 response = urlopen(request)
31 results = json.loads(k)
33 print 'No kittez. Got an error code:', e
38 def getScenarios(case, installer, version):
42 url = (reportingConf.URL_BASE + "?case=" + case +
43 "&period=" + str(reportingConf.PERIOD) + "&installer=" + installer +
44 "&version=" + version)
45 request = Request(url)
48 response = urlopen(request)
50 results = json.loads(k)
51 test_results = results['results']
53 print 'Got an error code:', e
55 if test_results is not None:
56 test_results.reverse()
60 for r in test_results:
61 # Retrieve all the scenarios per installer
62 if not r['scenario'] in scenario_results.keys():
63 scenario_results[r['scenario']] = []
64 scenario_results[r['scenario']].append(r)
66 return scenario_results
69 def getScenarioStats(scenario_results):
71 for k, v in scenario_results.iteritems():
72 scenario_stats[k] = len(v)
77 def getNbtestOk(results):
80 for k, v in r.iteritems():
85 print "Cannot retrieve test status"
89 def getResult(testCase, installer, scenario, version):
91 # retrieve raw results
92 results = getApiResults(testCase, installer, scenario, version)
93 # let's concentrate on test results only
94 test_results = results['results']
96 # if results found, analyze them
97 if test_results is not None:
98 test_results.reverse()
100 scenario_results = []
102 # print " ---------------- "
104 # print " ---------------- "
105 # print "nb of results:" + str(len(test_results))
107 for r in test_results:
108 # print r["start_date"]
109 # print r["criteria"]
110 scenario_results.append({r["start_date"]: r["criteria"]})
112 scenario_results.sort()
113 # 4 levels for the results
114 # 3: 4+ consecutive runs passing the success criteria
115 # 2: <4 successful consecutive runs but passing the criteria
116 # 1: close to pass the success criteria
117 # 0: 0% success, not passing
118 test_result_indicator = 0
119 nbTestOk = getNbtestOk(scenario_results)
120 # print "Nb test OK (last 10 days):"+ str(nbTestOk)
121 # check that we have at least 4 runs
123 test_result_indicator = 0
125 test_result_indicator = 1
127 # Test the last 4 run
128 if (len(scenario_results) > 3):
129 last4runResults = scenario_results[-4:]
130 nbTestOkLast4 = getNbtestOk(last4runResults)
131 # print "Nb test OK (last 4 run):"+ str(nbTestOkLast4)
132 if nbTestOkLast4 > 3:
133 test_result_indicator = 3
135 test_result_indicator = 2
137 test_result_indicator = 2
138 return test_result_indicator