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