Ensure required keystone settings available

When setting up keystone certs we must validate whether the
settings we require are available before called the keystone
client.

Change-Id: I4bf09fe7bf7f5a136aa92cf8b74b1b4d0e87543f
Closes-Bug: 1714942
This commit is contained in:
Edward Hope-Morley 2017-09-04 13:38:06 +01:00
parent a1444c4b2f
commit 46796e503e
2 changed files with 35 additions and 9 deletions

View File

@ -503,16 +503,21 @@ def get_keystone_client_from_relation(relation_type='identity-service'):
:param relation_type: Relation to keystone
:returns: Keystone client
"""
required = ['admin_token', 'auth_host', 'auth_port', 'api_version']
settings = {}
rdata = {}
for relid in relation_ids(relation_type):
for unit in related_units(relid):
rdata = relation_get(unit=unit, rid=relid)
if rdata:
rdata = relation_get(unit=unit, rid=relid) or {}
if set(required).issubset(set(rdata.keys())):
settings = {key: rdata.get(key) for key in required}
break
required = ['admin_token', 'auth_host', 'auth_port', 'api_version']
settings = {key: rdata.get(key) for key in required}
if not settings:
log("Required settings not yet provided by any identity-service "
"relation units", INFO)
return None
auth_protocol = rdata.get('auth_protocol', 'http')
if is_ipv6(settings.get('auth_host')):

View File

@ -121,11 +121,11 @@ class CephRadosGWUtilTests(CharmTestCase):
@patch.object(utils, 'relation_ids')
@patch.object(utils, 'is_ipv6', lambda addr: False)
@patch.object(utils, 'relation_get')
def test_get_keystone_client_from_relation(self, mock_relation_get,
mock_relation_ids,
mock_related_units,
mock_client,
mock_client_v3):
def test_get_ks_client_from_relation(self, mock_relation_get,
mock_relation_ids,
mock_related_units,
mock_client,
mock_client_v3):
auth_host = 'foo/bar'
auth_port = 80
admin_token = '666'
@ -151,6 +151,27 @@ class CephRadosGWUtilTests(CharmTestCase):
mock_client_v3.Client.assert_called_with(endpoint=auth_url,
token=admin_token)
@patch.object(utils, 'client_v3')
@patch.object(utils, 'client')
@patch.object(utils, 'related_units')
@patch.object(utils, 'relation_ids')
@patch.object(utils, 'is_ipv6', lambda addr: False)
@patch.object(utils, 'relation_get')
def test_get_ks_client_from_relation_not_available(self, mock_relation_get,
mock_relation_ids,
mock_related_units,
mock_client,
mock_client_v3):
mock_relation_ids.return_value = ['identity-service:5']
mock_related_units.return_value = ['keystone/1']
rel_data = {'auth_port': '5000',
'admin_token': 'foo',
'api_version': '2'}
mock_relation_get.return_value = rel_data
ksclient = utils.get_keystone_client_from_relation()
self.assertIsNone(ksclient)
@patch.object(utils, 'get_ks_cert')
@patch.object(utils.subprocess, 'Popen')
@patch.object(utils.subprocess, 'check_output')