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