Skip to content

Commit

Permalink
Add RemoteRestartContext
Browse files Browse the repository at this point in the history
Add RemoteRestartContext to process remote restart triggers
down a relation.
  • Loading branch information
Liam Young committed Feb 28, 2023
1 parent 7d443d8 commit 7c8ba20
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions charmhelpers/contrib/openstack/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3445,3 +3445,25 @@ def validate(self):
dummy_op.update(self.op)
pool = ch_ceph.BasePool('dummy-service', op=dummy_op)
pool.validate()


class RemoteRestartContext(OSContextGenerator):
"""Process restart trigger."""

def __init__(self, relation_name):
"""
:param relation_name: Name of relation to look for restart trigger.
:type relation_name: str
"""
self.relation_name = relation_name

def __call__(self):
for rid in relation_ids(self.relation_name):
for unit in related_units(rid):
restart_uuid = relation_get(
attribute='restart-trigger',
rid=rid,
unit=unit)
if restart_uuid:
return {'restart_trigger': restart_uuid}
return {}
7 changes: 7 additions & 0 deletions tests/contrib/openstack/test_os_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4748,6 +4748,13 @@ def test_parse_ovs_use_veth(self, _bool_from_string):
ctx_object.parse_ovs_use_veth()
_bool_from_string.assert_called_with("Invalid")

def test_remote_restarts_context(self):
self.relation_ids.return_value = ['rid1']
self.related_units.return_value = ['nova-compute/0']
self.relation_get.return_value = '123456'
ctx_object = context.RemoteRestartContext(relation_name='nova-ceilometer')()
self.assertEqual(ctx_object, {'restart_trigger': '123456'})


class MockPCIDevice(object):
"""Simple wrapper to mock pci.PCINetDevice class"""
Expand Down

0 comments on commit 7c8ba20

Please sign in to comment.