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.
18 from snaps.config.cluster_template import ClusterTemplateConfig
19 from snaps.config.keypair import KeypairConfig
20 from snaps.openstack.create_image import OpenStackImage
21 from snaps.openstack.create_keypairs import OpenStackKeypair
22 from snaps.openstack.os_credentials import OSCreds
23 from snaps.openstack.tests import openstack_tests
24 from snaps.openstack.tests.os_source_file_test import OSComponentTestCase
25 from snaps.openstack.utils import magnum_utils
27 __author__ = 'spisarski'
29 logger = logging.getLogger('magnum_utils_tests')
32 class MagnumSmokeTests(OSComponentTestCase):
34 Tests to ensure that the magnum client can communicate with the cloud
37 def test_connect_success(self):
39 Tests to ensure that the proper credentials can connect.
41 magnum = magnum_utils.magnum_client(self.os_creds)
43 # This should not throw an exception
44 self.assertIsNotNone(magnum.clusters.list())
46 def test_nova_connect_fail(self):
48 Tests to ensure that the improper credentials cannot connect.
51 with self.assertRaises(RuntimeError):
52 magnum_utils.magnum_client(
53 OSCreds(username='user', password='pass',
54 auth_url=self.os_creds.auth_url,
55 project_name=self.os_creds.project_name,
56 proxy_settings=self.os_creds.proxy_settings))
59 class MagnumUtilsTests(OSComponentTestCase):
61 Tests individual functions within magnum_utils.py
65 self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
66 self.cluster_type_name = self.guid + '-cluster-type'
67 self.magnum = magnum_utils.magnum_client(self.os_creds)
69 metadata = self.image_metadata
72 if 'extra_properties' not in metadata:
73 metadata['extra_properties'] = dict()
74 metadata['extra_properties']['os_distro'] = 'cirros'
76 os_image_settings = openstack_tests.cirros_image_settings(
77 name=self.guid + '-image', image_metadata=metadata)
79 self.image_creator = OpenStackImage(self.os_creds, os_image_settings)
81 keypair_priv_filepath = 'tmp/' + self.guid
82 keypair_pub_filepath = keypair_priv_filepath + '.pub'
84 self.keypair_creator = OpenStackKeypair(
85 self.os_creds, KeypairConfig(
86 name=self.guid + '-keypair',
87 public_filepath=keypair_pub_filepath,
88 private_filepath=keypair_priv_filepath))
90 self.cluster_template = None
93 self.image_creator.create()
94 self.keypair_creator.create()
100 if self.cluster_template:
102 magnum_utils.delete_cluster_template(
103 self.magnum, self.cluster_template.id)
106 if self.keypair_creator:
108 self.keypair_creator.clean()
111 if self.image_creator:
113 self.image_creator.clean()
117 def test_create_cluster_template_simple(self):
118 config = ClusterTemplateConfig(
119 name=self.cluster_type_name,
120 image=self.image_creator.image_settings.name,
121 keypair=self.keypair_creator.keypair_settings.name,
122 external_net=self.ext_net_name)
124 self.cluster_template = magnum_utils.create_cluster_template(
126 self.assertIsNotNone(self.cluster_template)
128 validate_cluster_template(config, self.cluster_template))
131 def validate_cluster_template(tmplt_config, tmplt_obj):
133 Returns true if the configuration matches the ClusterTemplate object
134 :param tmplt_config: the ClusterTemplateConfig object
135 :param tmplt_obj: the ClusterTemplate domain object
138 if not tmplt_config.network_driver:
139 network_driver = 'flannel'
141 network_driver = tmplt_config.network_driver
144 tmplt_config.coe.value == tmplt_obj.coe and
145 tmplt_config.dns_nameserver == tmplt_obj.dns_nameserver and
146 tmplt_config.docker_storage_driver.value
147 == tmplt_obj.docker_storage_driver and
148 tmplt_config.docker_volume_size == tmplt_obj.docker_volume_size and
149 tmplt_config.external_net == tmplt_obj.external_net and
150 tmplt_config.fixed_net == tmplt_obj.fixed_net and
151 tmplt_config.fixed_subnet == tmplt_obj.fixed_subnet and
152 tmplt_config.flavor == tmplt_obj.flavor and
153 tmplt_config.floating_ip_enabled == tmplt_obj.floating_ip_enabled and
154 tmplt_config.http_proxy == tmplt_obj.http_proxy and
155 tmplt_config.https_proxy == tmplt_obj.https_proxy and
156 tmplt_config.no_proxy == tmplt_obj.no_proxy and
157 tmplt_config.image == tmplt_obj.image and
158 tmplt_config.insecure_registry == tmplt_obj.insecure_registry and
159 tmplt_config.keypair == tmplt_obj.keypair and
160 tmplt_config.labels == tmplt_obj.labels and
161 tmplt_config.master_flavor == tmplt_obj.master_flavor and
162 tmplt_config.master_lb_enabled == tmplt_obj.master_lb_enabled and
163 tmplt_config.name == tmplt_obj.name and
164 network_driver == tmplt_obj.network_driver and
165 tmplt_config.no_proxy == tmplt_obj.no_proxy and
166 tmplt_config.public == tmplt_obj.public and
167 tmplt_config.registry_enabled == tmplt_obj.registry_enabled and
168 tmplt_config.server_type.value == tmplt_obj.server_type and
169 tmplt_config.tls_disabled == tmplt_obj.tls_disabled and
170 tmplt_config.volume_driver == tmplt_obj.volume_driver
172 # def test_create_cluster_simple(self):
173 # cluster = magnum_utils.create_cluster(self.magnum, 'foo')
174 # self.assertIsNotNone(cluster)