1 # Copyright (c) 2016 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.openstack.utils.tests.glance_utils_tests import GlanceSmokeTests, GlanceUtilsTests
20 from snaps.openstack.tests.create_flavor_tests import CreateFlavorTests
21 from snaps.tests.file_utils_tests import FileUtilsTests
22 from snaps.openstack.tests.create_security_group_tests import CreateSecurityGroupTests, \
23 SecurityGroupRuleSettingsUnitTests, SecurityGroupSettingsUnitTests
24 from snaps.openstack.tests.create_project_tests import CreateProjectSuccessTests, ProjectSettingsUnitTests, \
25 CreateProjectUserTests
26 from snaps.openstack.tests.create_user_tests import UserSettingsUnitTests, CreateUserSuccessTests
27 from snaps.openstack.utils.tests.keystone_utils_tests import KeystoneSmokeTests, KeystoneUtilsTests
28 from snaps.openstack.utils.tests.neutron_utils_tests import NeutronSmokeTests, NeutronUtilsNetworkTests, \
29 NeutronUtilsSubnetTests, NeutronUtilsRouterTests, NeutronUtilsSecurityGroupTests
30 from snaps.openstack.tests.create_image_tests import CreateImageSuccessTests, CreateImageNegativeTests, \
31 ImageSettingsUnitTests, CreateMultiPartImageTests
32 from snaps.openstack.tests.create_keypairs_tests import CreateKeypairsTests, KeypairSettingsUnitTests
33 from snaps.openstack.tests.create_network_tests import CreateNetworkSuccessTests, NetworkSettingsUnitTests, \
34 PortSettingsUnitTests, SubnetSettingsUnitTests, CreateNetworkTypeTests
35 from snaps.openstack.tests.create_router_tests import CreateRouterSuccessTests, CreateRouterNegativeTests
36 from snaps.openstack.tests.create_instance_tests import CreateInstanceSingleNetworkTests, \
37 CreateInstancePubPrivNetTests, CreateInstanceOnComputeHost, CreateInstanceSimpleTests, \
38 FloatingIpSettingsUnitTests, InstanceSecurityGroupTests, VmInstanceSettingsUnitTests, \
39 CreateInstancePortManipulationTests, SimpleHealthCheck, CreateInstanceFromThreePartImage
40 from snaps.provisioning.tests.ansible_utils_tests import AnsibleProvisioningTests
41 from snaps.openstack.tests.os_source_file_test import OSComponentTestCase, OSIntegrationTestCase
42 from snaps.openstack.utils.tests.nova_utils_tests import NovaSmokeTests, NovaUtilsKeypairTests, NovaUtilsFlavorTests
44 __author__ = 'spisarski'
47 def add_unit_tests(suite):
49 Adds tests that do not require external resources
50 :param suite: the unittest.TestSuite object to which to add the tests
51 :return: None as the tests will be adding to the 'suite' parameter object
53 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(FileUtilsTests))
54 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(SecurityGroupRuleSettingsUnitTests))
55 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(SecurityGroupSettingsUnitTests))
56 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(ImageSettingsUnitTests))
57 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(KeypairSettingsUnitTests))
58 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(UserSettingsUnitTests))
59 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(ProjectSettingsUnitTests))
60 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(NetworkSettingsUnitTests))
61 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(SubnetSettingsUnitTests))
62 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(PortSettingsUnitTests))
63 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(FloatingIpSettingsUnitTests))
64 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(VmInstanceSettingsUnitTests))
67 def add_openstack_client_tests(suite, os_creds, ext_net_name, use_keystone=True, log_level=logging.INFO):
69 Adds tests written to exercise OpenStack client retrieval
70 :param suite: the unittest.TestSuite object to which to add the tests
71 :param os_creds: and instance of OSCreds that holds the credentials required by OpenStack
72 :param ext_net_name: the name of an external network on the cloud under test
73 :param use_keystone: when True, tests requiring direct access to Keystone are added as these need to be running on
74 a host that has access to the cloud's private network
75 :param log_level: the logging level
76 :return: None as the tests will be adding to the 'suite' parameter object
78 # Basic connection tests
79 suite.addTest(OSComponentTestCase.parameterize(GlanceSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
83 suite.addTest(OSComponentTestCase.parameterize(KeystoneSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
86 suite.addTest(OSComponentTestCase.parameterize(NeutronSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
88 suite.addTest(OSComponentTestCase.parameterize(NovaSmokeTests, os_creds=os_creds, ext_net_name=ext_net_name,
92 def add_openstack_api_tests(suite, os_creds, ext_net_name, use_keystone=True, log_level=logging.INFO):
94 Adds tests written to exercise all existing OpenStack APIs
95 :param suite: the unittest.TestSuite object to which to add the tests
96 :param os_creds: and instance of OSCreds that holds the credentials required by OpenStack
97 :param ext_net_name: the name of an external network on the cloud under test
98 :param use_keystone: when True, tests requiring direct access to Keystone are added as these need to be running on
99 a host that has access to the cloud's private network
100 :param log_level: the logging level
101 :return: None as the tests will be adding to the 'suite' parameter object
103 # Tests the OpenStack API calls
105 suite.addTest(OSComponentTestCase.parameterize(
106 KeystoneUtilsTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
107 suite.addTest(OSComponentTestCase.parameterize(
108 CreateUserSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
109 suite.addTest(OSComponentTestCase.parameterize(
110 CreateProjectSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
111 suite.addTest(OSComponentTestCase.parameterize(
112 CreateProjectUserTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
114 suite.addTest(OSComponentTestCase.parameterize(
115 GlanceUtilsTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
116 suite.addTest(OSComponentTestCase.parameterize(
117 NeutronUtilsNetworkTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
118 suite.addTest(OSComponentTestCase.parameterize(
119 NeutronUtilsSubnetTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
120 suite.addTest(OSComponentTestCase.parameterize(
121 NeutronUtilsRouterTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
122 suite.addTest(OSComponentTestCase.parameterize(
123 NeutronUtilsSecurityGroupTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
124 suite.addTest(OSComponentTestCase.parameterize(
125 NovaUtilsKeypairTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
126 suite.addTest(OSComponentTestCase.parameterize(
127 NovaUtilsFlavorTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
128 suite.addTest(OSComponentTestCase.parameterize(
129 CreateFlavorTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))
132 def add_openstack_integration_tests(suite, os_creds, ext_net_name, use_keystone=True, flavor_metadata=None,
133 image_metadata=None, use_floating_ips=True, log_level=logging.INFO):
135 Adds tests written to exercise all long-running OpenStack integration tests meaning they will be creating VM
136 instances and potentially performing some SSH functions through floating IPs
137 :param suite: the unittest.TestSuite object to which to add the tests
138 :param os_creds: and instance of OSCreds that holds the credentials required by OpenStack
139 :param ext_net_name: the name of an external network on the cloud under test
140 :param use_keystone: when True, tests requiring direct access to Keystone are added as these need to be running on
141 a host that has access to the cloud's private network
142 :param image_metadata: dict() object containing metadata for creating an image with custom config:
143 (i.e. {'hw_video_model' : 'vga'}). It can be used to override the default url and
144 create 3-part images by passing kerner_url and ramdisk_url info
145 :param flavor_metadata: dict() object containing the metadata required by your flavor based on your configuration:
146 (i.e. {'hw:mem_page_size': 'large'})
147 :param use_floating_ips: when true, all tests requiring Floating IPs will be added to the suite
148 :param log_level: the logging level
149 :return: None as the tests will be adding to the 'suite' parameter object
151 # Tests the OpenStack API calls via a creator. If use_keystone, objects will be created with a custom user
154 # Creator Object tests
155 suite.addTest(OSIntegrationTestCase.parameterize(
156 CreateSecurityGroupTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
157 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
158 suite.addTest(OSIntegrationTestCase.parameterize(
159 CreateImageSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
160 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
161 suite.addTest(OSIntegrationTestCase.parameterize(
162 CreateImageNegativeTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
163 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
164 suite.addTest(OSIntegrationTestCase.parameterize(
165 CreateMultiPartImageTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
166 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
167 suite.addTest(OSIntegrationTestCase.parameterize(
168 CreateKeypairsTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
169 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
170 suite.addTest(OSIntegrationTestCase.parameterize(
171 CreateNetworkSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
172 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
173 suite.addTest(OSIntegrationTestCase.parameterize(
174 CreateRouterSuccessTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
175 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
176 suite.addTest(OSIntegrationTestCase.parameterize(
177 CreateRouterNegativeTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
178 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
181 suite.addTest(OSIntegrationTestCase.parameterize(
182 SimpleHealthCheck, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
183 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
184 suite.addTest(OSIntegrationTestCase.parameterize(
185 CreateInstanceSimpleTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
186 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
187 suite.addTest(OSIntegrationTestCase.parameterize(
188 CreateInstancePortManipulationTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
189 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
190 suite.addTest(OSIntegrationTestCase.parameterize(
191 InstanceSecurityGroupTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
192 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
193 suite.addTest(OSIntegrationTestCase.parameterize(
194 CreateInstanceOnComputeHost, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
195 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
196 suite.addTest(OSIntegrationTestCase.parameterize(
197 CreateInstanceFromThreePartImage, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
198 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
201 suite.addTest(OSIntegrationTestCase.parameterize(
202 CreateInstanceSingleNetworkTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
203 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
204 suite.addTest(OSIntegrationTestCase.parameterize(
205 CreateInstancePubPrivNetTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
206 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
207 suite.addTest(OSIntegrationTestCase.parameterize(
208 AnsibleProvisioningTests, os_creds=os_creds, ext_net_name=ext_net_name, use_keystone=use_keystone,
209 flavor_metadata=flavor_metadata, image_metadata=image_metadata, log_level=log_level))
212 def add_openstack_staging_tests(suite, os_creds, ext_net_name, log_level=logging.INFO):
214 Adds tests that are still in development have not been designed to run successfully against all OpenStack pods
215 :param suite: the unittest.TestSuite object to which to add the tests
216 :param os_creds: and instance of OSCreds that holds the credentials required by OpenStack
217 :param ext_net_name: the name of an external network on the cloud under test
218 :param log_level: the logging level
219 :return: None as the tests will be adding to the 'suite' parameter object
221 suite.addTest(OSComponentTestCase.parameterize(
222 CreateNetworkTypeTests, os_creds=os_creds, ext_net_name=ext_net_name, log_level=log_level))