Merge "prototypes: fix yamllint issues"
[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         display_name_matrix = {'healthcheck': 'healthcheck',
23                                'vping_ssh': 'vPing (ssh)',
24                                'vping_userdata': 'vPing (userdata)',
25                                'odl': 'ODL',
26                                'onos': 'ONOS',
27                                'ocl': 'OCL',
28                                'tempest_smoke_serial': 'Tempest (smoke)',
29                                'tempest_full_parallel': 'Tempest (full)',
30                                'tempest_defcore': 'Tempest (Defcore)',
31                                'refstack_defcore': 'Refstack',
32                                'rally_sanity': 'Rally (smoke)',
33                                'bgpvpn': 'bgpvpn',
34                                'rally_full': 'Rally (full)',
35                                'vims': 'vIMS',
36                                'doctor': 'Doctor',
37                                'promise': 'Promise',
38                                'moon': 'Moon',
39                                'copper': 'Copper',
40                                'security_scan': 'Security',
41                                'multisite': 'Multisite',
42                                'domino': 'Domino',
43                                'odl-sfc': 'SFC',
44                                'onos_sfc': 'SFC',
45                                'parser': 'Parser',
46                                'connection_check': 'Health (connection)',
47                                'api_check': 'Health (api)',
48                                'snaps_smoke': 'SNAPS',
49                                'snaps_health_check': 'Health (dhcp)',
50                                'netready': 'Netready',
51                                'fds': 'FDS',
52                                'cloudify_ims': 'vIMS (Cloudify)',
53                                'orchestra_ims': 'OpenIMS (OpenBaton)',
54                                'opera_ims': 'vIMS (Open-O)',
55                                'vyos_vrouter': 'vyos',
56                                'barometer': 'Barometer'}
57         try:
58             self.displayName = display_name_matrix[self.name]
59         except:
60             self.displayName = "unknown"
61
62     def getName(self):
63         return self.name
64
65     def getProject(self):
66         return self.project
67
68     def getConstraints(self):
69         return self.constraints
70
71     def getCriteria(self):
72         return self.criteria
73
74     def getTier(self):
75         return self.tier
76
77     def setCriteria(self, criteria):
78         self.criteria = criteria
79
80     def setIsRunnable(self, isRunnable):
81         self.isRunnable = isRunnable
82
83     def checkRunnable(self, installer, scenario, config):
84         # Re-use Functest declaration
85         # Retrieve Functest configuration file functest_config.yaml
86         is_runnable = True
87         config_test = config
88         # print " *********************** "
89         # print TEST_ENV
90         # print " ---------------------- "
91         # print "case = " + self.name
92         # print "installer = " + installer
93         # print "scenario = " + scenario
94         # print "project = " + self.project
95
96         # Retrieve test constraints
97         # Retrieve test execution param
98         test_execution_context = {"installer": installer,
99                                   "scenario": scenario}
100
101         # By default we assume that all the tests are always runnable...
102         # if test_env not empty => dependencies to be checked
103         if config_test is not None and len(config_test) > 0:
104             # possible criteria = ["installer", "scenario"]
105             # consider test criteria from config file
106             # compare towards CI env through CI en variable
107             for criteria in config_test:
108                 if re.search(config_test[criteria],
109                              test_execution_context[criteria]) is None:
110                     # print "Test "+ test + " cannot be run on the environment"
111                     is_runnable = False
112         # print is_runnable
113         self.isRunnable = is_runnable
114
115     def toString(self):
116         testcase = ("Name=" + self.name + ";Criteria=" +
117                     str(self.criteria) + ";Project=" + self.project +
118                     ";Constraints=" + str(self.constraints) +
119                     ";IsRunnable" + str(self.isRunnable))
120         return testcase
121
122     def getDbName(self):
123         # Correspondance name of the test case / name in the DB
124         # ideally we should modify the DB to avoid such interface....
125         # '<name in the config>':'<name in the DB>'
126         # I know it is uggly...
127         test_match_matrix = {'healthcheck': 'healthcheck',
128                              'vping_ssh': 'vping_ssh',
129                              'vping_userdata': 'vping_userdata',
130                              'odl': 'odl',
131                              'onos': 'onos',
132                              'ocl': 'ocl',
133                              'tempest_smoke_serial': 'tempest_smoke_serial',
134                              'tempest_full_parallel': 'tempest_full_parallel',
135                              'tempest_defcore': 'tempest_defcore',
136                              'refstack_defcore': 'refstack_defcore',
137                              'rally_sanity': 'rally_sanity',
138                              'bgpvpn': 'bgpvpn',
139                              'rally_full': 'rally_full',
140                              'vims': 'vims',
141                              'doctor': 'doctor-notification',
142                              'promise': 'promise',
143                              'moon': 'moon_authentication',
144                              'copper': 'copper-notification',
145                              'security_scan': 'security',
146                              'multisite': 'multisite',
147                              'domino': 'domino-multinode',
148                              'odl-sfc': 'functest-odl-sfc',
149                              'onos_sfc': 'onos_sfc',
150                              'parser': 'parser-basics',
151                              'connection_check': 'connection_check',
152                              'api_check': 'api_check',
153                              'snaps_smoke': 'snaps_smoke',
154                              'snaps_health_check': 'snaps_health_check',
155                              'netready': 'gluon_vping',
156                              'fds': 'fds',
157                              'cloudify_ims': 'cloudify_ims',
158                              'orchestra_ims': 'orchestra_ims',
159                              'opera_ims': 'opera_ims',
160                              'vyos_vrouter': 'vyos_vrouter',
161                              'barometer': 'barometercollectd'}
162         try:
163             return test_match_matrix[self.name]
164         except:
165             return "unknown"
166
167     def getDisplayName(self):
168         return self.displayName