Ensure that we define unit
before use
When ceph-proxy is configured prior to being related to clients, it is possible for the units to go into a hook error because of an undefined variable. This change ensures that we do correctly define the unit before we use it. Change-Id: Ic6e28783bde4fc342d7c5ef1d733e69a03b702fe Closes-Bug: #1862487
This commit is contained in:
parent
98c8156538
commit
649bdb4683
@ -146,7 +146,8 @@ def notify_radosgws():
|
|||||||
|
|
||||||
def notify_client():
|
def notify_client():
|
||||||
for relid in relation_ids('client'):
|
for relid in relation_ids('client'):
|
||||||
client_relation_joined(relid)
|
for unit in related_units(relid):
|
||||||
|
client_relation_joined(relid=relid, unit=unit)
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('radosgw-relation-changed')
|
@hooks.hook('radosgw-relation-changed')
|
||||||
@ -195,7 +196,8 @@ def client_relation_joined(relid=None, unit=None):
|
|||||||
units = related_units(relid)
|
units = related_units(relid)
|
||||||
if len(units) > 0:
|
if len(units) > 0:
|
||||||
service_name = units[0].split('/')[0]
|
service_name = units[0].split('/')[0]
|
||||||
|
if unit is None:
|
||||||
|
unit = units[0]
|
||||||
if service_name is not None:
|
if service_name is not None:
|
||||||
ceph_addrs = config('monitor-hosts')
|
ceph_addrs = config('monitor-hosts')
|
||||||
data = {'key': ceph.get_named_key(service_name),
|
data = {'key': ceph.get_named_key(service_name),
|
||||||
|
@ -87,7 +87,9 @@ class TestHooks(test_utils.CharmTestCase):
|
|||||||
def c(k):
|
def c(k):
|
||||||
x = {'radosgw': ['rados:1'],
|
x = {'radosgw': ['rados:1'],
|
||||||
'client': ['client:1'],
|
'client': ['client:1'],
|
||||||
'rados:1': ['rados/1']}
|
'rados:1': ['rados/1'],
|
||||||
|
'client:1': ['client/1'],
|
||||||
|
}
|
||||||
return x[k]
|
return x[k]
|
||||||
|
|
||||||
self.relation_ids.side_effect = c
|
self.relation_ids.side_effect = c
|
||||||
@ -124,7 +126,7 @@ class TestHooks(test_utils.CharmTestCase):
|
|||||||
context, owner='ceph-user', perms=0o600)
|
context, owner='ceph-user', perms=0o600)
|
||||||
|
|
||||||
mock_rgw_rel.assert_called_with(relid='rados:1', unit='rados/1')
|
mock_rgw_rel.assert_called_with(relid='rados:1', unit='rados/1')
|
||||||
mock_client_rel.assert_called_with('client:1')
|
mock_client_rel.assert_called_with(relid='client:1', unit='client/1')
|
||||||
|
|
||||||
@mock.patch.object(hooks.ceph, 'ceph_user')
|
@mock.patch.object(hooks.ceph, 'ceph_user')
|
||||||
@mock.patch('subprocess.check_output')
|
@mock.patch('subprocess.check_output')
|
||||||
|
Loading…
Reference in New Issue
Block a user