From 26f87250f56cfaada3cd5c8d2dc937aefbf94eb5 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 23 Jun 2014 12:18:17 +0100 Subject: [PATCH] Updated with fixes suggested from bug comments --- copyright | 9 + hooks/neutron_api_context.py | 4 - hooks/neutron_api_hooks.py | 53 +-- hooks/neutron_api_utils.py | 13 +- icon.svg | 676 +++++++++++++++++++++++++++ unit_tests/test_neutron_api_hooks.py | 73 +-- unit_tests/test_neutron_api_utils.py | 2 + 7 files changed, 713 insertions(+), 117 deletions(-) create mode 100644 copyright create mode 100644 icon.svg diff --git a/copyright b/copyright new file mode 100644 index 00000000..d44f24cf --- /dev/null +++ b/copyright @@ -0,0 +1,9 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0 + +Files: * +Copyright: 2012, Canonical Ltd. +License: GPL-3 + +License: GPL-3 + On Debian GNU/Linux system you can find the complete text of the + GPL-3 license in '/usr/share/common-licenses/GPL-3' diff --git a/hooks/neutron_api_context.py b/hooks/neutron_api_context.py index 7a5ef885..6fedd78a 100644 --- a/hooks/neutron_api_context.py +++ b/hooks/neutron_api_context.py @@ -42,14 +42,10 @@ class NeutronCCContext(context.NeutronContext): ctxt['verbose'] = config('verbose') ctxt['debug'] = config('debug') for rid in relation_ids('neutron-api'): - print "rid" for unit in related_units(rid): - print "unit" ctxt['nova_url'] = relation_get(attribute='nova_url', rid=rid, unit=unit) if ctxt['nova_url']: - print "Ive set nova_url" return ctxt - print "Ive not set nova_url" return ctxt diff --git a/hooks/neutron_api_hooks.py b/hooks/neutron_api_hooks.py index 8f1706f1..22d58eac 100755 --- a/hooks/neutron_api_hooks.py +++ b/hooks/neutron_api_hooks.py @@ -12,7 +12,6 @@ from charmhelpers.core.hookenv import ( relation_get, relation_ids, relation_set, - related_units, open_port, unit_get, ) @@ -30,7 +29,6 @@ from charmhelpers.contrib.openstack.utils import ( openstack_upgrade_available, ) from charmhelpers.contrib.openstack.neutron import ( - network_manager, neutron_plugin_attribute, ) @@ -73,7 +71,7 @@ def install(): def config_changed(): global CONFIGS if openstack_upgrade_available('neutron-server'): - do_openstack_upgrade(CONFIGS) + do_openstack_upgrade(CONFIGS) CONFIGS.write_all() for r_id in relation_ids('neutron-api'): neutron_api_relation_joined(rid=r_id) @@ -139,10 +137,9 @@ def db_changed(): @hooks.hook('pgsql-db-relation-changed') @restart_on_change(restart_map()) def postgresql_neutron_db_changed(): - if network_manager() in ['neutron', 'quantum']: - plugin = config('neutron-plugin') - # DB config might have been moved to main neutron.conf in H? - CONFIGS.write(neutron_plugin_attribute(plugin, 'config')) + plugin = config('neutron-plugin') + # DB config might have been moved to main neutron.conf in H? + CONFIGS.write(neutron_plugin_attribute(plugin, 'config')) @hooks.hook('amqp-relation-broken', @@ -170,51 +167,21 @@ def identity_changed(): neutron_api_relation_joined(rid=r_id) -def _get_keystone_info(): - keystone_info = {} - for lrid in relation_ids('identity-service'): - for unit in related_units(lrid): - rdata = relation_get(rid=lrid, unit=unit) - keystone_info['service_protocol'] = rdata.get('service_protocol') - keystone_info['service_host'] = rdata.get('service_host') - keystone_info['service_port'] = rdata.get('service_port') - keystone_info['service_tenant'] = rdata.get('service_tenant') - keystone_info['service_username'] = rdata.get('service_username') - keystone_info['service_password'] = rdata.get('service_password') - auth_url = "%s://%s:%s/v2.0" % (keystone_info['service_protocol'], - keystone_info['service_host'], - keystone_info['service_port']) - keystone_info['auth_url'] = auth_url - return keystone_info - - @hooks.hook('neutron-api-relation-joined') def neutron_api_relation_joined(rid=None): - manager = network_manager() base_url = canonical_url(CONFIGS) neutron_url = '%s:%s' % (base_url, api_port('neutron-server')) relation_data = { - 'network_manager': manager, - 'default_floating_pool': config('neutron-external-network'), - 'external_network': config('neutron-external-network'), - manager + '_plugin': config('neutron-plugin'), - manager + '_url': neutron_url, + 'neutron-url': neutron_url, + 'neutron-plugin': config('neutron-plugin'), } if config('neutron-security-groups'): - relation_data[manager + '_security_groups'] = "yes" + relation_data['neutron-security-groups'] = "yes" else: - relation_data[manager + '_security_groups'] = "no" - keystone_info = _get_keystone_info() - if is_relation_made('identity-service') and keystone_info: - relation_data.update({ - manager + '_admin_tenant_name': keystone_info['service_tenant'], - manager + '_admin_username': keystone_info['service_username'], - manager + '_admin_password': keystone_info['service_password'], - manager + '_admin_auth_url': keystone_info['auth_url'], - }) + relation_data['neutron-security-groups'] = "no" relation_set(relation_id=rid, **relation_data) # Nova-cc may have grabbed the quantum endpoint so kick identity-service - #relation to register that its here + # relation to register that its here for r_id in relation_ids('identity-service'): identity_joined(rid=r_id) @@ -228,7 +195,7 @@ def neutron_api_relation_changed(): @hooks.hook('neutron-plugin-api-relation-joined') def neutron_plugin_api_relation_joined(rid=None): relation_data = { - 'neutron_security_groups': config('neutron-security-groups') + 'neutron-security-groups': config('neutron-security-groups') } relation_set(relation_id=rid, **relation_data) diff --git a/hooks/neutron_api_utils.py b/hooks/neutron_api_utils.py index a70cd6da..6ddbfb76 100644 --- a/hooks/neutron_api_utils.py +++ b/hooks/neutron_api_utils.py @@ -4,7 +4,8 @@ import os from base64 import b64encode from charmhelpers.contrib.openstack import context, templating from charmhelpers.contrib.openstack.neutron import ( - network_manager, neutron_plugin_attribute) + neutron_plugin_attribute, +) from charmhelpers.contrib.openstack.utils import ( os_release, @@ -95,7 +96,7 @@ def determine_packages(): packages.extend(v['services']) pkgs = neutron_plugin_attribute(config('neutron-plugin'), 'server_packages', - network_manager()) + 'neutron') packages.extend(pkgs) return list(set(packages)) @@ -119,16 +120,14 @@ def resource_map(): ''' resource_map = deepcopy(BASE_RESOURCE_MAP) - net_manager = network_manager() - # add neutron plugin requirements. nova-c-c only needs the neutron-server # associated with configs, not the plugin agent. plugin = config('neutron-plugin') - conf = neutron_plugin_attribute(plugin, 'config', net_manager) - ctxts = (neutron_plugin_attribute(plugin, 'contexts', net_manager) + conf = neutron_plugin_attribute(plugin, 'config', 'neutron') + ctxts = (neutron_plugin_attribute(plugin, 'contexts', 'neutron') or []) services = neutron_plugin_attribute(plugin, 'server_services', - net_manager) + 'neutron') resource_map[conf] = {} resource_map[conf]['services'] = services resource_map[conf]['contexts'] = ctxts diff --git a/icon.svg b/icon.svg new file mode 100644 index 00000000..d1884699 --- /dev/null +++ b/icon.svg @@ -0,0 +1,676 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/unit_tests/test_neutron_api_hooks.py b/unit_tests/test_neutron_api_hooks.py index dfb2a64a..1eabb79d 100644 --- a/unit_tests/test_neutron_api_hooks.py +++ b/unit_tests/test_neutron_api_hooks.py @@ -33,14 +33,12 @@ TO_PATCH = [ 'is_leader', 'is_relation_made', 'log', - 'network_manager', 'neutron_plugin_attribute', 'open_port', 'openstack_upgrade_available', 'relation_get', 'relation_ids', 'relation_set', - 'related_units', 'unit_get', ] NEUTRON_CONF_DIR = "/etc/neutron" @@ -164,7 +162,6 @@ class NeutronAPIHooksTests(CharmTestCase): self.assertFalse(self.CONFIGS.write_all.called) def test_pgsql_db_changed(self): - self.network_manager.return_value = 'neutron' self._call_hook('pgsql-db-relation-changed') self.assertTrue(self.CONFIGS.write.called) @@ -203,26 +200,19 @@ class NeutronAPIHooksTests(CharmTestCase): self.assertTrue(self.CONFIGS.write.called_with(NEUTRON_CONF)) self.assertTrue(_api_rel_joined.called) - @patch.object(hooks, '_get_keystone_info') - def test_neutron_api_relation_no_id_joined(self, _get_ks_info): - _get_ks_info.return_value = None - manager = 'neutron' + def test_neutron_api_relation_no_id_joined(self): host = 'http://127.0.0.1' port = 1234 _id_rel_joined = self.patch('identity_joined') self.relation_ids.side_effect = self._fake_relids - self.network_manager.return_value = manager self.canonical_url.return_value = host self.api_port.return_value = port self.is_relation_made = False neutron_url = '%s:%s' % (host, port) _relation_data = { - 'network_manager': manager, - 'default_floating_pool': 'ext_net', - 'external_network': 'ext_net', - manager + '_plugin': 'ovs', - manager + '_url': neutron_url, - 'neutron_security_groups': 'no', + 'neutron-plugin': 'ovs', + 'neutron-url': neutron_url, + 'neutron-security-groups': 'no', } self._call_hook('neutron-api-relation-joined') self.relation_set.assert_called_with( @@ -232,40 +222,23 @@ class NeutronAPIHooksTests(CharmTestCase): self.assertTrue(_id_rel_joined.called) self.test_config.set('neutron-security-groups', True) self._call_hook('neutron-api-relation-joined') - _relation_data['neutron_security_groups'] = 'yes' + _relation_data['neutron-security-groups'] = 'yes' self.relation_set.assert_called_with( relation_id=None, **_relation_data ) - @patch.object(hooks, '_get_keystone_info') - def test_neutron_api_relation_joined(self, _get_ks_info): - _ks_info = { - 'service_tenant': 'bob', - 'service_username': 'bob', - 'service_password': 'bob', - 'auth_url': 'http://127.0.0.2', - } - _get_ks_info.return_value = _ks_info - manager = 'neutron' + def test_neutron_api_relation_joined(self): host = 'http://127.0.0.1' port = 1234 - self.network_manager.return_value = manager self.canonical_url.return_value = host self.api_port.return_value = port self.is_relation_made = True neutron_url = '%s:%s' % (host, port) _relation_data = { - 'network_manager': manager, - 'default_floating_pool': 'ext_net', - 'external_network': 'ext_net', - manager + '_plugin': 'ovs', - manager + '_url': neutron_url, - 'neutron_security_groups': 'no', - manager + '_admin_tenant_name': _ks_info['service_tenant'], - manager + '_admin_username': _ks_info['service_username'], - manager + '_admin_password': _ks_info['service_password'], - manager + '_admin_auth_url': _ks_info['auth_url'], + 'neutron-plugin': 'ovs', + 'neutron-url': neutron_url, + 'neutron-security-groups': 'no', } self._call_hook('neutron-api-relation-joined') self.relation_set.assert_called_with( @@ -279,7 +252,7 @@ class NeutronAPIHooksTests(CharmTestCase): def test_neutron_plugin_api_relation_joined(self): _relation_data = { - 'neutron_security_groups': False, + 'neutron-security-groups': False, } self._call_hook('neutron-plugin-api-relation-joined') self.relation_set.assert_called_with( @@ -358,29 +331,3 @@ class NeutronAPIHooksTests(CharmTestCase): self._call_hook('ha-relation-changed') self.assertFalse(_n_api_rel_joined.called) self.assertFalse(_id_rel_joined.called) - - def test_get_keystone_info(self): - self.relation_ids.return_value = 'relid1' - self.related_units.return_value = 'unit1' - _ks_info = { - 'service_protocol': 'https', - 'service_host': '127.0.0.3', - 'service_port': '4567', - 'service_tenant': 'region12', - 'service_username': 'bob', - 'service_password': 'pass', - } - self.test_relation.set(_ks_info) - auth_url = "%s://%s:%s/v2.0" % (_ks_info['service_protocol'], - _ks_info['service_host'], - _ks_info['service_port']) - expect_ks_info = { - 'service_protocol': _ks_info['service_protocol'], - 'service_host': _ks_info['service_host'], - 'service_port': _ks_info['service_port'], - 'service_tenant': _ks_info['service_tenant'], - 'service_username': _ks_info['service_username'], - 'service_password': _ks_info['service_password'], - 'auth_url': auth_url, - } - self.assertEqual(hooks._get_keystone_info(), expect_ks_info) diff --git a/unit_tests/test_neutron_api_utils.py b/unit_tests/test_neutron_api_utils.py index e27ba476..ffb974f6 100644 --- a/unit_tests/test_neutron_api_utils.py +++ b/unit_tests/test_neutron_api_utils.py @@ -25,6 +25,7 @@ TO_PATCH = [ 'get_os_codename_install_source', 'log', 'neutron_plugin_attribute', + 'os_release', ] @@ -50,6 +51,7 @@ class TestNeutronAPIUtils(CharmTestCase): self.config.side_effect = self.test_config.get self.test_config.set('region', 'region101') self.neutron_plugin_attribute.side_effect = _mock_npa + self.os_release.side_effect = 'trusty' def tearDown(self): # Reset cached cache