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