Add neutron-control interface

Add neutron-control interface to allow charms to send triggers to
restart neutron services managed by this charm

Change-Id: I0e44f7cab99db4fb9b5d2764859e16b30705e6fe
This commit is contained in:
Liam Young 2016-08-31 07:45:28 +00:00
parent 97a80fe777
commit a92b6fb881
15 changed files with 85 additions and 12 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ bin
tags
*.sw[nop]
*.pyc
.unit-state.db

View File

@ -0,0 +1 @@
neutron_ovs_hooks.py

View File

@ -0,0 +1 @@
neutron_ovs_hooks.py

View File

@ -0,0 +1 @@
neutron_ovs_hooks.py

View File

@ -0,0 +1 @@
neutron_ovs_hooks.py

View File

@ -268,16 +268,29 @@ class SharedSecretContext(OSContextGenerator):
class RemoteRestartContext(OSContextGenerator):
def __init__(self, interfaces=None):
self.interfaces = interfaces or ['neutron-plugin']
def __call__(self):
for rid in relation_ids('neutron-plugin'):
rids = []
for interface in self.interfaces:
rids.extend(relation_ids(interface))
ctxt = {}
for rid in rids:
for unit in related_units(rid):
restart_uuid = relation_get(
attribute='restart-trigger',
remote_data = relation_get(
rid=rid,
unit=unit)
if restart_uuid:
return {'restart_trigger': restart_uuid}
return {}
for k, v in remote_data.items():
if k.startswith('restart-trigger'):
restart_key = k.replace('-', '_')
try:
ctxt[restart_key].append(v)
except KeyError:
ctxt[restart_key] = [v]
for restart_key in ctxt.keys():
ctxt[restart_key] = '-'.join(sorted(ctxt[restart_key]))
return ctxt
class APIIdentityServiceContext(context.IdentityServiceContext):

View File

@ -143,6 +143,12 @@ def zeromq_configuration_relation_changed():
CONFIGS.write_all()
@hooks.hook('neutron-control-relation-changed')
@restart_on_change(restart_map(), stopstart=True)
def restart_check():
CONFIGS.write_all()
def main():
try:
hooks.execute(sys.argv)

View File

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

View File

@ -22,6 +22,8 @@ provides:
neutron-plugin:
interface: neutron-plugin
scope: container
neutron-control:
interface: service-control
requires:
amqp:
interface: rabbitmq
@ -30,4 +32,3 @@ requires:
zeromq-configuration:
interface: zeromq-configuration
scope: container

View File

@ -1,7 +1,9 @@
###############################################################################
# [ WARNING ]
# Configuration file maintained by Juju. Local changes may be overwritten.
# {{ restart_trigger_dhcp }}
###############################################################################
[DEFAULT]
state_path = /var/lib/neutron
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver

View File

@ -4,6 +4,7 @@
###############################################################################
# Metadata service seems to cache neutron api url from keystone so trigger
# restart if it changes: {{ quantum_url }}
# {{ restart_trigger_metadata }}
[DEFAULT]
auth_url = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/v2.0

View File

@ -1,7 +1,9 @@
###############################################################################
# [ WARNING ]
# Configuration file maintained by Juju. Local changes may be overwritten.
# {{ restart_trigger_l3agent }}
###############################################################################
[DEFAULT]
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
agent_mode = {{ agent_mode }}

View File

@ -4,6 +4,7 @@
###############################################################################
# Metadata service seems to cache neutron api url from keystone so trigger
# restart if it changes: {{ quantum_url }}
# {{ restart_trigger_metadata }}
[DEFAULT]
auth_url = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/v2.0

View File

@ -1,9 +1,10 @@
# icehouse
# kilo
###############################################################################
# [ WARNING ]
# Configuration file maintained by Juju. Local changes may be overwritten.
# Config managed by neutron-openvswitch charm
# Service restart triggered by principle using key: {{ restart_trigger }}
# Service restart triggered by remote application: {{ restart_trigger }}
# {{ restart_trigger_neutron }}
###############################################################################
[DEFAULT]
verbose = {{ verbose }}

View File

@ -491,14 +491,54 @@ class TestRemoteRestartContext(CharmTestCase):
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.relation_get.return_value = {
'restart-trigger': '8f73-f3adb96a90d8',
}
self.assertEquals(
context.RemoteRestartContext()(),
{'restart_trigger': '8f73-f3adb96a90d8'}
)
self.relation_ids.assert_called_with('neutron-plugin')
def test_restart_trigger_present_alt_relation(self):
self.relation_ids.return_value = ['rid1']
self.related_units.return_value = ['nova-compute/0']
self.relation_get.return_value = {
'restart-trigger': '8f73-f3adb96a90d8',
}
self.assertEquals(
context.RemoteRestartContext(['neutron-control'])(),
{'restart_trigger': '8f73-f3adb96a90d8'}
)
self.relation_ids.assert_called_with('neutron-control')
def test_restart_trigger_present_multi_relation(self):
self.relation_ids.return_value = ['rid1']
self.related_units.return_value = ['nova-compute/0']
ids = [
{'restart-trigger': '8f73'},
{'restart-trigger': '2ac3'}]
self.relation_get.side_effect = lambda rid, unit: ids.pop()
self.assertEquals(
context.RemoteRestartContext(
['neutron-plugin', 'neutron-control'])(),
{'restart_trigger': '2ac3-8f73'}
)
self.relation_ids.assert_called_with('neutron-control')
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.relation_get.return_value = {}
self.assertEquals(context.RemoteRestartContext()(), {})
def test_restart_trigger_service(self):
self.relation_ids.return_value = ['rid1']
self.related_units.return_value = ['nova-compute/0']
self.relation_get.return_value = {
'restart-trigger-neutron': 'neutron-uuid',
}
self.assertEquals(
context.RemoteRestartContext()(),
{'restart_trigger_neutron': 'neutron-uuid'}
)