9834f07535c4022085e2ffc686e590058db00433
[releng.git] / utils / test / reporting / 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                                'refstack_defcore': 'Refstack',
32                                'rally_sanity': 'Rally (smoke)',
33                                'bgpvpn': 'bgpvpn',
34                                'rally_full': 'Rally (full)',
35                                'vims': 'vIMS',
36                                'doctor-notification': 'Doctor',
37                                'promise': 'Promise',
38                                'moon': 'Moon',
39                                'copper': 'Copper',
40                                'security_scan': 'Security',
41                                'multisite': 'Multisite',
42                                'domino-multinode': 'Domino',
43                                'functest-odl-sfc': 'SFC',
44                                'onos_sfc': 'SFC',
45                                'parser-basics': 'Parser',
46                                'connection_check': 'Health (connection)',
47                                'api_check': 'Health (api)',
48                                'snaps_smoke': 'SNAPS',
49                                'snaps_health_check': 'Health (dhcp)',
50                                'gluon_vping': 'Netready',
51                                'fds': 'FDS',
52                                'cloudify_ims': 'vIMS (Cloudify)',
53                                'orchestra_ims': 'OpenIMS (OpenBaton)',
54                                'opera_ims': 'vIMS (Open-O)',
55                                'vyos_vrouter': 'vyos',
56                                'barometercollectd': 'Barometer',
57                                'odl_netvirt': 'Netvirt',
58                                'security_scan': 'Security'}
59         try:
60             self.displayName = display_name_matrix[self.name]
61         except:
62             self.displayName = "unknown"
63
64     def getName(self):
65         return self.name
66
67     def getProject(self):
68         return self.project
69
70     def getConstraints(self):
71         return self.constraints
72
73     def getCriteria(self):
74         return self.criteria
75
76     def getTier(self):
77         return self.tier
78
79     def setCriteria(self, criteria):
80         self.criteria = criteria
81
82     def setIsRunnable(self, isRunnable):
83         self.isRunnable = isRunnable
84
85     def checkRunnable(self, installer, scenario, config):
86         # Re-use Functest declaration
87         # Retrieve Functest configuration file functest_config.yaml
88         is_runnable = True
89         config_test = config
90         # print " *********************** "
91         # print TEST_ENV
92         # print " ---------------------- "
93         # print "case = " + self.name
94         # print "installer = " + installer
95         # print "scenario = " + scenario
96         # print "project = " + self.project
97
98         # Retrieve test constraints
99         # Retrieve test execution param
100         test_execution_context = {"installer": installer,
101                                   "scenario": scenario}
102
103         # By default we assume that all the tests are always runnable...
104         # if test_env not empty => dependencies to be checked
105         if config_test is not None and len(config_test) > 0:
106             # possible criteria = ["installer", "scenario"]
107             # consider test criteria from config file
108             # compare towards CI env through CI en variable
109             for criteria in config_test:
110                 if re.search(config_test[criteria],
111                              test_execution_context[criteria]) is None:
112                     # print "Test "+ test + " cannot be run on the environment"
113                     is_runnable = False
114         # print is_runnable
115         self.isRunnable = is_runnable
116
117     def toString(self):
118         testcase = ("Name=" + self.name + ";Criteria=" +
119                     str(self.criteria) + ";Project=" + self.project +
120                     ";Constraints=" + str(self.constraints) +
121                     ";IsRunnable" + str(self.isRunnable))
122         return testcase
123
124     def getDisplayName(self):
125         return self.displayName