diff --git a/charmhelpers/contrib/openstack/context.py b/charmhelpers/contrib/openstack/context.py index d894b6a66..845317388 100644 --- a/charmhelpers/contrib/openstack/context.py +++ b/charmhelpers/contrib/openstack/context.py @@ -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 {} diff --git a/tests/contrib/openstack/test_os_contexts.py b/tests/contrib/openstack/test_os_contexts.py index e90764b2e..6cb0ec65a 100644 --- a/tests/contrib/openstack/test_os_contexts.py +++ b/tests/contrib/openstack/test_os_contexts.py @@ -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"""