Adapt reporting after Functest refactoring
[releng.git] / utils / test / reporting / functest / testCase.py
1 #!/usr/bin/python
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 import re
10
11
12 class TestCase(object):
13
14     def __init__(self, name, project, constraints,
15                  criteria=-1, isRunnable=True, tier=-1):
16         self.name = name
17         self.project = project
18         self.constraints = constraints
19         self.criteria = criteria
20         self.isRunnable = isRunnable
21         self.tier = tier
22
23     def getName(self):
24         return self.name
25
26     def getProject(self):
27         return self.project
28
29     def getConstraints(self):
30         return self.constraints
31
32     def getCriteria(self):
33         return self.criteria
34
35     def getTier(self):
36         return self.tier
37
38     def setCriteria(self, criteria):
39         self.criteria = criteria
40
41     def setIsRunnable(self, isRunnable):
42         self.isRunnable = isRunnable
43
44     def checkRunnable(self, installer, scenario, config):
45         # Re-use Functest declaration
46         # Retrieve Functest configuration file functest_config.yaml
47         is_runnable = True
48         config_test = config
49         # print " *********************** "
50         # print TEST_ENV
51         # print " ---------------------- "
52         # print "case = " + self.name
53         # print "installer = " + installer
54         # print "scenario = " + scenario
55         # print "project = " + self.project
56
57         # Retrieve test constraints
58         # Retrieve test execution param
59         test_execution_context = {"installer": installer,
60                                   "scenario": scenario}
61
62         # By default we assume that all the tests are always runnable...
63         # if test_env not empty => dependencies to be checked
64         if config_test is not None and len(config_test) > 0:
65             # possible criteria = ["installer", "scenario"]
66             # consider test criteria from config file
67             # compare towards CI env through CI en variable
68             for criteria in config_test:
69                 if re.search(config_test[criteria],
70                              test_execution_context[criteria]) is None:
71                     # print "Test "+ test + " cannot be run on the environment"
72                     is_runnable = False
73         # print is_runnable
74         self.isRunnable = is_runnable
75
76     def toString(self):
77         testcase = ("Name=" + self.name + ";Criteria=" + str(self.criteria)
78                     + ";Project=" + self.project + ";Constraints="
79                     + str(self.constraints) + ";IsRunnable"
80                     + str(self.isRunnable))
81         return testcase
82
83     def getDbName(self):
84         # Correspondance name of the test case / name in the DB
85         # ideally we should modify the DB to avoid such interface....
86         # '<name in the config>':'<name in the DB>'
87         # I know it is uggly...
88         test_match_matrix = {'healthcheck': 'healthcheck',
89                              'vping_ssh': 'vPing',
90                              'vping_userdata': 'vPing_userdata',
91                              'odl': 'ODL',
92                              'onos': 'ONOS',
93                              'ovno': 'ovno',
94                              'tempest_smoke_serial': 'Tempest',
95                              'tempest_full_parallel': 'tempest_full_parallel',
96                              'rally_sanity': 'Rally',
97                              'bgpvpn': 'bgpvpn',
98                              'rally_full': 'rally_full',
99                              'vims': 'vIMS',
100                              'doctor': 'doctor-notification',
101                              'promise': 'promise'
102                              }
103         try:
104             return test_match_matrix[self.name]
105         except:
106             return "unknown"