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