Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RemoteRestartContext #755

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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