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.network_tests import (
23 SecurityGroupDomainObjectTests, SecurityGroupRuleDomainObjectTests,
24 PortDomainObjectTests, RouterDomainObjectTests,
25 InterfaceRouterDomainObjectTests, NetworkObjectTests, SubnetObjectTests)
26 from snaps.domain.test.project_tests import ProjectDomainObjectTests
27 from snaps.domain.test.role_tests import RoleDomainObjectTests
28 from snaps.domain.test.stack_tests import StackDomainObjectTests
29 from snaps.domain.test.user_tests import UserDomainObjectTests
30 from snaps.domain.test.vm_inst_tests import (
31 VmInstDomainObjectTests, FloatingIpDomainObjectTests)
32 from snaps.openstack.tests.conf.os_credentials_tests import (
33 ProxySettingsUnitTests, OSCredsUnitTests)
34 from snaps.openstack.tests.create_flavor_tests import (
35 CreateFlavorTests, FlavorSettingsUnitTests)
36 from snaps.openstack.tests.create_image_tests import (
37 CreateImageSuccessTests, CreateImageNegativeTests, ImageSettingsUnitTests,
38 CreateMultiPartImageTests)
39 from snaps.openstack.tests.create_instance_tests import (
40 CreateInstanceSingleNetworkTests, CreateInstancePubPrivNetTests,
41 CreateInstanceOnComputeHost, CreateInstanceSimpleTests,
42 FloatingIpSettingsUnitTests, InstanceSecurityGroupTests,
43 VmInstanceSettingsUnitTests, CreateInstancePortManipulationTests,
44 SimpleHealthCheck, CreateInstanceFromThreePartImage,
45 CreateInstanceMockOfflineTests)
46 from snaps.openstack.tests.create_keypairs_tests import (
47 CreateKeypairsTests, KeypairSettingsUnitTests, CreateKeypairsCleanupTests)
48 from snaps.openstack.tests.create_network_tests import (
49 CreateNetworkSuccessTests, NetworkSettingsUnitTests, PortSettingsUnitTests,
50 SubnetSettingsUnitTests, CreateNetworkTypeTests)
51 from snaps.openstack.tests.create_project_tests import (
52 CreateProjectSuccessTests, ProjectSettingsUnitTests,
53 CreateProjectUserTests)
54 from snaps.openstack.tests.create_router_tests import (
55 CreateRouterSuccessTests, CreateRouterNegativeTests,
56 RouterSettingsUnitTests)
57 from snaps.openstack.tests.create_security_group_tests import (
58 CreateSecurityGroupTests, SecurityGroupRuleSettingsUnitTests,
59 SecurityGroupSettingsUnitTests)
60 from snaps.openstack.tests.create_stack_tests import (
61 StackSettingsUnitTests, CreateStackSuccessTests, CreateStackNegativeTests)
62 from snaps.openstack.tests.create_user_tests import (
63 UserSettingsUnitTests, CreateUserSuccessTests)
64 from snaps.openstack.tests.os_source_file_test import (
65 OSComponentTestCase, OSIntegrationTestCase)
66 from snaps.openstack.utils.tests.glance_utils_tests import (
67 GlanceSmokeTests, GlanceUtilsTests)
68 from snaps.openstack.utils.tests.heat_utils_tests import (
69 HeatUtilsCreateStackTests, HeatSmokeTests)
70 from snaps.openstack.utils.tests.keystone_utils_tests import (
71 KeystoneSmokeTests, KeystoneUtilsTests)
72 from snaps.openstack.utils.tests.neutron_utils_tests import (
73 NeutronSmokeTests, NeutronUtilsNetworkTests, NeutronUtilsSubnetTests,
74 NeutronUtilsRouterTests, NeutronUtilsSecurityGroupTests,
75 NeutronUtilsFloatingIpTests)
76 from snaps.openstack.utils.tests.nova_utils_tests import (
77 NovaSmokeTests, NovaUtilsKeypairTests, NovaUtilsFlavorTests,
78 NovaUtilsInstanceTests)
79 from snaps.provisioning.tests.ansible_utils_tests import (
80 AnsibleProvisioningTests)
81 from snaps.tests.file_utils_tests import FileUtilsTests
83 __author__ = 'spisarski'
86 def add_unit_tests(suite):
88 Adds tests that do not require external resources
89 :param suite: the unittest.TestSuite object to which to add the tests
90 :return: None as the tests will be adding to the 'suite' parameter object
92 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(FileUtilsTests))
93 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
94 SecurityGroupRuleSettingsUnitTests))
95 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
96 ProxySettingsUnitTests))
97 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
99 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
100 SecurityGroupSettingsUnitTests))
101 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
102 SecurityGroupDomainObjectTests))
103 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
104 SecurityGroupRuleDomainObjectTests))
105 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
106 ImageSettingsUnitTests))
107 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
108 ImageDomainObjectTests))
109 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
110 FlavorSettingsUnitTests))
111 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
112 FlavorDomainObjectTests))
113 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
114 KeypairSettingsUnitTests))
115 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
116 KeypairDomainObjectTests))
117 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
118 UserSettingsUnitTests))
119 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
120 UserDomainObjectTests))
121 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
122 ProjectSettingsUnitTests))
123 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
124 ProjectDomainObjectTests))
125 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
126 RoleDomainObjectTests))
127 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
128 NetworkSettingsUnitTests))
129 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
131 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
132 SubnetSettingsUnitTests))
133 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
135 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
136 PortSettingsUnitTests))
137 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
138 PortDomainObjectTests))
139 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
140 RouterSettingsUnitTests))
141 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
142 RouterDomainObjectTests))
143 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
144 InterfaceRouterDomainObjectTests))
145 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
146 FloatingIpSettingsUnitTests))
147 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
148 VmInstanceSettingsUnitTests))
149 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
150 StackDomainObjectTests))
151 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
152 StackSettingsUnitTests))
153 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
154 VmInstDomainObjectTests))
155 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
156 FloatingIpDomainObjectTests))
159 def add_openstack_client_tests(suite, os_creds, ext_net_name,
160 use_keystone=True, log_level=logging.INFO):
162 Adds tests written to exercise OpenStack client retrieval
163 :param suite: the unittest.TestSuite object to which to add the tests
164 :param os_creds: and instance of OSCreds that holds the credentials
165 required by OpenStack
166 :param ext_net_name: the name of an external network on the cloud under
168 :param use_keystone: when True, tests requiring direct access to Keystone
169 are added as these need to be running on a host that
170 has access to the cloud's private network
171 :param log_level: the logging level
172 :return: None as the tests will be adding to the 'suite' parameter object
174 # Basic connection tests
176 OSComponentTestCase.parameterize(
177 GlanceSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
178 log_level=log_level))
182 OSComponentTestCase.parameterize(
183 KeystoneSmokeTests, os_creds=os_creds,
184 ext_net_name=ext_net_name, log_level=log_level))
187 OSComponentTestCase.parameterize(
188 NeutronSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
189 log_level=log_level))
191 OSComponentTestCase.parameterize(
192 NovaSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
193 log_level=log_level))
195 OSComponentTestCase.parameterize(
196 HeatSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
197 log_level=log_level))
200 def add_openstack_api_tests(suite, os_creds, ext_net_name, use_keystone=True,
201 image_metadata=None, log_level=logging.INFO):
203 Adds tests written to exercise all existing OpenStack APIs
204 :param suite: the unittest.TestSuite object to which to add the tests
205 :param os_creds: Instance of OSCreds that holds the credentials
206 required by OpenStack
207 :param ext_net_name: the name of an external network on the cloud under
209 :param use_keystone: when True, tests requiring direct access to Keystone
210 are added as these need to be running on a host that
211 has access to the cloud's private network
212 :param image_metadata: dict() object containing metadata for creating an
213 image with custom config
214 (see YAML files in examples/image-metadata)
215 :param log_level: the logging level
216 :return: None as the tests will be adding to the 'suite' parameter object
218 # Tests the OpenStack API calls
220 suite.addTest(OSComponentTestCase.parameterize(
221 KeystoneUtilsTests, os_creds=os_creds, ext_net_name=ext_net_name,
222 log_level=log_level))
223 suite.addTest(OSComponentTestCase.parameterize(
224 CreateUserSuccessTests, os_creds=os_creds,
225 ext_net_name=ext_net_name, log_level=log_level))
226 suite.addTest(OSComponentTestCase.parameterize(
227 CreateProjectSuccessTests, os_creds=os_creds,
228 ext_net_name=ext_net_name, log_level=log_level))
229 suite.addTest(OSComponentTestCase.parameterize(
230 CreateProjectUserTests, os_creds=os_creds,
231 ext_net_name=ext_net_name, log_level=log_level))
233 suite.addTest(OSComponentTestCase.parameterize(
234 GlanceUtilsTests, os_creds=os_creds, ext_net_name=ext_net_name,
235 image_metadata=image_metadata,
236 log_level=log_level))
237 suite.addTest(OSComponentTestCase.parameterize(
238 NeutronUtilsNetworkTests, os_creds=os_creds, ext_net_name=ext_net_name,
239 log_level=log_level))
240 suite.addTest(OSComponentTestCase.parameterize(
241 NeutronUtilsSubnetTests, os_creds=os_creds, ext_net_name=ext_net_name,
242 log_level=log_level))
243 suite.addTest(OSComponentTestCase.parameterize(
244 NeutronUtilsRouterTests, os_creds=os_creds, ext_net_name=ext_net_name,
245 log_level=log_level))
246 suite.addTest(OSComponentTestCase.parameterize(
247 NeutronUtilsSecurityGroupTests, os_creds=os_creds,
248 ext_net_name=ext_net_name, log_level=log_level))
249 suite.addTest(OSComponentTestCase.parameterize(
250 NeutronUtilsFloatingIpTests, os_creds=os_creds,
251 ext_net_name=ext_net_name, log_level=log_level))
252 suite.addTest(OSComponentTestCase.parameterize(
253 NovaUtilsKeypairTests, os_creds=os_creds, ext_net_name=ext_net_name,
254 log_level=log_level))
255 suite.addTest(OSComponentTestCase.parameterize(
256 NovaUtilsFlavorTests, os_creds=os_creds, ext_net_name=ext_net_name,
257 log_level=log_level))
258 suite.addTest(OSComponentTestCase.parameterize(
259 NovaUtilsInstanceTests, os_creds=os_creds, ext_net_name=ext_net_name,
260 log_level=log_level, image_metadata=image_metadata))
261 suite.addTest(OSComponentTestCase.parameterize(
262 CreateFlavorTests, os_creds=os_creds, ext_net_name=ext_net_name,
263 log_level=log_level))
264 suite.addTest(OSComponentTestCase.parameterize(
265 HeatUtilsCreateStackTests, os_creds=os_creds,
266 ext_net_name=ext_net_name, log_level=log_level,
267 image_metadata=image_metadata))
270 def add_openstack_integration_tests(suite, os_creds, ext_net_name,
271 use_keystone=True, flavor_metadata=None,
272 image_metadata=None, use_floating_ips=True,
273 log_level=logging.INFO):
275 Adds tests written to exercise all long-running OpenStack integration tests
276 meaning they will be creating VM instances and potentially performing some
277 SSH functions through floatingIPs
278 :param suite: the unittest.TestSuite object to which to add the tests
279 :param os_creds: and instance of OSCreds that holds the credentials
280 required by OpenStack
281 :param ext_net_name: the name of an external network on the cloud under
283 :param use_keystone: when True, tests requiring direct access to Keystone
284 are added as these need to be running on a host that
285 has access to the cloud's private network
286 :param image_metadata: dict() object containing metadata for creating an
287 image with custom config
288 (see YAML files in examples/image-metadata)
289 :param flavor_metadata: dict() object containing the metadata required by
290 your flavor based on your configuration:
291 (i.e. {'hw:mem_page_size': 'large'})
292 :param use_floating_ips: when true, all tests requiring Floating IPs will
293 be added to the suite
294 :param log_level: the logging level
295 :return: None as the tests will be adding to the 'suite' parameter object
297 # Tests the OpenStack API calls via a creator. If use_keystone, objects
298 # will be created with a custom user and project
300 # Creator Object tests
301 suite.addTest(OSIntegrationTestCase.parameterize(
302 CreateSecurityGroupTests, 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 CreateImageSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name,
308 use_keystone=use_keystone,
309 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
310 log_level=log_level))
311 suite.addTest(OSIntegrationTestCase.parameterize(
312 CreateImageNegativeTests, os_creds=os_creds, ext_net_name=ext_net_name,
313 use_keystone=use_keystone,
314 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
315 log_level=log_level))
316 suite.addTest(OSIntegrationTestCase.parameterize(
317 CreateMultiPartImageTests, os_creds=os_creds,
318 ext_net_name=ext_net_name, use_keystone=use_keystone,
319 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
320 log_level=log_level))
321 suite.addTest(OSIntegrationTestCase.parameterize(
322 CreateKeypairsTests, os_creds=os_creds, ext_net_name=ext_net_name,
323 use_keystone=use_keystone,
324 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
325 log_level=log_level))
326 suite.addTest(OSIntegrationTestCase.parameterize(
327 CreateKeypairsCleanupTests, os_creds=os_creds, ext_net_name=ext_net_name,
328 use_keystone=use_keystone,
329 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
330 log_level=log_level))
331 suite.addTest(OSIntegrationTestCase.parameterize(
332 CreateNetworkSuccessTests, 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 CreateRouterSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name,
338 use_keystone=use_keystone,
339 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
340 log_level=log_level))
341 suite.addTest(OSIntegrationTestCase.parameterize(
342 CreateRouterNegativeTests, 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))
348 suite.addTest(OSIntegrationTestCase.parameterize(
349 SimpleHealthCheck, 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 suite.addTest(OSIntegrationTestCase.parameterize(
354 CreateInstanceSimpleTests, os_creds=os_creds,
355 ext_net_name=ext_net_name, use_keystone=use_keystone,
356 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
357 log_level=log_level))
358 suite.addTest(OSIntegrationTestCase.parameterize(
359 CreateInstancePortManipulationTests, 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 InstanceSecurityGroupTests, 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 CreateInstanceOnComputeHost, 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))
373 suite.addTest(OSIntegrationTestCase.parameterize(
374 CreateInstanceFromThreePartImage, os_creds=os_creds,
375 ext_net_name=ext_net_name, use_keystone=use_keystone,
376 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
377 log_level=log_level))
378 suite.addTest(OSIntegrationTestCase.parameterize(
379 CreateStackSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name,
380 use_keystone=use_keystone,
381 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
382 log_level=log_level))
383 suite.addTest(OSIntegrationTestCase.parameterize(
384 CreateStackNegativeTests, os_creds=os_creds, ext_net_name=ext_net_name,
385 use_keystone=use_keystone,
386 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
387 log_level=log_level))
390 suite.addTest(OSIntegrationTestCase.parameterize(
391 CreateInstanceSingleNetworkTests, os_creds=os_creds,
392 ext_net_name=ext_net_name, use_keystone=use_keystone,
393 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
394 log_level=log_level))
395 suite.addTest(OSIntegrationTestCase.parameterize(
396 CreateInstancePubPrivNetTests, os_creds=os_creds,
397 ext_net_name=ext_net_name, use_keystone=use_keystone,
398 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
399 log_level=log_level))
400 suite.addTest(OSIntegrationTestCase.parameterize(
401 AnsibleProvisioningTests, os_creds=os_creds,
402 ext_net_name=ext_net_name, use_keystone=use_keystone,
403 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
404 log_level=log_level))
407 def add_openstack_ci_tests(
408 suite, os_creds, ext_net_name, use_keystone=True, flavor_metadata=None,
409 image_metadata=None, use_floating_ips=True, log_level=logging.INFO):
411 Adds tests written for a CI server to run the tests to validate code
413 :param suite: the unittest.TestSuite object to which to add the tests
414 :param os_creds: and instance of OSCreds that holds the credentials
415 required by OpenStack
416 :param ext_net_name: the name of an external network on the cloud under
418 :param use_keystone: when True, tests requiring direct access to Keystone
419 are added as these need to be running on a host that
420 has access to the cloud's private network
421 :param image_metadata: dict() object containing metadata for creating an
422 image with custom config
423 (see YAML files in examples/image-metadata)
424 :param flavor_metadata: dict() object containing the metadata required by
425 your flavor based on your configuration:
426 (i.e. {'hw:mem_page_size': 'large'})
427 :param use_floating_ips: when true, all tests requiring Floating IPs will
428 be added to the suite
429 :param log_level: the logging level
430 :return: None as the tests will be adding to the 'suite' parameter object
433 add_unit_tests(suite)
435 add_openstack_client_tests(suite, os_creds, ext_net_name, use_keystone,
438 add_openstack_api_tests(suite, os_creds, ext_net_name, use_keystone,
439 image_metadata, log_level)
441 suite.addTest(OSIntegrationTestCase.parameterize(
442 SimpleHealthCheck, os_creds=os_creds, ext_net_name=ext_net_name,
443 use_keystone=use_keystone,
444 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
445 log_level=log_level))
448 suite.addTest(OSIntegrationTestCase.parameterize(
449 CreateInstanceSingleNetworkTests, os_creds=os_creds,
450 ext_net_name=ext_net_name, use_keystone=use_keystone,
451 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
452 log_level=log_level))
454 suite.addTest(OSIntegrationTestCase.parameterize(
455 CreateStackSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name,
456 use_keystone=use_keystone,
457 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
458 log_level=log_level))
459 suite.addTest(OSIntegrationTestCase.parameterize(
460 CreateStackNegativeTests, os_creds=os_creds, ext_net_name=ext_net_name,
461 use_keystone=use_keystone,
462 flavor_metadata=flavor_metadata, image_metadata=image_metadata,
463 log_level=log_level))
466 def add_openstack_staging_tests(suite, os_creds, ext_net_name,
467 log_level=logging.INFO):
469 Adds tests that are still in development have not been designed to run
470 successfully against all OpenStack pods
471 :param suite: the unittest.TestSuite object to which to add the tests
472 :param os_creds: Instance of OSCreds that holds the credentials
473 required by OpenStack
474 :param ext_net_name: the name of an external network on the cloud under
476 :param log_level: the logging level
477 :return: None as the tests will be adding to the 'suite' parameter object
479 suite.addTest(OSComponentTestCase.parameterize(
480 CreateNetworkTypeTests, os_creds=os_creds, ext_net_name=ext_net_name,
481 log_level=log_level))
482 suite.addTest(OSComponentTestCase.parameterize(
483 CreateInstanceMockOfflineTests, os_creds=os_creds,
484 ext_net_name=ext_net_name, log_level=log_level))