1 from urllib2 import Request, urlopen, URLError
9 class TestCase(object):
10 def __init__(self, name, project, criteria=-1):
12 self.project = project
13 self.criteria = criteria
21 def getCriteria(self):
24 def setCriteria(self, criteria):
25 self.criteria = criteria
28 def getApiResults(case, installer):
31 # to remove proxy (to be removed at the end for local test only)
32 # proxy_handler = urllib2.ProxyHandler({})
33 # opener = urllib2.build_opener(proxy_handler)
34 # urllib2.install_opener(opener)
35 url = "http://testresults.opnfv.org/testapi/results?case=" + case + "&period=30&installer=" + installer
36 #url = "http://127.0.0.1:8000/results?case=" + case + "&period=30&installer=" + installer
37 request = Request(url)
40 response = urlopen(request)
42 results = json.loads(k)
44 print 'No kittez. Got an error code:', e
49 def getScenarios(case, installer):
51 results = getApiResults(case, installer)
52 test_results = results['test_results']
54 if test_results is not None:
55 test_results.reverse()
59 for r in test_results:
60 # Retrieve all the scenarios per installer
61 if not r['version'] in scenario_results.keys():
62 scenario_results[r['version']] = []
63 scenario_results[r['version']].append(r)
65 return scenario_results
68 def getScenarioStats(scenario_results):
70 for k, v in scenario_results.iteritems():
71 scenario_stats[k] = len(v)
76 def getResult(testCase, installer):
78 # retrieve raw results
79 results = getApiResults(testCase, installer)
80 # let's concentrate on test results only
81 test_results = results['test_results']
83 # if results found, analyze them
84 if test_results is not None:
85 test_results.reverse()
89 for r in test_results:
90 if not r['version'] in scenario_results.keys():
91 scenario_results[r['version']] = []
92 scenario_results[r['version']].append(r)
94 for s, s_result in scenario_results.items():
95 scenario_results[s] = s_result[0:5]
96 # For each scenario, we build a result object to deal with
97 # results, criteria and error handling
98 for result in scenario_results[s]:
99 result["creation_date"] = result["creation_date"].split(".")[0]
101 # Cannot be fully generic
102 # need to look for specific criteria case by case
103 # TODO add a criteria passed/failed in DB??
104 # TODO result["Success_criteria"] = result["success_criteria"]
105 # meanwhile just random....
106 # and consider the last random arbitrarily
107 # 4 levels for the results
108 # 3: 4+ consecutive runs passing the success criteria
109 # 2: <4 successful consecutive runs but passing the criteria
110 # 1: close to pass the success criteria
111 # 0: 0% success, not passing
114 return int(random.random()*4)+1
116 # ******************************************************************************
117 # ******************************************************************************
118 # ******************************************************************************
119 # ******************************************************************************
120 # ******************************************************************************
122 # as the criteria are all difference, we shall use a common way to indicate
124 # 100 = 100% = all the test must be OK
125 # 90 = 90% = all the test must be above 90% of success rate
126 # TODO harmonize success criteria
127 # some criteria could be the duration, the success rate, the packet loss,...
128 # to be done case by case
129 # TODo create TestCriteria Object
132 installers = ["apex", "compass", "fuel", "joid"]
133 # init just tempest to get the scenario as all the scenarios run Temepst
134 tempest = TestCase("Tempest", "functest", -1)
136 for installer in installers:
138 scenario_results = getScenarios(tempest, installer)
139 scenario_stats = getScenarioStats(scenario_results)
143 for s, s_result in scenario_results.items():
145 vPing = TestCase("vPing", "functest")
146 vPing_userdata = TestCase("vPing_userdata", "functest")
147 tempest = TestCase("Tempest", "functest")
148 rally = TestCase("Rally", "functest")
149 odl = TestCase("ODL", "functest")
150 onos = TestCase("ONOS", "functest")
151 ovno = TestCase("OVNO", "functest")
152 vIMS = TestCase("vIMS", "functest")
153 doctor = TestCase("doctor-notification", "doctor")
154 promise = TestCase("promise", "promise")
155 odl_vpn = TestCase("ODL VPN Service tests", "sdnvpn")
156 bgpvpn_api = TestCase("OpenStack Neutron BGPVPN API extension tests",
158 testCases = [vPing, vPing_userdata, tempest, rally, odl, onos, vIMS,
161 for testCase in testCases:
162 result = getResult(testCase, installer)
163 testCase.setCriteria(result)
164 # print "case %s (%s) = %s " % (testCase.getName(), s, result)
167 templateLoader = jinja2.FileSystemLoader(os.path.dirname(os.path.abspath(__file__)))
168 templateEnv = jinja2.Environment(loader=templateLoader)
170 TEMPLATE_FILE = "index-status-tmpl.html"
171 template = templateEnv.get_template(TEMPLATE_FILE)
173 outputText = template.render(scenario_stats=scenario_stats,
177 with open("index-status-" + installer + ".html", "wb") as fh: