From 6a0d74f687c5e0a53dbe2b03b7f0f536586f631b Mon Sep 17 00:00:00 2001 From: Liam Young Date: Fri, 6 Jun 2014 11:11:53 +0000 Subject: [PATCH 01/10] Add support for plugins --- hooks/neutron-plugin-relation-changed | 1 + hooks/neutron-plugin-relation-departed | 1 + hooks/neutron-plugin-relation-joined | 1 + hooks/quantum_hooks.py | 11 +++++++++++ hooks/quantum_utils.py | 14 +++++++++++++- metadata.yaml | 3 +++ 6 files changed, 30 insertions(+), 1 deletion(-) create mode 120000 hooks/neutron-plugin-relation-changed create mode 120000 hooks/neutron-plugin-relation-departed create mode 120000 hooks/neutron-plugin-relation-joined diff --git a/hooks/neutron-plugin-relation-changed b/hooks/neutron-plugin-relation-changed new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-relation-changed @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-relation-departed b/hooks/neutron-plugin-relation-departed new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-relation-departed @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-relation-joined b/hooks/neutron-plugin-relation-joined new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-relation-joined @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/quantum_hooks.py b/hooks/quantum_hooks.py index 8d0cac66..9fb11e46 100755 --- a/hooks/quantum_hooks.py +++ b/hooks/quantum_hooks.py @@ -1,5 +1,6 @@ #!/usr/bin/python +import uuid from base64 import b64decode from charmhelpers.core.hookenv import ( @@ -47,6 +48,8 @@ from quantum_utils import ( stop_services ) +from charmhelpers.contrib.openstack import context + hooks = Hooks() CONFIGS = register_configs() @@ -175,6 +178,14 @@ def cluster_departed(): def stop(): stop_services() +@hooks.hook('neutron-plugin-relation-joined') +def neutron_plugin_relation_joined(rid=None, remote_restart=False): + amqp_ctxt = context.AMQPContext() + rel_settings = amqp_ctxt() + if remote_restart: + rel_settings['restart_trigger'] = str(uuid.uuid4()) + relation_set(relation_id=rid, **rel_settings) + if __name__ == '__main__': try: hooks.execute(sys.argv) diff --git a/hooks/quantum_utils.py b/hooks/quantum_utils.py index 0da00f79..6418a3f0 100644 --- a/hooks/quantum_utils.py +++ b/hooks/quantum_utils.py @@ -7,7 +7,8 @@ from charmhelpers.core.hookenv import ( log, config, relations_of_type, - unit_private_ip + unit_private_ip, + is_relation_made ) from charmhelpers.fetch import ( apt_upgrade, @@ -340,6 +341,17 @@ def register_configs(): if drop_config in CONFIG_FILES[name][plugin]: CONFIG_FILES[name][plugin].pop(drop_config) + # Hardcoded list of configs which are managed by plugin subordinate if + # available. Any new plugin conf should go into a subordinate list so + # this list should never change + if is_relation_made('neutron-plugin'): + drop_configs = [NEUTRON_ML2_PLUGIN_CONF, NEUTRON_OVS_PLUGIN_CONF, + NEUTRON_CONF, NEUTRON_NVP_PLUGIN_CONF] + for l_plugin in NEUTRON_PLUGIN_CONF: + for drop_config in drop_configs: + if drop_config in CONFIG_FILES['neutron'][l_plugin]: + CONFIG_FILES[name][l_plugin].pop(drop_config) + for conf in CONFIG_FILES[name][plugin]: configs.register(conf, CONFIG_FILES[name][plugin][conf]['hook_contexts']) diff --git a/metadata.yaml b/metadata.yaml index 637f8953..2b407034 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -25,6 +25,9 @@ requires: interface: pgsql amqp: interface: rabbitmq + neutron-plugin: + interface: neutron-plugin + scope: container peers: cluster: interface: quantum-gateway-ha From acc3b8f57702f782c778e848d848a48f73eb0523 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Fri, 6 Jun 2014 12:24:09 +0000 Subject: [PATCH 02/10] Switch from using a plugin to baking an nova amqp relation into the charm --- .../charmhelpers/contrib/openstack/context.py | 5 +++-- hooks/neutron-plugin-relation-changed | 1 - hooks/neutron-plugin-relation-departed | 1 - hooks/neutron-plugin-relation-joined | 1 - hooks/quantum_hooks.py | 11 ---------- hooks/quantum_utils.py | 21 +++++++------------ metadata.yaml | 5 ++--- 7 files changed, 12 insertions(+), 33 deletions(-) delete mode 120000 hooks/neutron-plugin-relation-changed delete mode 120000 hooks/neutron-plugin-relation-departed delete mode 120000 hooks/neutron-plugin-relation-joined diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index 474d51ea..cd286ef7 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -245,8 +245,9 @@ class IdentityServiceContext(OSContextGenerator): class AMQPContext(OSContextGenerator): interfaces = ['amqp'] - def __init__(self, ssl_dir=None): + def __init__(self, rel_name='amqp', ssl_dir=None): self.ssl_dir = ssl_dir + self.rel_name = rel_name def __call__(self): log('Generating template context for amqp') @@ -259,7 +260,7 @@ class AMQPContext(OSContextGenerator): 'Missing required charm config options: %s.' % e) raise OSContextError ctxt = {} - for rid in relation_ids('amqp'): + for rid in relation_ids(self.rel_name): ha_vip_only = False for unit in related_units(rid): if relation_get('clustered', rid=rid, unit=unit): diff --git a/hooks/neutron-plugin-relation-changed b/hooks/neutron-plugin-relation-changed deleted file mode 120000 index 9a2da58e..00000000 --- a/hooks/neutron-plugin-relation-changed +++ /dev/null @@ -1 +0,0 @@ -quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-relation-departed b/hooks/neutron-plugin-relation-departed deleted file mode 120000 index 9a2da58e..00000000 --- a/hooks/neutron-plugin-relation-departed +++ /dev/null @@ -1 +0,0 @@ -quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-relation-joined b/hooks/neutron-plugin-relation-joined deleted file mode 120000 index 9a2da58e..00000000 --- a/hooks/neutron-plugin-relation-joined +++ /dev/null @@ -1 +0,0 @@ -quantum_hooks.py \ No newline at end of file diff --git a/hooks/quantum_hooks.py b/hooks/quantum_hooks.py index 9fb11e46..8d0cac66 100755 --- a/hooks/quantum_hooks.py +++ b/hooks/quantum_hooks.py @@ -1,6 +1,5 @@ #!/usr/bin/python -import uuid from base64 import b64decode from charmhelpers.core.hookenv import ( @@ -48,8 +47,6 @@ from quantum_utils import ( stop_services ) -from charmhelpers.contrib.openstack import context - hooks = Hooks() CONFIGS = register_configs() @@ -178,14 +175,6 @@ def cluster_departed(): def stop(): stop_services() -@hooks.hook('neutron-plugin-relation-joined') -def neutron_plugin_relation_joined(rid=None, remote_restart=False): - amqp_ctxt = context.AMQPContext() - rel_settings = amqp_ctxt() - if remote_restart: - rel_settings['restart_trigger'] = str(uuid.uuid4()) - relation_set(relation_id=rid, **rel_settings) - if __name__ == '__main__': try: hooks.execute(sys.argv) diff --git a/hooks/quantum_utils.py b/hooks/quantum_utils.py index 6418a3f0..0758cb33 100644 --- a/hooks/quantum_utils.py +++ b/hooks/quantum_utils.py @@ -8,7 +8,7 @@ from charmhelpers.core.hookenv import ( config, relations_of_type, unit_private_ip, - is_relation_made + is_relation_made, ) from charmhelpers.fetch import ( apt_upgrade, @@ -177,8 +177,7 @@ NOVA_CONF = "/etc/nova/nova.conf" NOVA_CONFIG_FILES = { NOVA_CONF: { - 'hook_contexts': [context.AMQPContext(ssl_dir=NOVA_CONF_DIR), - context.SharedDBContext(ssl_dir=NOVA_CONF_DIR), + 'hook_contexts': [context.SharedDBContext(ssl_dir=NOVA_CONF_DIR), context.PostgresqlDBContext(), NetworkServiceContext(), QuantumGatewayContext(), @@ -341,17 +340,11 @@ def register_configs(): if drop_config in CONFIG_FILES[name][plugin]: CONFIG_FILES[name][plugin].pop(drop_config) - # Hardcoded list of configs which are managed by plugin subordinate if - # available. Any new plugin conf should go into a subordinate list so - # this list should never change - if is_relation_made('neutron-plugin'): - drop_configs = [NEUTRON_ML2_PLUGIN_CONF, NEUTRON_OVS_PLUGIN_CONF, - NEUTRON_CONF, NEUTRON_NVP_PLUGIN_CONF] - for l_plugin in NEUTRON_PLUGIN_CONF: - for drop_config in drop_configs: - if drop_config in CONFIG_FILES['neutron'][l_plugin]: - CONFIG_FILES[name][l_plugin].pop(drop_config) - + if is_relation_made('amqp-nova'): + amqp_nova_ctxt = context.AMQPContext(ssl_dir=NOVA_CONF_DIR, rel_name='amqp-nova') + else: + amqp_nova_ctxt = context.AMQPContext(ssl_dir=NOVA_CONF_DIR, rel_name='amqp') + CONFIG_FILES[name][plugin][NOVA_CONF]['hook_contexts'].append(amqp_nova_ctxt) for conf in CONFIG_FILES[name][plugin]: configs.register(conf, CONFIG_FILES[name][plugin][conf]['hook_contexts']) diff --git a/metadata.yaml b/metadata.yaml index 2b407034..c15d03fd 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -25,9 +25,8 @@ requires: interface: pgsql amqp: interface: rabbitmq - neutron-plugin: - interface: neutron-plugin - scope: container + amqp-nova: + interface: rabbitmq peers: cluster: interface: quantum-gateway-ha From ec3344fbfa908871a68e02366a72eff39fb9e536 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Fri, 6 Jun 2014 12:37:09 +0000 Subject: [PATCH 03/10] Add ability for user to set rabbit username and vhost for amqp-nova relation --- config.yaml | 8 ++++++++ hooks/charmhelpers/contrib/openstack/context.py | 13 ++++++++++--- hooks/quantum_utils.py | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config.yaml b/config.yaml index 814aa1ec..a12bdbd3 100644 --- a/config.yaml +++ b/config.yaml @@ -50,6 +50,14 @@ options: type: string description: RabbitMQ Virtual Host default: openstack + nova-rabbit-user: + type: string + description: RabbitMQ Nova user + default: nova + nova-rabbit-vhost: + type: string + description: RabbitMQ Nova Virtual Host + default: openstack debug: default: False type: boolean diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index cd286ef7..7f8d2703 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -245,16 +245,23 @@ class IdentityServiceContext(OSContextGenerator): class AMQPContext(OSContextGenerator): interfaces = ['amqp'] - def __init__(self, rel_name='amqp', ssl_dir=None): + def __init__(self, rel_name='amqp', relation_prefix=None, ssl_dir=None): self.ssl_dir = ssl_dir self.rel_name = rel_name + self.relation_prefix = relation_prefix def __call__(self): log('Generating template context for amqp') conf = config() + user_setting = 'rabbit-user' + vhost_setting = 'rabbit-vhost' + if self.relation_prefix: + user_setting = self.relation_prefix + '-rabbit-user' + vhost_setting = self.relation_prefix + '-rabbit-vhost' + try: - username = conf['rabbit-user'] - vhost = conf['rabbit-vhost'] + username = conf[user_setting] + vhost = conf[vhost_setting] except KeyError as e: log('Could not generate shared_db context. ' 'Missing required charm config options: %s.' % e) diff --git a/hooks/quantum_utils.py b/hooks/quantum_utils.py index 0758cb33..2c6fc92e 100644 --- a/hooks/quantum_utils.py +++ b/hooks/quantum_utils.py @@ -341,7 +341,7 @@ def register_configs(): CONFIG_FILES[name][plugin].pop(drop_config) if is_relation_made('amqp-nova'): - amqp_nova_ctxt = context.AMQPContext(ssl_dir=NOVA_CONF_DIR, rel_name='amqp-nova') + amqp_nova_ctxt = context.AMQPContext(ssl_dir=NOVA_CONF_DIR, rel_name='amqp-nova', relation_prefix='nova') else: amqp_nova_ctxt = context.AMQPContext(ssl_dir=NOVA_CONF_DIR, rel_name='amqp') CONFIG_FILES[name][plugin][NOVA_CONF]['hook_contexts'].append(amqp_nova_ctxt) From 55a942f6bbcd1f3eac7757f04110a0adba56e02c Mon Sep 17 00:00:00 2001 From: Liam Young Date: Fri, 6 Jun 2014 13:02:28 +0000 Subject: [PATCH 04/10] Add hooks for amqp-nova relation --- hooks/amqp-nova-relation-changed | 1 + hooks/amqp-nova-relation-departed | 1 + hooks/amqp-nova-relation-joined | 1 + hooks/quantum_hooks.py | 17 +++++++++++++++++ 4 files changed, 20 insertions(+) create mode 120000 hooks/amqp-nova-relation-changed create mode 120000 hooks/amqp-nova-relation-departed create mode 120000 hooks/amqp-nova-relation-joined diff --git a/hooks/amqp-nova-relation-changed b/hooks/amqp-nova-relation-changed new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/amqp-nova-relation-changed @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/amqp-nova-relation-departed b/hooks/amqp-nova-relation-departed new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/amqp-nova-relation-departed @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/amqp-nova-relation-joined b/hooks/amqp-nova-relation-joined new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/amqp-nova-relation-joined @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/quantum_hooks.py b/hooks/quantum_hooks.py index 8d0cac66..72bc1762 100755 --- a/hooks/quantum_hooks.py +++ b/hooks/quantum_hooks.py @@ -83,6 +83,8 @@ def config_changed(): pgsql_db_joined(relation_id=r_id) for r_id in relation_ids('amqp'): amqp_joined(relation_id=r_id) + for r_id in relation_ids('amqp-nova'): + amqp_nova_joined(relation_id=r_id) if valid_plugin(): CONFIGS.write_all() configure_ovs() @@ -123,6 +125,12 @@ def pgsql_db_joined(relation_id=None): relation_id=relation_id) +@hooks.hook('amqp-nova-relation-joined') +def amqp_nova_joined(relation_id=None): + relation_set(relation_id=relation_id, + username=config('nova-rabbit-user'), + vhost=config('nova-rabbit-vhost')) + @hooks.hook('amqp-relation-joined') def amqp_joined(relation_id=None): relation_set(relation_id=relation_id, @@ -130,6 +138,14 @@ def amqp_joined(relation_id=None): vhost=config('rabbit-vhost')) +@hooks.hook('amqp-nova-relation-departed') +@restart_on_change(restart_map()) +def amqp_nova_departed(): + if 'amqp-nova' not in CONFIGS.complete_contexts(): + log('amqp relation incomplete. Peer not ready?') + return + CONFIGS.write_all() + @hooks.hook('amqp-relation-departed') @restart_on_change(restart_map()) def amqp_departed(): @@ -142,6 +158,7 @@ def amqp_departed(): @hooks.hook('shared-db-relation-changed', 'pgsql-db-relation-changed', 'amqp-relation-changed', + 'amqp-nova-relation-changed', 'cluster-relation-changed', 'cluster-relation-joined') @restart_on_change(restart_map()) From 34d230c47617bce3b67cdd1f6d0a0e8410356e92 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 9 Jun 2014 11:30:01 +0000 Subject: [PATCH 05/10] Fix for amqp comple context when rel name != amqp --- hooks/charmhelpers/contrib/openstack/context.py | 2 +- hooks/quantum_hooks.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index 7f8d2703..dcb8f5bc 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -243,12 +243,12 @@ class IdentityServiceContext(OSContextGenerator): class AMQPContext(OSContextGenerator): - interfaces = ['amqp'] def __init__(self, rel_name='amqp', relation_prefix=None, ssl_dir=None): self.ssl_dir = ssl_dir self.rel_name = rel_name self.relation_prefix = relation_prefix + self.interfaces = [rel_name] def __call__(self): log('Generating template context for amqp') diff --git a/hooks/quantum_hooks.py b/hooks/quantum_hooks.py index 72bc1762..74c44c1e 100755 --- a/hooks/quantum_hooks.py +++ b/hooks/quantum_hooks.py @@ -138,9 +138,10 @@ def amqp_joined(relation_id=None): vhost=config('rabbit-vhost')) +@hooks.hook('amqp-nova-relation-changed') @hooks.hook('amqp-nova-relation-departed') @restart_on_change(restart_map()) -def amqp_nova_departed(): +def amqp_nova_changed(): if 'amqp-nova' not in CONFIGS.complete_contexts(): log('amqp relation incomplete. Peer not ready?') return From de90ebb4f4c8ed8528ad8f13b1134c90f9f67ad7 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 9 Jun 2014 15:55:22 +0000 Subject: [PATCH 06/10] Add neutron plugin support --- hooks/neutron-plugin-relation-broken | 1 + hooks/neutron-plugin-relation-changed | 1 + hooks/neutron-plugin-relation-departed | 1 + hooks/neutron-plugin-relation-joined | 1 + hooks/quantum_contexts.py | 6 ++++-- hooks/quantum_hooks.py | 16 ++++++++++++++-- hooks/quantum_utils.py | 6 ++++++ metadata.yaml | 3 +++ templates/icehouse/neutron.conf | 11 +++++++++-- 9 files changed, 40 insertions(+), 6 deletions(-) create mode 120000 hooks/neutron-plugin-relation-broken create mode 120000 hooks/neutron-plugin-relation-changed create mode 120000 hooks/neutron-plugin-relation-departed create mode 120000 hooks/neutron-plugin-relation-joined diff --git a/hooks/neutron-plugin-relation-broken b/hooks/neutron-plugin-relation-broken new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-relation-broken @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-relation-changed b/hooks/neutron-plugin-relation-changed new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-relation-changed @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-relation-departed b/hooks/neutron-plugin-relation-departed new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-relation-departed @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-relation-joined b/hooks/neutron-plugin-relation-joined new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-relation-joined @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/quantum_contexts.py b/hooks/quantum_contexts.py index 5aa472fd..a840ecad 100644 --- a/hooks/quantum_contexts.py +++ b/hooks/quantum_contexts.py @@ -12,7 +12,8 @@ from charmhelpers.core.hookenv import ( related_units, relation_get, unit_get, - cached + cached, + is_relation_made, ) from charmhelpers.fetch import ( apt_install, @@ -154,7 +155,8 @@ class QuantumGatewayContext(OSContextGenerator): 'plugin': config('plugin'), 'debug': config('debug'), 'verbose': config('verbose'), - 'instance_mtu': config('instance-mtu') + 'instance_mtu': config('instance-mtu'), + 'neutron_plugin_present': is_relation_made('neutron-plugin'), } return ctxt diff --git a/hooks/quantum_hooks.py b/hooks/quantum_hooks.py index 74c44c1e..8c6495e6 100755 --- a/hooks/quantum_hooks.py +++ b/hooks/quantum_hooks.py @@ -1,7 +1,7 @@ #!/usr/bin/python from base64 import b64decode - +import uuid from charmhelpers.core.hookenv import ( log, ERROR, WARNING, config, @@ -44,7 +44,8 @@ from quantum_utils import ( valid_plugin, configure_ovs, reassign_agent_resources, - stop_services + stop_services, + NEUTRON_CONF, ) hooks = Hooks() @@ -187,6 +188,17 @@ def cluster_departed(): reassign_agent_resources() CONFIGS.write_all() +@hooks.hook('neutron-plugin-relation-joined') +def neutron_plugin_relation_joined(rid=None, remote_restart=False): + rel_settings = {} + rel_settings['restart_trigger'] = str(uuid.uuid4()) + relation_set(relation_id=rid, **rel_settings) + +@restart_on_change(restart_map()) +@hooks.hook('neutron-plugin-relation-changed') +def neutron_plugin_relation_changed(): + CONFIGS.write(NEUTRON_CONF) + @hooks.hook('cluster-relation-broken') @hooks.hook('stop') diff --git a/hooks/quantum_utils.py b/hooks/quantum_utils.py index 2c6fc92e..85c9c16e 100644 --- a/hooks/quantum_utils.py +++ b/hooks/quantum_utils.py @@ -345,6 +345,12 @@ def register_configs(): else: amqp_nova_ctxt = context.AMQPContext(ssl_dir=NOVA_CONF_DIR, rel_name='amqp') CONFIG_FILES[name][plugin][NOVA_CONF]['hook_contexts'].append(amqp_nova_ctxt) + if is_relation_made('neutron-plugin'): + CONFIG_FILES[name][plugin][NEUTRON_CONF]['hook_contexts'].append(context.SubordinateConfigContext(interface='neutron-plugin', service='neutron', config_file=NEUTRON_CONF)) + # Files which are managed by the plugin + ceded_list = ['NEUTRON_OVS_PLUGIN_CONF', 'NEUTRON_ML2_PLUGIN_CONF'] + for conf in ceded_list: + del CONFIG_FILES[name][plugin][conf] for conf in CONFIG_FILES[name][plugin]: configs.register(conf, CONFIG_FILES[name][plugin][conf]['hook_contexts']) diff --git a/metadata.yaml b/metadata.yaml index c15d03fd..a7670842 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -27,6 +27,9 @@ requires: interface: rabbitmq amqp-nova: interface: rabbitmq + neutron-plugin: + interface: neutron-plugin + scope: container peers: cluster: interface: quantum-gateway-ha diff --git a/templates/icehouse/neutron.conf b/templates/icehouse/neutron.conf index 6db71eb4..8c922fd0 100644 --- a/templates/icehouse/neutron.conf +++ b/templates/icehouse/neutron.conf @@ -6,10 +6,17 @@ verbose = {{ verbose }} debug = {{ debug }} lock_path = /var/lock/neutron -core_plugin = {{ core_plugin }} +{% if neutron_plugin_present == 'False' -%} +core_plugin = {{ core_plugin }} +{% endif -%} {% include "parts/rabbitmq" %} control_exchange = neutron notification_driver = neutron.openstack.common.notifier.list_notifier list_notifier_drivers = neutron.openstack.common.notifier.rabbit_notifier +{% if sections and 'DEFAULT' in sections -%} +{% for key, value in sections['DEFAULT'] -%} +{{ key }} = {{ value }} +{% endfor -%} +{% endif -%} [agent] -root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf \ No newline at end of file +root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf From 6a1f4a7b6ddbb6500cab9c36b4b3d153aaa3fdae Mon Sep 17 00:00:00 2001 From: Liam Young Date: Tue, 10 Jun 2014 06:33:43 +0000 Subject: [PATCH 07/10] Fix bug when trying to delete configs from context which aren't there! --- hooks/quantum_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/quantum_utils.py b/hooks/quantum_utils.py index 85c9c16e..aa39a01b 100644 --- a/hooks/quantum_utils.py +++ b/hooks/quantum_utils.py @@ -350,7 +350,8 @@ def register_configs(): # Files which are managed by the plugin ceded_list = ['NEUTRON_OVS_PLUGIN_CONF', 'NEUTRON_ML2_PLUGIN_CONF'] for conf in ceded_list: - del CONFIG_FILES[name][plugin][conf] + if conf in CONFIG_FILES[name][plugin]: + del CONFIG_FILES[name][plugin][conf] for conf in CONFIG_FILES[name][plugin]: configs.register(conf, CONFIG_FILES[name][plugin][conf]['hook_contexts']) From e8363fbbc700c6e2bc7a7d75f3374186e4ae5102 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Wed, 11 Jun 2014 09:30:31 +0000 Subject: [PATCH 08/10] Remove plugin support as neutron-plugin info is going to stay baked in the charm --- hooks/neutron-plugin-relation-broken | 1 - hooks/neutron-plugin-relation-changed | 1 - hooks/neutron-plugin-relation-departed | 1 - hooks/neutron-plugin-relation-joined | 1 - hooks/quantum_contexts.py | 6 ++---- hooks/quantum_hooks.py | 16 ++-------------- hooks/quantum_utils.py | 7 ------- metadata.yaml | 3 --- templates/icehouse/neutron.conf | 11 ++--------- 9 files changed, 6 insertions(+), 41 deletions(-) delete mode 120000 hooks/neutron-plugin-relation-broken delete mode 120000 hooks/neutron-plugin-relation-changed delete mode 120000 hooks/neutron-plugin-relation-departed delete mode 120000 hooks/neutron-plugin-relation-joined diff --git a/hooks/neutron-plugin-relation-broken b/hooks/neutron-plugin-relation-broken deleted file mode 120000 index 9a2da58e..00000000 --- a/hooks/neutron-plugin-relation-broken +++ /dev/null @@ -1 +0,0 @@ -quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-relation-changed b/hooks/neutron-plugin-relation-changed deleted file mode 120000 index 9a2da58e..00000000 --- a/hooks/neutron-plugin-relation-changed +++ /dev/null @@ -1 +0,0 @@ -quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-relation-departed b/hooks/neutron-plugin-relation-departed deleted file mode 120000 index 9a2da58e..00000000 --- a/hooks/neutron-plugin-relation-departed +++ /dev/null @@ -1 +0,0 @@ -quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-relation-joined b/hooks/neutron-plugin-relation-joined deleted file mode 120000 index 9a2da58e..00000000 --- a/hooks/neutron-plugin-relation-joined +++ /dev/null @@ -1 +0,0 @@ -quantum_hooks.py \ No newline at end of file diff --git a/hooks/quantum_contexts.py b/hooks/quantum_contexts.py index a840ecad..5aa472fd 100644 --- a/hooks/quantum_contexts.py +++ b/hooks/quantum_contexts.py @@ -12,8 +12,7 @@ from charmhelpers.core.hookenv import ( related_units, relation_get, unit_get, - cached, - is_relation_made, + cached ) from charmhelpers.fetch import ( apt_install, @@ -155,8 +154,7 @@ class QuantumGatewayContext(OSContextGenerator): 'plugin': config('plugin'), 'debug': config('debug'), 'verbose': config('verbose'), - 'instance_mtu': config('instance-mtu'), - 'neutron_plugin_present': is_relation_made('neutron-plugin'), + 'instance_mtu': config('instance-mtu') } return ctxt diff --git a/hooks/quantum_hooks.py b/hooks/quantum_hooks.py index 8c6495e6..74c44c1e 100755 --- a/hooks/quantum_hooks.py +++ b/hooks/quantum_hooks.py @@ -1,7 +1,7 @@ #!/usr/bin/python from base64 import b64decode -import uuid + from charmhelpers.core.hookenv import ( log, ERROR, WARNING, config, @@ -44,8 +44,7 @@ from quantum_utils import ( valid_plugin, configure_ovs, reassign_agent_resources, - stop_services, - NEUTRON_CONF, + stop_services ) hooks = Hooks() @@ -188,17 +187,6 @@ def cluster_departed(): reassign_agent_resources() CONFIGS.write_all() -@hooks.hook('neutron-plugin-relation-joined') -def neutron_plugin_relation_joined(rid=None, remote_restart=False): - rel_settings = {} - rel_settings['restart_trigger'] = str(uuid.uuid4()) - relation_set(relation_id=rid, **rel_settings) - -@restart_on_change(restart_map()) -@hooks.hook('neutron-plugin-relation-changed') -def neutron_plugin_relation_changed(): - CONFIGS.write(NEUTRON_CONF) - @hooks.hook('cluster-relation-broken') @hooks.hook('stop') diff --git a/hooks/quantum_utils.py b/hooks/quantum_utils.py index aa39a01b..2c6fc92e 100644 --- a/hooks/quantum_utils.py +++ b/hooks/quantum_utils.py @@ -345,13 +345,6 @@ def register_configs(): else: amqp_nova_ctxt = context.AMQPContext(ssl_dir=NOVA_CONF_DIR, rel_name='amqp') CONFIG_FILES[name][plugin][NOVA_CONF]['hook_contexts'].append(amqp_nova_ctxt) - if is_relation_made('neutron-plugin'): - CONFIG_FILES[name][plugin][NEUTRON_CONF]['hook_contexts'].append(context.SubordinateConfigContext(interface='neutron-plugin', service='neutron', config_file=NEUTRON_CONF)) - # Files which are managed by the plugin - ceded_list = ['NEUTRON_OVS_PLUGIN_CONF', 'NEUTRON_ML2_PLUGIN_CONF'] - for conf in ceded_list: - if conf in CONFIG_FILES[name][plugin]: - del CONFIG_FILES[name][plugin][conf] for conf in CONFIG_FILES[name][plugin]: configs.register(conf, CONFIG_FILES[name][plugin][conf]['hook_contexts']) diff --git a/metadata.yaml b/metadata.yaml index a7670842..c15d03fd 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -27,9 +27,6 @@ requires: interface: rabbitmq amqp-nova: interface: rabbitmq - neutron-plugin: - interface: neutron-plugin - scope: container peers: cluster: interface: quantum-gateway-ha diff --git a/templates/icehouse/neutron.conf b/templates/icehouse/neutron.conf index 8c922fd0..6db71eb4 100644 --- a/templates/icehouse/neutron.conf +++ b/templates/icehouse/neutron.conf @@ -6,17 +6,10 @@ verbose = {{ verbose }} debug = {{ debug }} lock_path = /var/lock/neutron -{% if neutron_plugin_present == 'False' -%} -core_plugin = {{ core_plugin }} -{% endif -%} +core_plugin = {{ core_plugin }} {% include "parts/rabbitmq" %} control_exchange = neutron notification_driver = neutron.openstack.common.notifier.list_notifier list_notifier_drivers = neutron.openstack.common.notifier.rabbit_notifier -{% if sections and 'DEFAULT' in sections -%} -{% for key, value in sections['DEFAULT'] -%} -{{ key }} = {{ value }} -{% endfor -%} -{% endif -%} [agent] -root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf +root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf \ No newline at end of file From 6b2a4bb3f458cbf6658783b8567f56f80a676ca5 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 19 Jun 2014 13:57:55 +0100 Subject: [PATCH 09/10] Updated unit tests --- hooks/quantum_hooks.py | 3 +- unit_tests/test_quantum_hooks.py | 47 ++++++++++++++++++++++++++++++++ unit_tests/test_quantum_utils.py | 28 +++++++++++++++++-- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/hooks/quantum_hooks.py b/hooks/quantum_hooks.py index 74c44c1e..d3857b04 100755 --- a/hooks/quantum_hooks.py +++ b/hooks/quantum_hooks.py @@ -138,8 +138,8 @@ def amqp_joined(relation_id=None): vhost=config('rabbit-vhost')) -@hooks.hook('amqp-nova-relation-changed') @hooks.hook('amqp-nova-relation-departed') +@hooks.hook('amqp-nova-relation-changed') @restart_on_change(restart_map()) def amqp_nova_changed(): if 'amqp-nova' not in CONFIGS.complete_contexts(): @@ -159,7 +159,6 @@ def amqp_departed(): @hooks.hook('shared-db-relation-changed', 'pgsql-db-relation-changed', 'amqp-relation-changed', - 'amqp-nova-relation-changed', 'cluster-relation-changed', 'cluster-relation-joined') @restart_on_change(restart_map()) diff --git a/unit_tests/test_quantum_hooks.py b/unit_tests/test_quantum_hooks.py index 03e6777e..9ce7e5eb 100644 --- a/unit_tests/test_quantum_hooks.py +++ b/unit_tests/test_quantum_hooks.py @@ -93,6 +93,24 @@ class TestQuantumHooks(CharmTestCase): self.assertTrue(self.log.called) _exit.assert_called_with(1) + def test_config_changed(self): + def mock_relids(rel): + return ['relid'] + self.openstack_upgrade_available.return_value = True + self.valid_plugin.return_value = True + self.relation_ids.side_effect = mock_relids + _db_joined = self.patch('db_joined') + _pgsql_db_joined = self.patch('pgsql_db_joined') + _amqp_joined = self.patch('amqp_joined') + _amqp_nova_joined = self.patch('amqp_nova_joined') + self._call_hook('config-changed') + self.assertTrue(self.do_openstack_upgrade.called) + self.assertTrue(self.configure_ovs.called) + self.assertTrue(_db_joined.called) + self.assertTrue(_pgsql_db_joined.called) + self.assertTrue(_amqp_joined.called) + self.assertTrue(_amqp_nova_joined.called) + def test_config_changed_upgrade(self): self.openstack_upgrade_available.return_value = True self.valid_plugin.return_value = True @@ -164,6 +182,35 @@ class TestQuantumHooks(CharmTestCase): self._call_hook('amqp-relation-changed') self.assertTrue(self.CONFIGS.write_all.called) + def test_amqp_departed_no_rel(self): + self.CONFIGS.complete_contexts.return_value = [] + self._call_hook('amqp-relation-departed') + self.assertFalse(self.CONFIGS.write_all.called) + + def test_amqp_departed(self): + self.CONFIGS.complete_contexts.return_value = ['amqp'] + self._call_hook('amqp-relation-departed') + self.assertTrue(self.CONFIGS.write_all.called) + + + def test_amqp_nova_joined(self): + self._call_hook('amqp-nova-relation-joined') + self.relation_set.assert_called_with( + username='nova', + vhost='openstack', + relation_id=None + ) + + def test_amqp_nova_changed_no_rel(self): + self.CONFIGS.complete_contexts.return_value = [] + self._call_hook('amqp-nova-relation-changed') + self.assertFalse(self.CONFIGS.write_all.called) + + def test_amqp_nova_changed(self): + self.CONFIGS.complete_contexts.return_value = ['amqp-nova'] + self._call_hook('amqp-nova-relation-changed') + self.assertTrue(self.CONFIGS.write_all.called) + def test_shared_db_changed(self): self._call_hook('shared-db-relation-changed') self.assertTrue(self.CONFIGS.write_all.called) diff --git a/unit_tests/test_quantum_utils.py b/unit_tests/test_quantum_utils.py index f6841693..bb63dcab 100644 --- a/unit_tests/test_quantum_utils.py +++ b/unit_tests/test_quantum_utils.py @@ -1,6 +1,6 @@ from mock import MagicMock, call, patch import collections - +import charmhelpers.contrib.openstack.context as chcontext import charmhelpers.contrib.openstack.templating as templating templating.OSConfigRenderer = MagicMock() @@ -41,7 +41,8 @@ TO_PATCH = [ 'relations_of_type', 'service_stop', 'determine_dkms_package', - 'service_restart' + 'service_restart', + 'is_relation_made', ] @@ -132,6 +133,7 @@ class TestQuantumUtils(CharmTestCase): def test_do_openstack_upgrade(self): self.config.side_effect = self.test_config.get + self.is_relation_made.return_value = False self.test_config.set('openstack-origin', 'cloud:precise-havana') self.test_config.set('plugin', 'ovs') self.get_os_codename_install_source.return_value = 'havana' @@ -151,6 +153,7 @@ class TestQuantumUtils(CharmTestCase): def test_register_configs_ovs(self): self.config.return_value = 'ovs' + self.is_relation_made.return_value = False configs = quantum_utils.register_configs() confs = [quantum_utils.NEUTRON_DHCP_AGENT_CONF, quantum_utils.NEUTRON_METADATA_AGENT_CONF, @@ -166,6 +169,25 @@ class TestQuantumUtils(CharmTestCase): ['hook_contexts'] ) + def test_register_configs_amqp_nova(self): + self.config.return_value = 'ovs' + self.is_relation_made.return_value = True + configs = quantum_utils.register_configs() + confs = [quantum_utils.NEUTRON_DHCP_AGENT_CONF, + quantum_utils.NEUTRON_METADATA_AGENT_CONF, + quantum_utils.NOVA_CONF, + quantum_utils.NEUTRON_CONF, + quantum_utils.NEUTRON_L3_AGENT_CONF, + quantum_utils.NEUTRON_OVS_PLUGIN_CONF, + quantum_utils.EXT_PORT_CONF] + for conf in confs: + configs.register.assert_any_call( + conf, + quantum_utils.CONFIG_FILES['neutron'][quantum_utils.OVS][conf] + ['hook_contexts'] + ) + + def test_restart_map_ovs(self): self.config.return_value = 'ovs' ex_map = { @@ -200,6 +222,7 @@ class TestQuantumUtils(CharmTestCase): def test_register_configs_nvp(self): self.config.return_value = 'nvp' + self.is_relation_made.return_value = False configs = quantum_utils.register_configs() confs = [quantum_utils.NEUTRON_DHCP_AGENT_CONF, quantum_utils.NEUTRON_METADATA_AGENT_CONF, @@ -253,6 +276,7 @@ class TestQuantumUtils(CharmTestCase): def test_register_configs_pre_install(self): self.config.return_value = 'ovs' + self.is_relation_made.return_value = False self.networking_name.return_value = 'quantum' configs = quantum_utils.register_configs() confs = [quantum_utils.QUANTUM_DHCP_AGENT_CONF, From 1bb6d2462993d46da1b95f0083fbcf22fb477e86 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 23 Jun 2014 12:43:28 +0100 Subject: [PATCH 10/10] Fix merge confilct --- unit_tests/test_quantum_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/unit_tests/test_quantum_utils.py b/unit_tests/test_quantum_utils.py index bb63dcab..70f98382 100644 --- a/unit_tests/test_quantum_utils.py +++ b/unit_tests/test_quantum_utils.py @@ -42,6 +42,7 @@ TO_PATCH = [ 'service_stop', 'determine_dkms_package', 'service_restart', + 'remap_plugin', 'is_relation_made', ]