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