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