From 43c822e00296ce4a7e8ac7d3a23551450a5839b2 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Fri, 27 Jun 2014 14:32:44 +0100 Subject: [PATCH] If apache is in place switch neutron server to listen on different port --- hooks/neutron_api_context.py | 6 ++++++ unit_tests/test_neutron_api_context.py | 8 +++++++- unit_tests/test_neutron_api_hooks.py | 6 ++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/hooks/neutron_api_context.py b/hooks/neutron_api_context.py index 23aa4382..9180c2a2 100644 --- a/hooks/neutron_api_context.py +++ b/hooks/neutron_api_context.py @@ -5,6 +5,9 @@ from charmhelpers.core.hookenv import ( relation_get, ) from charmhelpers.contrib.openstack import context +from charmhelpers.contrib.hahelpers.cluster import ( + determine_api_port, +) class ApacheSSLContext(context.ApacheSSLContext): @@ -54,10 +57,13 @@ class NeutronCCContext(context.NeutronContext): pass def __call__(self): + from neutron_api_utils import api_port ctxt = super(NeutronCCContext, self).__call__() ctxt['external_network'] = config('neutron-external-network') ctxt['verbose'] = config('verbose') ctxt['debug'] = config('debug') + ctxt['neutron_bind_port'] = \ + determine_api_port(api_port('neutron-server')) for rid in relation_ids('neutron-api'): for unit in related_units(rid): ctxt['nova_url'] = relation_get(attribute='nova_url', diff --git a/unit_tests/test_neutron_api_context.py b/unit_tests/test_neutron_api_context.py index 1c3a2ee3..223a4b13 100644 --- a/unit_tests/test_neutron_api_context.py +++ b/unit_tests/test_neutron_api_context.py @@ -7,6 +7,7 @@ TO_PATCH = [ 'relation_ids', 'related_units', 'config', + 'determine_api_port', ] @@ -53,6 +54,8 @@ class NeutronAPIContextsTest(CharmTestCase): super(NeutronAPIContextsTest, self).setUp(context, TO_PATCH) self.relation_get.side_effect = self.test_relation.get self.config.side_effect = self.test_config.get + self.api_port = 9696 + self.determine_api_port.return_value = self.api_port self.test_config.set('neutron-plugin', 'ovs') self.test_config.set('neutron-security-groups', True) self.test_config.set('debug', True) @@ -70,11 +73,13 @@ class NeutronAPIContextsTest(CharmTestCase): ctxt_data = { 'debug': True, 'external_network': 'bob', - 'verbose': True + 'neutron_bind_port': self.api_port, + 'verbose': True, } with patch.object(napi_ctxt, '_ensure_packages'): self.assertEquals(ctxt_data, napi_ctxt()) + #@patch.object(charmhelpers.contrib.hahelpers.cluster, 'determine_api_port') @patch.object(context.NeutronCCContext, 'network_manager') @patch.object(context.NeutronCCContext, 'plugin') def test_neutroncc_context_api_rel(self, plugin, nm): @@ -85,6 +90,7 @@ class NeutronAPIContextsTest(CharmTestCase): self.test_relation.set({'nova_url': nova_url}) napi_ctxt = context.NeutronCCContext() self.assertEquals(nova_url, napi_ctxt()['nova_url']) + self.assertEquals(self.api_port, napi_ctxt()['neutron_bind_port']) def test_neutroncc_context_manager(self): napi_ctxt = context.NeutronCCContext() diff --git a/unit_tests/test_neutron_api_hooks.py b/unit_tests/test_neutron_api_hooks.py index 7ce7907e..7be02bd8 100644 --- a/unit_tests/test_neutron_api_hooks.py +++ b/unit_tests/test_neutron_api_hooks.py @@ -340,7 +340,8 @@ class NeutronAPIHooksTests(CharmTestCase): self.relation_ids.side_effect = self._fake_relids _id_rel_joined = self.patch('identity_joined') hooks.configure_https() - self.check_call.assert_called_with(['a2ensite', 'openstack_https_frontend']) + self.check_call.assert_called_with(['a2ensite', + 'openstack_https_frontend']) self.assertTrue(_id_rel_joined.called) def test_configure_https_nohttps(self): @@ -348,5 +349,6 @@ class NeutronAPIHooksTests(CharmTestCase): self.relation_ids.side_effect = self._fake_relids _id_rel_joined = self.patch('identity_joined') hooks.configure_https() - self.check_call.assert_called_with(['a2dissite', 'openstack_https_frontend']) + self.check_call.assert_called_with(['a2dissite', + 'openstack_https_frontend']) self.assertTrue(_id_rel_joined.called)