Restart services when trigger from principle

Check to see if a restart trigger has been sent by the principle,
if it has then right the trigger uuid in to the neutron.conf to
trigger a service restart

Change-Id: I19649cb73dad94f4fe24412c0b8c37a28f30047d
Partial-Bug: 1571634
This commit is contained in:
Liam Young 2016-04-19 05:44:09 +00:00
parent 1dfe139242
commit 236bb562f1
4 changed files with 42 additions and 0 deletions

View File

@ -251,6 +251,20 @@ class SharedSecretContext(OSContextGenerator):
return ctxt return ctxt
class RemoteRestartContext(OSContextGenerator):
def __call__(self):
for rid in relation_ids('neutron-plugin'):
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 {}
class APIIdentityServiceContext(context.IdentityServiceContext): class APIIdentityServiceContext(context.IdentityServiceContext):
def __init__(self): def __init__(self):

View File

@ -114,6 +114,7 @@ BASE_RESOURCE_MAP = OrderedDict([
(NEUTRON_CONF, { (NEUTRON_CONF, {
'services': ['neutron-plugin-openvswitch-agent'], 'services': ['neutron-plugin-openvswitch-agent'],
'contexts': [neutron_ovs_context.OVSPluginContext(), 'contexts': [neutron_ovs_context.OVSPluginContext(),
neutron_ovs_context.RemoteRestartContext(),
context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR), context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR),
context.ZeroMQContext(), context.ZeroMQContext(),
context.NotificationDriverContext()], context.NotificationDriverContext()],

View File

@ -3,6 +3,7 @@
# [ WARNING ] # [ WARNING ]
# Configuration file maintained by Juju. Local changes may be overwritten. # Configuration file maintained by Juju. Local changes may be overwritten.
# Config managed by neutron-openvswitch charm # Config managed by neutron-openvswitch charm
# Service restart triggered by principle using key: {{ restart_trigger }}
############################################################################### ###############################################################################
[DEFAULT] [DEFAULT]
verbose = {{ verbose }} verbose = {{ verbose }}

View File

@ -13,6 +13,9 @@ TO_PATCH = [
'network_get_primary_address', 'network_get_primary_address',
'glob', 'glob',
'PCINetDevices', 'PCINetDevices',
'relation_ids',
'relation_get',
'related_units',
] ]
@ -464,3 +467,26 @@ class TestDPDKDeviceContext(CharmTestCase):
'driver': 'uio_pci_generic' 'driver': 'uio_pci_generic'
}) })
self.config.assert_called_with('dpdk-driver') self.config.assert_called_with('dpdk-driver')
class TestRemoteRestartContext(CharmTestCase):
def setUp(self):
super(TestRemoteRestartContext, self).setUp(context,
TO_PATCH)
self.config.side_effect = self.test_config.get
def test_restart_trigger_present(self):
self.relation_ids.return_value = ['rid1']
self.related_units.return_value = ['nova-compute/0']
self.relation_get.return_value = '8f73-f3adb96a90d8'
self.assertEquals(
context.RemoteRestartContext()(),
{'restart_trigger': '8f73-f3adb96a90d8'}
)
def test_restart_trigger_absent(self):
self.relation_ids.return_value = ['rid1']
self.related_units.return_value = ['nova-compute/0']
self.relation_get.return_value = None
self.assertEquals(context.RemoteRestartContext()(), {})