From 2be884aefe40faab305c9995dbe853e853cd8bba Mon Sep 17 00:00:00 2001 From: Jeremy McDermond Date: Tue, 8 Dec 2015 10:14:09 -0800 Subject: [PATCH] Add option for nova endpoint type When the neutron notification to nova was updated to use novaclient the nova_url parameter was disabled. This prevents administrators from using anything but the publicURL as the proper endpoint to notify nova. This patch adds an option to pass on to novaclient for the endpoint_type so that the administrator can set the notification url to public, internal or admin. Change-Id: I405f761944449cab6b8c8895f98419f79cd74cad Closes-Bug: #1478471 DocImpact: Need to add a new option to the neutron configuration reference. (cherry picked from commit 7dad96deb4ae66509d968465bcd1c852c6743bc1) --- etc/neutron.conf | 4 ++++ neutron/common/config.py | 6 ++++++ neutron/notifiers/nova.py | 1 + neutron/tests/unit/notifiers/test_nova.py | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/etc/neutron.conf b/etc/neutron.conf index 6297e7762dd..18a9dd82b62 100644 --- a/etc/neutron.conf +++ b/etc/neutron.conf @@ -785,6 +785,10 @@ admin_password = %SERVICE_PASSWORD% # PEM encoded client certificate cert file # certfile = +# Type of the nova endpoint to use. This endpoint will be looked up in the +# keystone catalog and should be one of public, internal or admin. +# endpoint_type = public + # Verify HTTPS connections. # insecure = False diff --git a/neutron/common/config.py b/neutron/common/config.py index b6ba1a716e7..cf58b74e552 100644 --- a/neutron/common/config.py +++ b/neutron/common/config.py @@ -184,6 +184,12 @@ nova_opts = [ deprecated_group='DEFAULT', help=_('Name of nova region to use. Useful if keystone manages' ' more than one region.')), + cfg.StrOpt('endpoint_type', + default='public', + choices=['public', 'admin', 'internal'], + help=_('Type of the nova endpoint to use. This endpoint will' + ' be looked up in the keystone catalog and should be' + ' one of public, internal or admin.')), ] cfg.CONF.register_opts(nova_opts, group=NOVA_CONF_SECTION) diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index 8fb81862c2f..1ee89f8d90f 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -100,6 +100,7 @@ class Notifier(object): NOVA_API_VERSION, session=session, region_name=cfg.CONF.nova.region_name, + endpoint_type=cfg.CONF.nova.endpoint_type, extensions=extensions) self.batch_notifier = batch_notifier.BatchNotifier( cfg.CONF.send_events_interval, self.send_events) diff --git a/neutron/tests/unit/notifiers/test_nova.py b/neutron/tests/unit/notifiers/test_nova.py index 0bb9693645c..53446484c82 100644 --- a/neutron/tests/unit/notifiers/test_nova.py +++ b/neutron/tests/unit/notifiers/test_nova.py @@ -305,3 +305,23 @@ class TestNovaNotify(base.BaseTestCase): event = self.nova_notifier.create_port_changed_event('delete_port', {}, returned_obj) self.assertEqual(expected_event, event) + + @mock.patch('novaclient.client.Client') + def test_endpoint_types(self, mock_client): + nova.Notifier() + mock_client.assert_called_once_with( + nova.NOVA_API_VERSION, + session=mock.ANY, + region_name=cfg.CONF.nova.region_name, + endpoint_type='public', + extensions=mock.ANY) + + mock_client.reset_mock() + cfg.CONF.set_override('endpoint_type', 'internal', 'nova') + nova.Notifier() + mock_client.assert_called_once_with( + nova.NOVA_API_VERSION, + session=mock.ANY, + region_name=cfg.CONF.nova.region_name, + endpoint_type='internal', + extensions=mock.ANY)