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:
parent
97a80fe777
commit
a92b6fb881
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ bin
|
|||||||
tags
|
tags
|
||||||
*.sw[nop]
|
*.sw[nop]
|
||||||
*.pyc
|
*.pyc
|
||||||
|
.unit-state.db
|
||||||
|
1
hooks/neutron-control-relation-broken
Symbolic link
1
hooks/neutron-control-relation-broken
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
neutron_ovs_hooks.py
|
1
hooks/neutron-control-relation-changed
Symbolic link
1
hooks/neutron-control-relation-changed
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
neutron_ovs_hooks.py
|
1
hooks/neutron-control-relation-departed
Symbolic link
1
hooks/neutron-control-relation-departed
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
neutron_ovs_hooks.py
|
1
hooks/neutron-control-relation-joined
Symbolic link
1
hooks/neutron-control-relation-joined
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
neutron_ovs_hooks.py
|
@ -268,16 +268,29 @@ class SharedSecretContext(OSContextGenerator):
|
|||||||
|
|
||||||
class RemoteRestartContext(OSContextGenerator):
|
class RemoteRestartContext(OSContextGenerator):
|
||||||
|
|
||||||
|
def __init__(self, interfaces=None):
|
||||||
|
self.interfaces = interfaces or ['neutron-plugin']
|
||||||
|
|
||||||
def __call__(self):
|
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):
|
for unit in related_units(rid):
|
||||||
restart_uuid = relation_get(
|
remote_data = relation_get(
|
||||||
attribute='restart-trigger',
|
|
||||||
rid=rid,
|
rid=rid,
|
||||||
unit=unit)
|
unit=unit)
|
||||||
if restart_uuid:
|
for k, v in remote_data.items():
|
||||||
return {'restart_trigger': restart_uuid}
|
if k.startswith('restart-trigger'):
|
||||||
return {}
|
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):
|
class APIIdentityServiceContext(context.IdentityServiceContext):
|
||||||
|
@ -143,6 +143,12 @@ def zeromq_configuration_relation_changed():
|
|||||||
CONFIGS.write_all()
|
CONFIGS.write_all()
|
||||||
|
|
||||||
|
|
||||||
|
@hooks.hook('neutron-control-relation-changed')
|
||||||
|
@restart_on_change(restart_map(), stopstart=True)
|
||||||
|
def restart_check():
|
||||||
|
CONFIGS.write_all()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
hooks.execute(sys.argv)
|
hooks.execute(sys.argv)
|
||||||
|
@ -136,7 +136,8 @@ 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(),
|
neutron_ovs_context.RemoteRestartContext(
|
||||||
|
['neutron-plugin', 'neutron-control']),
|
||||||
context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR),
|
context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR),
|
||||||
context.ZeroMQContext(),
|
context.ZeroMQContext(),
|
||||||
context.NotificationDriverContext()],
|
context.NotificationDriverContext()],
|
||||||
|
@ -22,6 +22,8 @@ provides:
|
|||||||
neutron-plugin:
|
neutron-plugin:
|
||||||
interface: neutron-plugin
|
interface: neutron-plugin
|
||||||
scope: container
|
scope: container
|
||||||
|
neutron-control:
|
||||||
|
interface: service-control
|
||||||
requires:
|
requires:
|
||||||
amqp:
|
amqp:
|
||||||
interface: rabbitmq
|
interface: rabbitmq
|
||||||
@ -30,4 +32,3 @@ requires:
|
|||||||
zeromq-configuration:
|
zeromq-configuration:
|
||||||
interface: zeromq-configuration
|
interface: zeromq-configuration
|
||||||
scope: container
|
scope: container
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# [ WARNING ]
|
# [ WARNING ]
|
||||||
# Configuration file maintained by Juju. Local changes may be overwritten.
|
# Configuration file maintained by Juju. Local changes may be overwritten.
|
||||||
|
# {{ restart_trigger_dhcp }}
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
state_path = /var/lib/neutron
|
state_path = /var/lib/neutron
|
||||||
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
|
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# Metadata service seems to cache neutron api url from keystone so trigger
|
# Metadata service seems to cache neutron api url from keystone so trigger
|
||||||
# restart if it changes: {{ quantum_url }}
|
# restart if it changes: {{ quantum_url }}
|
||||||
|
# {{ restart_trigger_metadata }}
|
||||||
|
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
auth_url = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/v2.0
|
auth_url = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/v2.0
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# [ WARNING ]
|
# [ WARNING ]
|
||||||
# Configuration file maintained by Juju. Local changes may be overwritten.
|
# Configuration file maintained by Juju. Local changes may be overwritten.
|
||||||
|
# {{ restart_trigger_l3agent }}
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
|
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
|
||||||
agent_mode = {{ agent_mode }}
|
agent_mode = {{ agent_mode }}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# Metadata service seems to cache neutron api url from keystone so trigger
|
# Metadata service seems to cache neutron api url from keystone so trigger
|
||||||
# restart if it changes: {{ quantum_url }}
|
# restart if it changes: {{ quantum_url }}
|
||||||
|
# {{ restart_trigger_metadata }}
|
||||||
|
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
auth_url = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/v2.0
|
auth_url = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/v2.0
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
# icehouse
|
# kilo
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# [ 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 }}
|
# Service restart triggered by remote application: {{ restart_trigger }}
|
||||||
|
# {{ restart_trigger_neutron }}
|
||||||
###############################################################################
|
###############################################################################
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
verbose = {{ verbose }}
|
verbose = {{ verbose }}
|
||||||
|
@ -491,14 +491,54 @@ class TestRemoteRestartContext(CharmTestCase):
|
|||||||
def test_restart_trigger_present(self):
|
def test_restart_trigger_present(self):
|
||||||
self.relation_ids.return_value = ['rid1']
|
self.relation_ids.return_value = ['rid1']
|
||||||
self.related_units.return_value = ['nova-compute/0']
|
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(
|
self.assertEquals(
|
||||||
context.RemoteRestartContext()(),
|
context.RemoteRestartContext()(),
|
||||||
{'restart_trigger': '8f73-f3adb96a90d8'}
|
{'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):
|
def test_restart_trigger_absent(self):
|
||||||
self.relation_ids.return_value = ['rid1']
|
self.relation_ids.return_value = ['rid1']
|
||||||
self.related_units.return_value = ['nova-compute/0']
|
self.related_units.return_value = ['nova-compute/0']
|
||||||
self.relation_get.return_value = None
|
self.relation_get.return_value = {}
|
||||||
self.assertEquals(context.RemoteRestartContext()(), {})
|
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'}
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user