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