Added new 3-part image tests to test_suite_builder.py and documented them
[snaps.git] / snaps / test_suite_builder.py
1 # Copyright (c) 2016 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.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
43
44 __author__ = 'spisarski'
45
46
47 def add_unit_tests(suite):
48     """
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
52     """
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))
65
66
67 def add_openstack_client_tests(suite, source_filename, ext_net_name, use_keystone=True, http_proxy_str=None,
68                                log_level=logging.INFO):
69     """
70     Adds tests written to exercise OpenStack client retrieval
71     :param suite: the unittest.TestSuite object to which to add the tests
72     :param source_filename: the OpenStack credentials filename
73     :param ext_net_name: the name of an external network on the cloud under test
74     :param http_proxy_str: <host>:<port> of the proxy server (optional)
75     :param use_keystone: when True, tests requiring direct access to Keystone are added as these need to be running on
76                          a host that has access to the cloud's private network
77     :param log_level: the logging level
78     :return: None as the tests will be adding to the 'suite' parameter object
79     """
80     # Basic connection tests
81     suite.addTest(OSComponentTestCase.parameterize(GlanceSmokeTests, source_filename, ext_net_name,
82                                                    http_proxy_str=http_proxy_str, log_level=log_level))
83
84     if use_keystone:
85         suite.addTest(OSComponentTestCase.parameterize(KeystoneSmokeTests, source_filename, ext_net_name,
86                                                        http_proxy_str=http_proxy_str, log_level=log_level))
87
88     suite.addTest(OSComponentTestCase.parameterize(NeutronSmokeTests, source_filename, ext_net_name,
89                                                    http_proxy_str=http_proxy_str, log_level=log_level))
90     suite.addTest(OSComponentTestCase.parameterize(NovaSmokeTests, source_filename, ext_net_name,
91                                                    http_proxy_str=http_proxy_str, log_level=log_level))
92
93
94 def add_openstack_api_tests(suite, source_filename, ext_net_name, http_proxy_str=None, use_keystone=True,
95                             log_level=logging.INFO):
96     """
97     Adds tests written to exercise all existing OpenStack APIs
98     :param suite: the unittest.TestSuite object to which to add the tests
99     :param source_filename: the OpenStack credentials filename
100     :param ext_net_name: the name of an external network on the cloud under test
101     :param http_proxy_str: <host>:<port> of the proxy server (optional)
102     :param use_keystone: when True, tests requiring direct access to Keystone are added as these need to be running on
103                          a host that has access to the cloud's private network
104     :param log_level: the logging level
105     :return: None as the tests will be adding to the 'suite' parameter object
106     """
107     # Tests the OpenStack API calls
108     if use_keystone:
109         suite.addTest(OSComponentTestCase.parameterize(KeystoneUtilsTests, source_filename, ext_net_name,
110                                                        http_proxy_str=http_proxy_str, log_level=log_level))
111         suite.addTest(OSComponentTestCase.parameterize(CreateUserSuccessTests, source_filename, ext_net_name,
112                                                        http_proxy_str=http_proxy_str, log_level=log_level))
113         suite.addTest(OSComponentTestCase.parameterize(CreateProjectSuccessTests, source_filename, ext_net_name,
114                                                        http_proxy_str=http_proxy_str, log_level=log_level))
115         suite.addTest(OSComponentTestCase.parameterize(CreateProjectUserTests, source_filename, ext_net_name,
116                                                        http_proxy_str=http_proxy_str, log_level=log_level))
117
118     suite.addTest(OSComponentTestCase.parameterize(GlanceUtilsTests, source_filename, ext_net_name,
119                                                    http_proxy_str=http_proxy_str, log_level=log_level))
120     suite.addTest(OSComponentTestCase.parameterize(NeutronUtilsNetworkTests, source_filename, ext_net_name,
121                                                    http_proxy_str=http_proxy_str, log_level=log_level))
122     suite.addTest(OSComponentTestCase.parameterize(NeutronUtilsSubnetTests, source_filename, ext_net_name,
123                                                    http_proxy_str=http_proxy_str, log_level=log_level))
124     suite.addTest(OSComponentTestCase.parameterize(NeutronUtilsRouterTests, source_filename, ext_net_name,
125                                                    http_proxy_str=http_proxy_str, log_level=log_level))
126     suite.addTest(OSComponentTestCase.parameterize(NeutronUtilsSecurityGroupTests, source_filename, ext_net_name,
127                                                    http_proxy_str=http_proxy_str, log_level=log_level))
128     suite.addTest(OSComponentTestCase.parameterize(NovaUtilsKeypairTests, source_filename, ext_net_name,
129                                                    http_proxy_str=http_proxy_str, log_level=log_level))
130     suite.addTest(OSComponentTestCase.parameterize(NovaUtilsFlavorTests, source_filename, ext_net_name,
131                                                    http_proxy_str=http_proxy_str, log_level=log_level))
132     suite.addTest(OSComponentTestCase.parameterize(CreateFlavorTests, source_filename, ext_net_name,
133                                                    http_proxy_str=http_proxy_str, log_level=log_level))
134
135
136 def add_openstack_integration_tests(suite, source_filename, ext_net_name, proxy_settings=None, ssh_proxy_cmd=None,
137                                     use_keystone=True, use_floating_ips=True, log_level=logging.INFO):
138     """
139     Adds tests written to exercise all long-running OpenStack integration tests meaning they will be creating VM
140     instances and potentially performing some SSH functions through floating IPs
141     :param suite: the unittest.TestSuite object to which to add the tests
142     :param source_filename: the OpenStack credentials filename
143     :param ext_net_name: the name of an external network on the cloud under test
144     :param proxy_settings: <host>:<port> of the proxy server (optional)
145     :param ssh_proxy_cmd: the command your environment requires for creating ssh connections through a proxy
146     :param use_keystone: when True, tests requiring direct access to Keystone are added as these need to be running on
147                          a host that has access to the cloud's private network
148     :param use_floating_ips: when true, all tests requiring Floating IPs will be added to the suite
149     :param log_level: the logging level
150     :return: None as the tests will be adding to the 'suite' parameter object
151     """
152     # Tests the OpenStack API calls via a creator. If use_keystone, objects will be created with a custom user
153     # and project
154
155     # Creator Object tests
156     suite.addTest(OSIntegrationTestCase.parameterize(CreateSecurityGroupTests, source_filename, ext_net_name,
157                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
158                                                      log_level=log_level))
159     suite.addTest(OSIntegrationTestCase.parameterize(CreateImageSuccessTests, source_filename, ext_net_name,
160                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
161                                                      log_level=log_level))
162     suite.addTest(OSIntegrationTestCase.parameterize(CreateImageNegativeTests, source_filename, ext_net_name,
163                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
164                                                      log_level=log_level))
165     suite.addTest(OSIntegrationTestCase.parameterize(CreateMultiPartImageTests, source_filename, ext_net_name,
166                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
167                                                      log_level=log_level))
168     suite.addTest(OSIntegrationTestCase.parameterize(CreateKeypairsTests, source_filename, ext_net_name,
169                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
170                                                      log_level=log_level))
171     suite.addTest(OSIntegrationTestCase.parameterize(CreateNetworkSuccessTests, source_filename, ext_net_name,
172                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
173                                                      log_level=log_level))
174     suite.addTest(OSComponentTestCase.parameterize(CreateNetworkTypeTests, source_filename, ext_net_name,
175                                                    http_proxy_str=proxy_settings, log_level=log_level))
176     suite.addTest(OSIntegrationTestCase.parameterize(CreateRouterSuccessTests, source_filename, ext_net_name,
177                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
178                                                      log_level=log_level))
179     suite.addTest(OSIntegrationTestCase.parameterize(CreateRouterNegativeTests, source_filename, ext_net_name,
180                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
181                                                      log_level=log_level))
182
183     # VM Instances
184     suite.addTest(OSIntegrationTestCase.parameterize(SimpleHealthCheck, source_filename, ext_net_name,
185                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
186                                                      log_level=log_level))
187     suite.addTest(OSIntegrationTestCase.parameterize(CreateInstanceSimpleTests, source_filename, ext_net_name,
188                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
189                                                      log_level=log_level))
190     suite.addTest(OSIntegrationTestCase.parameterize(CreateInstancePortManipulationTests, source_filename, ext_net_name,
191                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
192                                                      log_level=log_level))
193     suite.addTest(OSIntegrationTestCase.parameterize(InstanceSecurityGroupTests, source_filename, ext_net_name,
194                                                      http_proxy_str=proxy_settings, use_keystone=use_keystone,
195                                                      log_level=log_level))
196     suite.addTest(OSComponentTestCase.parameterize(CreateInstanceOnComputeHost, source_filename, ext_net_name,
197                                                    http_proxy_str=proxy_settings, log_level=log_level))
198     suite.addTest(OSComponentTestCase.parameterize(CreateInstanceFromThreePartImage, source_filename, ext_net_name,
199                                                    http_proxy_str=proxy_settings, log_level=log_level))
200
201     if use_floating_ips:
202         suite.addTest(OSIntegrationTestCase.parameterize(CreateInstanceSingleNetworkTests, source_filename,
203                                                          ext_net_name, http_proxy_str=proxy_settings,
204                                                          ssh_proxy_cmd=ssh_proxy_cmd, use_keystone=use_keystone,
205                                                          log_level=log_level))
206         suite.addTest(OSIntegrationTestCase.parameterize(CreateInstancePubPrivNetTests, source_filename,
207                                                          ext_net_name, http_proxy_str=proxy_settings,
208                                                          ssh_proxy_cmd=ssh_proxy_cmd, use_keystone=use_keystone,
209                                                          log_level=log_level))
210         suite.addTest(OSIntegrationTestCase.parameterize(AnsibleProvisioningTests, source_filename,
211                                                          ext_net_name, http_proxy_str=proxy_settings,
212                                                          ssh_proxy_cmd=ssh_proxy_cmd, use_keystone=use_keystone,
213                                                          log_level=log_level))