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