From c8e783883f949c7a9edc6007d4cf1a12b446360c Mon Sep 17 00:00:00 2001 From: Liam Young Date: Wed, 11 Jun 2014 09:44:51 +0000 Subject: [PATCH] Restore management of neutron.conf to plugin --- config.yaml | 2 +- hooks/amqp-relation-broken | 1 + hooks/amqp-relation-changed | 1 + hooks/amqp-relation-departed | 1 + hooks/amqp-relation-joined | 1 + .../charmhelpers/contrib/openstack/context.py | 7 +-- hooks/neutron_ovs_context.py | 4 -- hooks/neutron_ovs_hooks.py | 47 +++++++++---------- hooks/neutron_ovs_utils.py | 45 +++++------------- metadata.yaml | 2 + templates/havana/neutron.conf | 34 ++++++++++++++ templates/icehouse/ml2_conf.ini | 1 - 12 files changed, 75 insertions(+), 71 deletions(-) create mode 120000 hooks/amqp-relation-broken create mode 120000 hooks/amqp-relation-changed create mode 120000 hooks/amqp-relation-departed create mode 120000 hooks/amqp-relation-joined create mode 100644 templates/havana/neutron.conf diff --git a/config.yaml b/config.yaml index f5603d71..9c40a2f6 100644 --- a/config.yaml +++ b/config.yaml @@ -1,6 +1,6 @@ options: rabbit-user: - default: nova + default: neutron type: string description: Username used to access rabbitmq queue rabbit-vhost: diff --git a/hooks/amqp-relation-broken b/hooks/amqp-relation-broken new file mode 120000 index 00000000..55aa8e52 --- /dev/null +++ b/hooks/amqp-relation-broken @@ -0,0 +1 @@ +neutron_ovs_hooks.py \ No newline at end of file diff --git a/hooks/amqp-relation-changed b/hooks/amqp-relation-changed new file mode 120000 index 00000000..55aa8e52 --- /dev/null +++ b/hooks/amqp-relation-changed @@ -0,0 +1 @@ +neutron_ovs_hooks.py \ No newline at end of file diff --git a/hooks/amqp-relation-departed b/hooks/amqp-relation-departed new file mode 120000 index 00000000..55aa8e52 --- /dev/null +++ b/hooks/amqp-relation-departed @@ -0,0 +1 @@ +neutron_ovs_hooks.py \ No newline at end of file diff --git a/hooks/amqp-relation-joined b/hooks/amqp-relation-joined new file mode 120000 index 00000000..55aa8e52 --- /dev/null +++ b/hooks/amqp-relation-joined @@ -0,0 +1 @@ +neutron_ovs_hooks.py \ No newline at end of file diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index fe30c0a1..e92b1cc8 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -487,10 +487,6 @@ class NeutronContext(OSContextGenerator): def plugin(self): return None - @property - def save_nova_flag(self): - return True - @property def network_manager(self): return None @@ -582,8 +578,7 @@ class NeutronContext(OSContextGenerator): flags = config_flags_parser(alchemy_flags) ctxt['neutron_alchemy_flags'] = flags - if self.save_nova_flag: - self._save_flag_file() + self._save_flag_file() return ctxt diff --git a/hooks/neutron_ovs_context.py b/hooks/neutron_ovs_context.py index 8a832c8f..a294a82c 100644 --- a/hooks/neutron_ovs_context.py +++ b/hooks/neutron_ovs_context.py @@ -38,10 +38,6 @@ class OVSPluginContext(context.NeutronContext): def network_manager(self): return 'neutron' - @property - def save_nova_flag(self): - return False - @property def neutron_security_groups(self): return _neutron_security_groups() diff --git a/hooks/neutron_ovs_hooks.py b/hooks/neutron_ovs_hooks.py index 0e4691aa..913e2c49 100755 --- a/hooks/neutron_ovs_hooks.py +++ b/hooks/neutron_ovs_hooks.py @@ -1,14 +1,13 @@ #!/usr/bin/python -import uuid + import sys -import json from charmhelpers.core.hookenv import ( Hooks, UnregisteredHookError, + config, log, relation_set, - relation_ids, ) from charmhelpers.core.host import ( @@ -23,7 +22,7 @@ from neutron_ovs_utils import ( determine_packages, register_configs, restart_map, - NEUTRON_SETTINGS, + NEUTRON_CONF, ) hooks = Hooks() @@ -35,33 +34,31 @@ def install(): apt_update() apt_install(determine_packages(), fatal=True) -@hooks.hook('config-changed') @restart_on_change(restart_map()) +@hooks.hook('config-changed') def config_changed(): CONFIGS.write_all() - [neutron_plugin_relation_joined(rid) for rid in relation_ids('neutron-plugin')] -@hooks.hook('neutron-plugin-relation-joined') -def neutron_plugin_relation_joined(remote_restart=True): - if remote_restart: - comment = ('restart', 'Restart Trigger: ' + str(uuid.uuid4())) - for conf in NEUTRON_SETTINGS['neutron']: - if 'sections' in NEUTRON_SETTINGS['neutron'][conf] and \ - 'COMMENT' in NEUTRON_SETTINGS['neutron'][conf]['sections']: - NEUTRON_SETTINGS['neutron'][conf]['sections']['COMMENT'].append(comment) - relation_set(subordinate_configuration=json.dumps(NEUTRON_SETTINGS)) - -@hooks.hook('neutron-plugin-relation-changed') @restart_on_change(restart_map()) -def neutron_plugin_relation_changed(remote_restart=True): +@hooks.hook('neutron-plugin-relation-changed') +def neutron_plugin_relation_changed(): CONFIGS.write_all() - if remote_restart: - comment = ('restart', 'Restart Trigger: ' + str(uuid.uuid4())) - for conf in NEUTRON_SETTINGS['neutron']: - if 'sections' in NEUTRON_SETTINGS['neutron'][conf] and \ - 'COMMENT' in NEUTRON_SETTINGS['neutron'][conf]['sections']: - NEUTRON_SETTINGS['neutron'][conf]['sections']['COMMENT'].append(comment) - relation_set(subordinate_configuration=json.dumps(NEUTRON_SETTINGS)) + +@hooks.hook('amqp-relation-joined') +def amqp_joined(relation_id=None): + relation_set(relation_id=relation_id, + username=config('rabbit-user'), + vhost=config('rabbit-vhost')) + + +@hooks.hook('amqp-relation-changed') +@hooks.hook('amqp-relation-departed') +@restart_on_change(restart_map()) +def amqp_changed(): + if 'amqp' not in CONFIGS.complete_contexts(): + log('amqp relation incomplete. Peer not ready?') + return + CONFIGS.write(NEUTRON_CONF) def main(): try: diff --git a/hooks/neutron_ovs_utils.py b/hooks/neutron_ovs_utils.py index 32eaf8dc..11fa9d54 100644 --- a/hooks/neutron_ovs_utils.py +++ b/hooks/neutron_ovs_utils.py @@ -1,55 +1,32 @@ from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute from copy import deepcopy -from charmhelpers.contrib.openstack import templating + +from charmhelpers.contrib.openstack import context, templating from collections import OrderedDict from charmhelpers.contrib.openstack.utils import ( os_release, ) import neutron_ovs_context +from charmhelpers.core.hookenv import is_relation_made NOVA_CONF_DIR = "/etc/nova" NEUTRON_CONF_DIR = "/etc/neutron" -NEUTRON_CONF = "%s/neutron.conf" % NEUTRON_CONF_DIR -ML2_CONF = '%s/plugins/ml2/ml2_conf.ini' % NEUTRON_CONF_DIR +NEUTRON_CONF = '%s/neutron.conf' % NEUTRON_CONF_DIR NEUTRON_DEFAULT = '/etc/default/neutron-server' +ML2_CONF = '%s/plugins/ml2/ml2_conf.ini' % NEUTRON_CONF_DIR BASE_RESOURCE_MAP = OrderedDict([ + (NEUTRON_CONF, { + 'services': ['neutron-plugin-openvswitch-agent'], + 'contexts': [neutron_ovs_context.OVSPluginContext(), + context.AMQPContext()], + }), (ML2_CONF, { 'services': ['neutron-plugin-openvswitch-agent'], 'contexts': [neutron_ovs_context.OVSPluginContext()], }), ]) TEMPLATES = 'templates/' -NEUTRON_SERVICE_PLUGINS=['neutron.services.l3_router.l3_router_plugin.L3RouterPlugin', - 'neutron.services.firewall.fwaas_plugin.FirewallPlugin', - 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', - 'neutron.services.vpn.plugin.VPNDriverPlugin', - 'neutron.services.metering.metering_plugin.MeteringPlugin'] -NEUTRON_SETTINGS = { - "neutron": { - NEUTRON_CONF: { - "sections": { - "DEFAULT": [ - ('core_plugin', 'neutron.plugins.ml2.plugin.Ml2Plugin'), - ('service_plugins', ','.join(NEUTRON_SERVICE_PLUGINS)), - ], - "COMMENT": [ - ('comment1', 'Warning: some settings controlled by subordinate neutron-openvswitch'), - ] - } - }, - NEUTRON_DEFAULT: { - "sections": { - "DEFAULT": [ - ('NEUTRON_PLUGIN_CONFIG', ML2_CONF), - ], - "COMMENT": [ - ('comment1', 'Warning: some settings controlled by subordinate neutron-openvswitch'), - ] - } - } - } -} def determine_packages(): ovs_pkgs = [] @@ -61,7 +38,7 @@ def determine_packages(): return set(ovs_pkgs) def register_configs(release=None): - release = release or os_release('neutron-common') + release = release or os_release('nova-common') configs = templating.OSConfigRenderer(templates_dir=TEMPLATES, openstack_release=release) for cfg, rscs in resource_map().iteritems(): diff --git a/metadata.yaml b/metadata.yaml index afdac68f..8d09b884 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -11,6 +11,8 @@ provides: interface: neutron-plugin scope: container requires: + amqp: + interface: rabbitmq container: interface: juju-info scope: container diff --git a/templates/havana/neutron.conf b/templates/havana/neutron.conf new file mode 100644 index 00000000..50142f24 --- /dev/null +++ b/templates/havana/neutron.conf @@ -0,0 +1,34 @@ +# grizzly +############################################################################### +# [ WARNING ] +# Configuration file maintained by Juju. Local changes may be overwritten. +############################################################################### +[DEFAULT] +state_path = /var/lib/neutron +lock_path = $state_path/lock +bind_host = 0.0.0.0 +bind_port = 9696 + +{% if core_plugin -%} +core_plugin = {{ core_plugin }} +{% endif -%} + +api_paste_config = /etc/neutron/api-paste.ini +auth_strategy = keystone +notification_driver = neutron.openstack.common.notifier.rpc_notifier +use_syslog = {{ use_syslog }} +default_notification_level = INFO +notification_topics = notifications + +{% include "parts/rabbitmq" %} + +[QUOTAS] + +[DEFAULT_SERVICETYPE] + +[AGENT] +root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf + +[keystone_authtoken] +signing_dir = /var/lib/neutron/keystone-signing + diff --git a/templates/icehouse/ml2_conf.ini b/templates/icehouse/ml2_conf.ini index 438e24d3..53985e24 100644 --- a/templates/icehouse/ml2_conf.ini +++ b/templates/icehouse/ml2_conf.ini @@ -2,7 +2,6 @@ ############################################################################### # [ WARNING ] # Configuration file maintained by Juju. Local changes may be overwritten. -# Config from neutron-openvswitch plugin ############################################################################### [ml2] type_drivers = gre,vxlan