e3389a97a71fbb2855ce3e591bdd40a5dfb5bfdf
[snaps.git] / snaps / test_suite_builder.py
1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 #                    and others.  All rights reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import logging
17 import unittest
18
19 from snaps.domain.test.flavor_tests import FlavorDomainObjectTests
20 from snaps.domain.test.image_tests import ImageDomainObjectTests
21 from snaps.domain.test.keypair_tests import KeypairDomainObjectTests
22 from snaps.domain.test.stack_tests import StackDomainObjectTests
23 from snaps.domain.test.vm_inst_tests import (VmInstDomainObjectTests,
24                                              FloatingIpDomainObjectTests)
25 from snaps.openstack.tests.conf.os_credentials_tests import (
26     ProxySettingsUnitTests, OSCredsUnitTests)
27 from snaps.openstack.tests.create_flavor_tests import (
28     CreateFlavorTests, FlavorSettingsUnitTests)
29 from snaps.openstack.tests.create_image_tests import (
30     CreateImageSuccessTests, CreateImageNegativeTests, ImageSettingsUnitTests,
31     CreateMultiPartImageTests)
32 from snaps.openstack.tests.create_instance_tests import (
33     CreateInstanceSingleNetworkTests, CreateInstancePubPrivNetTests,
34     CreateInstanceOnComputeHost, CreateInstanceSimpleTests,
35     FloatingIpSettingsUnitTests, InstanceSecurityGroupTests,
36     VmInstanceSettingsUnitTests, CreateInstancePortManipulationTests,
37     SimpleHealthCheck, CreateInstanceFromThreePartImage,
38     CreateInstanceMockOfflineTests)
39 from snaps.openstack.tests.create_keypairs_tests import (
40     CreateKeypairsTests, KeypairSettingsUnitTests)
41 from snaps.openstack.tests.create_network_tests import (
42     CreateNetworkSuccessTests, NetworkSettingsUnitTests, PortSettingsUnitTests,
43     SubnetSettingsUnitTests, CreateNetworkTypeTests)
44 from snaps.openstack.tests.create_project_tests import (
45     CreateProjectSuccessTests, ProjectSettingsUnitTests,
46     CreateProjectUserTests)
47 from snaps.openstack.tests.create_router_tests import (
48     CreateRouterSuccessTests, CreateRouterNegativeTests)
49 from snaps.openstack.tests.create_security_group_tests import (
50     CreateSecurityGroupTests, SecurityGroupRuleSettingsUnitTests,
51     SecurityGroupSettingsUnitTests)
52 from snaps.openstack.tests.create_stack_tests import (
53     StackSettingsUnitTests, CreateStackSuccessTests,  CreateStackNegativeTests)
54 from snaps.openstack.tests.create_user_tests import (
55     UserSettingsUnitTests, CreateUserSuccessTests)
56 from snaps.openstack.tests.os_source_file_test import (
57     OSComponentTestCase, OSIntegrationTestCase)
58 from snaps.openstack.utils.tests.glance_utils_tests import (
59     GlanceSmokeTests, GlanceUtilsTests)
60 from snaps.openstack.utils.tests.heat_utils_tests import (
61     HeatUtilsCreateStackTests, HeatSmokeTests)
62 from snaps.openstack.utils.tests.keystone_utils_tests import (
63     KeystoneSmokeTests, KeystoneUtilsTests)
64 from snaps.openstack.utils.tests.neutron_utils_tests import (
65     NeutronSmokeTests, NeutronUtilsNetworkTests, NeutronUtilsSubnetTests,
66     NeutronUtilsRouterTests, NeutronUtilsSecurityGroupTests,
67     NeutronUtilsFloatingIpTests)
68 from snaps.openstack.utils.tests.nova_utils_tests import (
69     NovaSmokeTests, NovaUtilsKeypairTests, NovaUtilsFlavorTests,
70     NovaUtilsInstanceTests)
71 from snaps.provisioning.tests.ansible_utils_tests import (
72     AnsibleProvisioningTests)
73 from snaps.tests.file_utils_tests import FileUtilsTests
74
75 __author__ = 'spisarski'
76
77
78 def add_unit_tests(suite):
79     """
80     Adds tests that do not require external resources
81     :param suite: the unittest.TestSuite object to which to add the tests
82     :return: None as the tests will be adding to the 'suite' parameter object
83     """
84     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(FileUtilsTests))
85     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
86         SecurityGroupRuleSettingsUnitTests))
87     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
88         ProxySettingsUnitTests))
89     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
90         OSCredsUnitTests))
91     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
92         SecurityGroupSettingsUnitTests))
93     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
94         ImageSettingsUnitTests))
95     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
96         ImageDomainObjectTests))
97     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
98         FlavorSettingsUnitTests))
99     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
100         FlavorDomainObjectTests))
101     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
102         KeypairSettingsUnitTests))
103     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
104         KeypairDomainObjectTests))
105     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
106         UserSettingsUnitTests))
107     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
108         ProjectSettingsUnitTests))
109     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
110         NetworkSettingsUnitTests))
111     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
112         SubnetSettingsUnitTests))
113     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
114         PortSettingsUnitTests))
115     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
116         FloatingIpSettingsUnitTests))
117     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
118         VmInstanceSettingsUnitTests))
119     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
120         StackDomainObjectTests))
121     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
122         StackSettingsUnitTests))
123     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
124         VmInstDomainObjectTests))
125     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
126         FloatingIpDomainObjectTests))
127
128
129 def add_openstack_client_tests(suite, os_creds, ext_net_name,
130                                use_keystone=True, log_level=logging.INFO):
131     """
132     Adds tests written to exercise OpenStack client retrieval
133     :param suite: the unittest.TestSuite object to which to add the tests
134     :param os_creds: and instance of OSCreds that holds the credentials
135                      required by OpenStack
136     :param ext_net_name: the name of an external network on the cloud under
137                          test
138     :param use_keystone: when True, tests requiring direct access to Keystone
139                          are added as these need to be running on a host that
140                          has access to the cloud's private network
141     :param log_level: the logging level
142     :return: None as the tests will be adding to the 'suite' parameter object
143     """
144     # Basic connection tests
145     suite.addTest(
146         OSComponentTestCase.parameterize(
147             GlanceSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
148             log_level=log_level))
149
150     if use_keystone:
151         suite.addTest(
152             OSComponentTestCase.parameterize(
153                 KeystoneSmokeTests, os_creds=os_creds,
154                 ext_net_name=ext_net_name, log_level=log_level))
155
156     suite.addTest(
157         OSComponentTestCase.parameterize(
158             NeutronSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
159             log_level=log_level))
160     suite.addTest(
161         OSComponentTestCase.parameterize(
162             NovaSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
163             log_level=log_level))
164     suite.addTest(
165         OSComponentTestCase.parameterize(
166             HeatSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
167             log_level=log_level))
168
169
170 def add_openstack_api_tests(suite, os_creds, ext_net_name, use_keystone=True,
171                             image_metadata=None, log_level=logging.INFO):
172     """
173     Adds tests written to exercise all existing OpenStack APIs
174     :param suite: the unittest.TestSuite object to which to add the tests
175     :param os_creds: Instance of OSCreds that holds the credentials
176                      required by OpenStack
177     :param ext_net_name: the name of an external network on the cloud under
178                          test
179     :param use_keystone: when True, tests requiring direct access to Keystone
180                          are added as these need to be running on a host that
181                          has access to the cloud's private network
182     :param image_metadata: dict() object containing metadata for creating an
183                            image with custom config
184                            (see YAML files in examples/image-metadata)
185     :param log_level: the logging level
186     :return: None as the tests will be adding to the 'suite' parameter object
187     """
188     # Tests the OpenStack API calls
189     if use_keystone:
190         suite.addTest(OSComponentTestCase.parameterize(
191             KeystoneUtilsTests, os_creds=os_creds, ext_net_name=ext_net_name,
192             log_level=log_level))
193         suite.addTest(OSComponentTestCase.parameterize(
194             CreateUserSuccessTests, os_creds=os_creds,
195             ext_net_name=ext_net_name, log_level=log_level))
196         suite.addTest(OSComponentTestCase.parameterize(
197             CreateProjectSuccessTests, os_creds=os_creds,
198             ext_net_name=ext_net_name, log_level=log_level))
199         suite.addTest(OSComponentTestCase.parameterize(
200             CreateProjectUserTests, os_creds=os_creds,
201             ext_net_name=ext_net_name, log_level=log_level))
202
203     suite.addTest(OSComponentTestCase.parameterize(
204         GlanceUtilsTests, os_creds=os_creds, ext_net_name=ext_net_name,
205         image_metadata=image_metadata,
206         log_level=log_level))
207     suite.addTest(OSComponentTestCase.parameterize(
208         NeutronUtilsNetworkTests, os_creds=os_creds, ext_net_name=ext_net_name,
209         log_level=log_level))
210     suite.addTest(OSComponentTestCase.parameterize(
211         NeutronUtilsSubnetTests, os_creds=os_creds, ext_net_name=ext_net_name,
212         log_level=log_level))
213     suite.addTest(OSComponentTestCase.parameterize(
214         NeutronUtilsRouterTests, os_creds=os_creds, ext_net_name=ext_net_name,
215         log_level=log_level))
216     suite.addTest(OSComponentTestCase.parameterize(
217         NeutronUtilsSecurityGroupTests, os_creds=os_creds,
218         ext_net_name=ext_net_name, log_level=log_level))
219     suite.addTest(OSComponentTestCase.parameterize(
220         NeutronUtilsFloatingIpTests, os_creds=os_creds,
221         ext_net_name=ext_net_name, log_level=log_level))
222     suite.addTest(OSComponentTestCase.parameterize(
223         NovaUtilsKeypairTests, os_creds=os_creds, ext_net_name=ext_net_name,
224         log_level=log_level))
225     suite.addTest(OSComponentTestCase.parameterize(
226         NovaUtilsFlavorTests, os_creds=os_creds, ext_net_name=ext_net_name,
227         log_level=log_level))
228     suite.addTest(OSComponentTestCase.parameterize(
229         NovaUtilsInstanceTests, os_creds=os_creds, ext_net_name=ext_net_name,
230         log_level=log_level, image_metadata=image_metadata))
231     suite.addTest(OSComponentTestCase.parameterize(
232         CreateFlavorTests, os_creds=os_creds, ext_net_name=ext_net_name,
233         log_level=log_level))
234     suite.addTest(OSComponentTestCase.parameterize(
235         HeatUtilsCreateStackTests, os_creds=os_creds,
236         ext_net_name=ext_net_name, log_level=log_level,
237         image_metadata=image_metadata))
238
239
240 def add_openstack_integration_tests(suite, os_creds, ext_net_name,
241                                     use_keystone=True, flavor_metadata=None,
242                                     image_metadata=None, use_floating_ips=True,
243                                     log_level=logging.INFO):
244     """
245     Adds tests written to exercise all long-running OpenStack integration tests
246     meaning they will be creating VM instances and potentially performing some
247     SSH functions through floatingIPs
248     :param suite: the unittest.TestSuite object to which to add the tests
249     :param os_creds: and instance of OSCreds that holds the credentials
250                      required by OpenStack
251     :param ext_net_name: the name of an external network on the cloud under
252                          test
253     :param use_keystone: when True, tests requiring direct access to Keystone
254                          are added as these need to be running on a host that
255                          has access to the cloud's private network
256     :param image_metadata: dict() object containing metadata for creating an
257                            image with custom config
258                            (see YAML files in examples/image-metadata)
259     :param flavor_metadata: dict() object containing the metadata required by
260                             your flavor based on your configuration:
261                             (i.e. {'hw:mem_page_size': 'large'})
262     :param use_floating_ips: when true, all tests requiring Floating IPs will
263                              be added to the suite
264     :param log_level: the logging level
265     :return: None as the tests will be adding to the 'suite' parameter object
266     """
267     # Tests the OpenStack API calls via a creator. If use_keystone, objects
268     # will be created with a custom user and project
269
270     # Creator Object tests
271     suite.addTest(OSIntegrationTestCase.parameterize(
272         CreateSecurityGroupTests, os_creds=os_creds, ext_net_name=ext_net_name,
273         use_keystone=use_keystone,
274         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
275         log_level=log_level))
276     suite.addTest(OSIntegrationTestCase.parameterize(
277         CreateImageSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name,
278         use_keystone=use_keystone,
279         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
280         log_level=log_level))
281     suite.addTest(OSIntegrationTestCase.parameterize(
282         CreateImageNegativeTests, os_creds=os_creds, ext_net_name=ext_net_name,
283         use_keystone=use_keystone,
284         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
285         log_level=log_level))
286     suite.addTest(OSIntegrationTestCase.parameterize(
287         CreateMultiPartImageTests, os_creds=os_creds,
288         ext_net_name=ext_net_name, use_keystone=use_keystone,
289         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
290         log_level=log_level))
291     suite.addTest(OSIntegrationTestCase.parameterize(
292         CreateKeypairsTests, os_creds=os_creds, ext_net_name=ext_net_name,
293         use_keystone=use_keystone,
294         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
295         log_level=log_level))
296     suite.addTest(OSIntegrationTestCase.parameterize(
297         CreateNetworkSuccessTests, os_creds=os_creds,
298         ext_net_name=ext_net_name, use_keystone=use_keystone,
299         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
300         log_level=log_level))
301     suite.addTest(OSIntegrationTestCase.parameterize(
302         CreateRouterSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name,
303         use_keystone=use_keystone,
304         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
305         log_level=log_level))
306     suite.addTest(OSIntegrationTestCase.parameterize(
307         CreateRouterNegativeTests, os_creds=os_creds,
308         ext_net_name=ext_net_name, use_keystone=use_keystone,
309         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
310         log_level=log_level))
311
312     # VM Instances
313     suite.addTest(OSIntegrationTestCase.parameterize(
314         SimpleHealthCheck, os_creds=os_creds, ext_net_name=ext_net_name,
315         use_keystone=use_keystone,
316         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
317         log_level=log_level))
318     suite.addTest(OSIntegrationTestCase.parameterize(
319         CreateInstanceSimpleTests, os_creds=os_creds,
320         ext_net_name=ext_net_name, use_keystone=use_keystone,
321         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
322         log_level=log_level))
323     suite.addTest(OSIntegrationTestCase.parameterize(
324         CreateInstancePortManipulationTests, os_creds=os_creds,
325         ext_net_name=ext_net_name, use_keystone=use_keystone,
326         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
327         log_level=log_level))
328     suite.addTest(OSIntegrationTestCase.parameterize(
329         InstanceSecurityGroupTests, os_creds=os_creds,
330         ext_net_name=ext_net_name, use_keystone=use_keystone,
331         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
332         log_level=log_level))
333     suite.addTest(OSIntegrationTestCase.parameterize(
334         CreateInstanceOnComputeHost, os_creds=os_creds,
335         ext_net_name=ext_net_name, use_keystone=use_keystone,
336         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
337         log_level=log_level))
338     suite.addTest(OSIntegrationTestCase.parameterize(
339         CreateInstanceFromThreePartImage, os_creds=os_creds,
340         ext_net_name=ext_net_name, use_keystone=use_keystone,
341         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
342         log_level=log_level))
343     suite.addTest(OSIntegrationTestCase.parameterize(
344         CreateStackSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name,
345         use_keystone=use_keystone,
346         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
347         log_level=log_level))
348     suite.addTest(OSIntegrationTestCase.parameterize(
349         CreateStackNegativeTests, os_creds=os_creds, ext_net_name=ext_net_name,
350         use_keystone=use_keystone,
351         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
352         log_level=log_level))
353
354     if use_floating_ips:
355         suite.addTest(OSIntegrationTestCase.parameterize(
356             CreateInstanceSingleNetworkTests, os_creds=os_creds,
357             ext_net_name=ext_net_name, use_keystone=use_keystone,
358             flavor_metadata=flavor_metadata, image_metadata=image_metadata,
359             log_level=log_level))
360         suite.addTest(OSIntegrationTestCase.parameterize(
361             CreateInstancePubPrivNetTests, os_creds=os_creds,
362             ext_net_name=ext_net_name, use_keystone=use_keystone,
363             flavor_metadata=flavor_metadata, image_metadata=image_metadata,
364             log_level=log_level))
365         suite.addTest(OSIntegrationTestCase.parameterize(
366             AnsibleProvisioningTests, os_creds=os_creds,
367             ext_net_name=ext_net_name, use_keystone=use_keystone,
368             flavor_metadata=flavor_metadata, image_metadata=image_metadata,
369             log_level=log_level))
370
371
372 def add_openstack_staging_tests(suite, os_creds, ext_net_name,
373                                 log_level=logging.INFO):
374     """
375     Adds tests that are still in development have not been designed to run
376     successfully against all OpenStack pods
377     :param suite: the unittest.TestSuite object to which to add the tests
378     :param os_creds: Instance of OSCreds that holds the credentials
379                     required by OpenStack
380     :param ext_net_name: the name of an external network on the cloud under
381                          test
382     :param log_level: the logging level
383     :return: None as the tests will be adding to the 'suite' parameter object
384     """
385     suite.addTest(OSComponentTestCase.parameterize(
386         CreateNetworkTypeTests, os_creds=os_creds, ext_net_name=ext_net_name,
387         log_level=log_level))
388     suite.addTest(OSComponentTestCase.parameterize(
389         CreateInstanceMockOfflineTests, os_creds=os_creds,
390         ext_net_name=ext_net_name, log_level=log_level))