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