Skip to content

Commit 57d227b

Browse files
committed
Enable SSL support on manila client
The python-manilaclient requires passing the cacert file for TLS endpoints. This commit enables that on the `get_manila_session_client` and also, for the manila tests, wraps the client in a retrier that retries on connection failures (i.e. if the server is not running).
1 parent 1e2a8a1 commit 57d227b

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

zaza/openstack/charm_tests/manila/tests.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
import logging
2020
import tenacity
2121

22-
from manilaclient import client as manilaclient
23-
2422
import zaza.model
2523
import zaza.openstack.configure.guest as guest
24+
from zaza.openstack.utilities import retry_on_connect_failure
2625
import zaza.openstack.utilities.generic as generic_utils
2726
import zaza.openstack.utilities.openstack as openstack_utils
2827
import zaza.openstack.charm_tests.test_utils as test_utils
@@ -67,8 +66,9 @@ class ManilaTests(test_utils.OpenStackBaseTest):
6766
def setUpClass(cls):
6867
"""Run class setup for running tests."""
6968
super(ManilaTests, cls).setUpClass()
70-
cls.manila_client = manilaclient.Client(
71-
session=cls.keystone_session, client_version='2')
69+
cls.manila_client = retry_on_connect_failure(
70+
openstack_utils.get_manila_session_client(
71+
session=cls.keystone_session))
7272

7373
def test_manila_api(self):
7474
"""Test that the Manila API is working."""
@@ -132,8 +132,8 @@ def setUpClass(cls):
132132
super(ManilaBaseTest, cls).setUpClass()
133133
cls.nova_client = openstack_utils.get_nova_session_client(
134134
session=cls.keystone_session)
135-
cls.manila_client = manilaclient.Client(
136-
session=cls.keystone_session, client_version='2')
135+
cls.manila_client = openstack_utils.get_manila_session_client(
136+
session=cls.keystone_session)
137137
cls.share_name = 'test-manila-share'
138138
cls.share_type_name = 'default_share_type'
139139
cls.share_protocol = 'nfs'
@@ -221,7 +221,7 @@ def _mount_share_on_instance(self, instance_ip, ssh_user_name,
221221

222222
for attempt in tenacity.Retrying(
223223
stop=tenacity.stop_after_attempt(5),
224-
wait=tenacity.wait_exponential(multiplier=3, min=2, max=10)):
224+
wait=tenacity.wait_exponential(multiplier=5, min=2, max=60)):
225225
with attempt:
226226
openstack_utils.ssh_command(
227227
vm_name="instance-{}".format(instance_ip),
@@ -233,7 +233,7 @@ def _mount_share_on_instance(self, instance_ip, ssh_user_name,
233233

234234
@tenacity.retry(
235235
stop=tenacity.stop_after_attempt(5),
236-
wait=tenacity.wait_exponential(multiplier=3, min=2, max=10))
236+
wait=tenacity.wait_exponential(multiplier=5, min=2, max=60))
237237
def _write_testing_file_on_instance(self, instance_ip, ssh_user_name,
238238
ssh_private_key):
239239
"""Write a file on a Manila share mounted into a Nova instance.
@@ -260,7 +260,7 @@ def _write_testing_file_on_instance(self, instance_ip, ssh_user_name,
260260

261261
@tenacity.retry(
262262
stop=tenacity.stop_after_attempt(5),
263-
wait=tenacity.wait_exponential(multiplier=3, min=2, max=10))
263+
wait=tenacity.wait_exponential(multiplier=5, min=2, max=60))
264264
def _clear_testing_file_on_instance(self, instance_ip, ssh_user_name,
265265
ssh_private_key):
266266
"""Clear a file on a Manila share mounted into a Nova instance.
@@ -287,7 +287,7 @@ def _clear_testing_file_on_instance(self, instance_ip, ssh_user_name,
287287

288288
@tenacity.retry(
289289
stop=tenacity.stop_after_attempt(5),
290-
wait=tenacity.wait_exponential(multiplier=3, min=2, max=10))
290+
wait=tenacity.wait_exponential(multiplier=5, min=2, max=60))
291291
def _validate_testing_file_from_instance(self, instance_ip, ssh_user_name,
292292
ssh_private_key):
293293
"""Validate a file from the Manila share mounted into a Nova instance.

zaza/openstack/charm_tests/manila_ganesha/setup.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import zaza.openstack.utilities.openstack as openstack_utils
2222

23-
from manilaclient import client as manilaclient
24-
2523

2624
MANILA_GANESHA_TYPE_NAME = "cephfsnfstype"
2725

@@ -34,8 +32,8 @@ def setup_ganesha_share_type(manila_client=None):
3432
"""
3533
if manila_client is None:
3634
keystone_session = openstack_utils.get_overcloud_keystone_session()
37-
manila_client = manilaclient.Client(
38-
session=keystone_session, client_version='2')
35+
manila_client = openstack_utils.get_manila_session_client(
36+
keystone_session)
3937

4038
manila_client.share_types.create(
4139
name=MANILA_GANESHA_TYPE_NAME, spec_driver_handles_share_servers=False,

zaza/openstack/utilities/openstack.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -513,17 +513,34 @@ def get_aodh_session_client(session):
513513
return aodh_client.Client(session=session)
514514

515515

516-
def get_manila_session_client(session, version='2'):
516+
def get_manila_session_client(session, version='2', model_name=None):
517517
"""Return Manila client authenticated by keystone session.
518518
519519
:param session: Keystone session object
520520
:type session: keystoneauth1.session.Session object
521521
:param version: Manila API version
522522
:type version: str
523+
:param model_name: Optional model name to get the client for.
524+
:type model_name: str
523525
:returns: Authenticated manilaclient
524526
:rtype: manilaclient.Client
525527
"""
526-
return manilaclient.Client(session=session, client_version=version)
528+
tls_rid = model.get_relation_id('manila', 'vault',
529+
model_name=model_name,
530+
remote_interface_name='certificates')
531+
ssl_config = get_application_config_option(
532+
'manila',
533+
'ssl_cert',
534+
model_name=model_name)
535+
extra_kwargs = {}
536+
if tls_rid or ssl_config:
537+
cacert = get_cacert()
538+
if cacert:
539+
extra_kwargs['cacert'] = cacert
540+
541+
return manilaclient.Client(session=session,
542+
client_version=version,
543+
**extra_kwargs)
527544

528545

529546
def get_watcher_session_client(session):
@@ -2229,6 +2246,7 @@ def _get_overcloud_auth(address=None, model_name=None):
22292246
else:
22302247
transport = 'http'
22312248
port = 5000
2249+
print("transport =", transport, " port=", port)
22322250

22332251
if not address:
22342252
address = get_keystone_ip(model_name=model_name)
@@ -2268,6 +2286,7 @@ def _get_overcloud_auth(address=None, model_name=None):
22682286
if local_ca_cert:
22692287
auth_settings['OS_CACERT'] = local_ca_cert
22702288

2289+
print("auth_settings\n", auth_settings)
22712290
return auth_settings
22722291

22732292

@@ -2479,6 +2498,8 @@ def _resource_reaches_status(resource, resource_id,
24792498
raise exceptions.StatusError(resource_status, expected_status)
24802499

24812500
assert resource_status == expected_status
2501+
logging.info("{}: resource {} now in {} state".format(
2502+
msg, resource_id, resource_status))
24822503

24832504

24842505
def resource_reaches_status(resource,

0 commit comments

Comments
 (0)