Add new cinder scenarios for rally sanity/full
[functest.git] / functest / ci / tier_handler.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2016 Ericsson AB and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10
11 import re
12 import textwrap
13
14 import prettytable
15
16
17 LINE_LENGTH = 72
18
19
20 def split_text(text, max_len):
21     words = text.split()
22     lines = []
23     line = ""
24     for word in words:
25         if len(line) + len(word) < max_len - 1:
26             line += word + " "
27         else:
28             lines.append(line)
29             line = word + " "
30     if line != "":
31         lines.append(line)
32     return lines
33
34
35 class Tier(object):
36
37     def __init__(self, name, order, ci_loop, description=""):
38         self.tests_array = []
39         self.skipped_tests_array = []
40         self.name = name
41         self.order = order
42         self.ci_loop = ci_loop
43         self.description = description
44
45     def add_test(self, testcase):
46         self.tests_array.append(testcase)
47
48     def skip_test(self, testcase):
49         self.skipped_tests_array.append(testcase)
50
51     def get_tests(self):
52         array_tests = []
53         for test in self.tests_array:
54             array_tests.append(test)
55         return array_tests
56
57     def get_skipped_test(self):
58         return self.skipped_tests_array
59
60     def get_test_names(self):
61         array_tests = []
62         for test in self.tests_array:
63             array_tests.append(test.get_name())
64         return array_tests
65
66     def get_test(self, test_name):
67         if self.is_test(test_name):
68             for test in self.tests_array:
69                 if test.get_name() == test_name:
70                     return test
71         return None
72
73     def is_test(self, test_name):
74         for test in self.tests_array:
75             if test.get_name() == test_name:
76                 return True
77         return False
78
79     def get_name(self):
80         return self.name
81
82     def get_order(self):
83         return self.order
84
85     def get_ci_loop(self):
86         return self.ci_loop
87
88     def __str__(self):
89         msg = prettytable.PrettyTable(
90             header_style='upper', padding_width=5,
91             field_names=['tiers', 'order', 'CI Loop', 'description',
92                          'testcases'])
93         msg.add_row(
94             [self.name, self.order, self.ci_loop,
95              textwrap.fill(self.description, width=40),
96              textwrap.fill(' '.join([str(x.get_name(
97                  )) for x in self.get_tests()]), width=40)])
98         return msg.get_string()
99
100
101 class TestCase(object):
102
103     def __init__(self, name,
104                  enabled,
105                  dependency,
106                  criteria,
107                  blocking,
108                  description="",
109                  project=""):
110         self.name = name
111         self.enabled = enabled
112         self.dependency = dependency
113         self.criteria = criteria
114         self.blocking = blocking
115         self.description = description
116         self.project = project
117
118     @staticmethod
119     def is_none(item):
120         return item is None or item is ""
121
122     def is_compatible(self, ci_installer, ci_scenario):
123         try:
124             if (self.is_none(ci_installer) and not
125                     self.is_none(self.dependency.get_installer())):
126                 return False
127             if not self.is_none(ci_installer):
128                 if re.search(self.dependency.get_installer(),
129                              ci_installer) is None:
130                     return False
131             if not self.is_none(ci_scenario):
132                 if re.search(self.dependency.get_scenario(),
133                              ci_scenario) is None:
134                     return False
135             return True
136         except TypeError:
137             return False
138
139     def get_name(self):
140         return self.name
141
142     def is_enabled(self):
143         return self.enabled
144
145     def get_criteria(self):
146         return self.criteria
147
148     def is_blocking(self):
149         return self.blocking
150
151     def get_project(self):
152         return self.project
153
154     def __str__(self):
155         msg = prettytable.PrettyTable(
156             header_style='upper', padding_width=5,
157             field_names=['test case', 'description', 'criteria', 'dependency'])
158         msg.add_row([self.name, textwrap.fill(self.description, width=40),
159                      self.criteria, self.dependency])
160         return msg.get_string()
161
162
163 class Dependency(object):
164
165     def __init__(self, installer, scenario):
166         self.installer = installer
167         self.scenario = scenario
168
169     def get_installer(self):
170         return self.installer
171
172     def get_scenario(self):
173         return self.scenario
174
175     def __str__(self):
176         delimitator = "\n" if self.get_installer(
177             ) and self.get_scenario() else ""
178         return "{}{}{}".format(self.get_installer(), delimitator,
179                                self.get_scenario())