From 8f53a051cc7f5381a0b389847c17db5c127dc89e Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 21 Aug 2019 10:50:08 -0400 Subject: [PATCH] Remove deprecated [neutron]/url option The url option was deprecated in Queens: I41724a612a5f3eabd504f3eaa9d2f9d141ca3f69 The same functionality is available in the endpoint_override option so tests and docs are updated to use that where they were using url before. Note that because the logic in the get_client method changed, some small changes were made to the test_withtoken and test_withtoken_context_is_admin unit tests to differentiate from when there is a context with a token that is not admin and an admin context that does not have a token which was otherwise determined by asserting the default region name. Change-Id: I6c068a84c4c0bd88f088f9328d7897bfc1f843f1 --- .../configuration/hypervisor-hyper-v.rst | 2 +- nova/conf/neutron.py | 23 ------------ nova/network/neutronv2/api.py | 35 +++++++------------ nova/tests/unit/network/test_neutronv2.py | 29 ++++++++------- .../rm-neutron-url-conf-2056befe7207bd0b.yaml | 6 ++++ 5 files changed, 36 insertions(+), 59 deletions(-) create mode 100644 releasenotes/notes/rm-neutron-url-conf-2056befe7207bd0b.yaml diff --git a/doc/source/admin/configuration/hypervisor-hyper-v.rst b/doc/source/admin/configuration/hypervisor-hyper-v.rst index 9cdc6f86aa..9608366ee8 100644 --- a/doc/source/admin/configuration/hypervisor-hyper-v.rst +++ b/doc/source/admin/configuration/hypervisor-hyper-v.rst @@ -370,7 +370,7 @@ on Hyper-V. Below is a sample ``nova.conf`` for Windows: [glance] api_servers = http://IP_ADDRESS:9292 [neutron] - url = http://IP_ADDRESS:9696 + endpoint_override = http://IP_ADDRESS:9696 auth_strategy = keystone project_name = service username = neutron diff --git a/nova/conf/neutron.py b/nova/conf/neutron.py index 33fca355dd..34c8d67fea 100644 --- a/nova/conf/neutron.py +++ b/nova/conf/neutron.py @@ -30,25 +30,6 @@ Configuration options for neutron (network connectivity as a service). """) neutron_opts = [ - cfg.URIOpt('url', - sample_default='http://127.0.0.1:9696', - deprecated_for_removal=True, - deprecated_since='17.0.0', - deprecated_reason='Endpoint lookup uses the service catalog via ' - 'common keystoneauth1 Adapter configuration ' - 'options. In the current release, "url" will ' - 'override this behavior, but will be ignored and/or ' - 'removed in a future release. To achieve the same ' - 'result, use the endpoint_override option instead.', - help=""" -This option specifies the URL for connecting to Neutron. - -Possible values: - -* Any valid URL that points to the Neutron API service is appropriate here. - This typically matches the URL returned for the 'network' service type - from the Keystone service catalog. -"""), cfg.StrOpt('ovs_bridge', default='br-int', help=""" @@ -147,10 +128,6 @@ ALL_OPTS = (neutron_opts + metadata_proxy_opts) def register_opts(conf): conf.register_group(neutron_group) conf.register_opts(ALL_OPTS, group=neutron_group) - # NOTE(efried): We don't pass `url` as a deprecated opt because that would - # make CONF.neutron.url indistinguishable from - # CONF.neutron.endpoint_override in the code, and we need to be able to use - # the former to trigger the legacy behavior. confutils.register_ksa_opts(conf, neutron_group, DEFAULT_SERVICE_TYPE) diff --git a/nova/network/neutronv2/api.py b/nova/network/neutronv2/api.py index a3d9e47fa8..fea9045269 100644 --- a/nova/network/neutronv2/api.py +++ b/nova/network/neutronv2/api.py @@ -174,28 +174,19 @@ def get_client(context, admin=False): auth=auth_plugin, global_request_id=context.global_id) - if CONF.neutron.url: - # TODO(efried): Remove in Rocky - client_args = dict(client_args, - endpoint_override=CONF.neutron.url, - # NOTE(efried): The legacy behavior was to default - # region_name in the conf. - region_name=CONF.neutron.region_name or 'RegionOne') - else: - # The new way - # NOTE(efried): We build an adapter - # to pull conf options - # to pass to neutronclient - # which uses them to build an Adapter. - # This should be unwound at some point. - adap = utils.get_ksa_adapter( - 'network', ksa_auth=auth_plugin, ksa_session=session) - client_args = dict(client_args, - service_type=adap.service_type, - service_name=adap.service_name, - interface=adap.interface, - region_name=adap.region_name, - endpoint_override=adap.endpoint_override) + # NOTE(efried): We build an adapter + # to pull conf options + # to pass to neutronclient + # which uses them to build an Adapter. + # This should be unwound at some point. + adap = utils.get_ksa_adapter( + 'network', ksa_auth=auth_plugin, ksa_session=session) + client_args = dict(client_args, + service_type=adap.service_type, + service_name=adap.service_name, + interface=adap.interface, + region_name=adap.region_name, + endpoint_override=adap.endpoint_override) return ClientWrapper(clientv20.Client(**client_args), admin=admin or context.is_admin) diff --git a/nova/tests/unit/network/test_neutronv2.py b/nova/tests/unit/network/test_neutronv2.py index 2313a055cf..54320fe910 100644 --- a/nova/tests/unit/network/test_neutronv2.py +++ b/nova/tests/unit/network/test_neutronv2.py @@ -162,16 +162,17 @@ class TestNeutronClient(test.NoDBTestCase): self.assertEqual('eo', cl.httpclient.endpoint_override) def test_withtoken(self): - self.flags(url='http://anyhost/', group='neutron') + self.flags(endpoint_override='http://anyhost/', group='neutron') self.flags(timeout=30, group='neutron') + # Will use the token rather than load auth from config. my_context = context.RequestContext('userid', uuids.my_tenant, auth_token='token') cl = neutronapi.get_client(my_context) - self.assertEqual(CONF.neutron.url, cl.httpclient.endpoint_override) - # Specifying 'url' defaults 'region_name' - self.assertEqual('RegionOne', cl.httpclient.region_name) + self.assertEqual(CONF.neutron.endpoint_override, + cl.httpclient.endpoint_override) + self.assertEqual(CONF.neutron.region_name, cl.httpclient.region_name) self.assertEqual(my_context.auth_token, cl.httpclient.auth.auth_token) self.assertEqual(CONF.neutron.timeout, cl.httpclient.session.timeout) @@ -228,21 +229,23 @@ class TestNeutronClient(test.NoDBTestCase): self.assertIsInstance(exc.format_message(), six.text_type) def test_withtoken_context_is_admin(self): - self.flags(url='http://anyhost/', group='neutron') + self.flags(endpoint_override='http://anyhost/', group='neutron') self.flags(timeout=30, group='neutron') + # No auth_token set but is_admin will load auth from config. my_context = context.RequestContext('userid', uuids.my_tenant, - auth_token='token', is_admin=True) - cl = neutronapi.get_client(my_context) + with mock.patch.object(neutronapi, '_load_auth_plugin') as mock_auth: + cl = neutronapi.get_client(my_context) - self.assertEqual(CONF.neutron.url, cl.httpclient.endpoint_override) - self.assertEqual(my_context.auth_token, + self.assertEqual(CONF.neutron.endpoint_override, + cl.httpclient.endpoint_override) + self.assertEqual(mock_auth.return_value.auth_token, cl.httpclient.auth.auth_token) self.assertEqual(CONF.neutron.timeout, cl.httpclient.session.timeout) def test_withouttoken_keystone_connection_error(self): - self.flags(url='http://anyhost/', group='neutron') + self.flags(endpoint_override='http://anyhost/', group='neutron') my_context = context.RequestContext('userid', uuids.my_tenant) self.assertRaises(NEUTRON_CLIENT_EXCEPTION, neutronapi.get_client, @@ -251,7 +254,7 @@ class TestNeutronClient(test.NoDBTestCase): @mock.patch('nova.network.neutronv2.api._ADMIN_AUTH') @mock.patch.object(client.Client, "list_networks", new=mock.Mock()) def test_reuse_admin_token(self, m): - self.flags(url='http://anyhost/', group='neutron') + self.flags(endpoint_override='http://anyhost/', group='neutron') my_context = context.RequestContext('userid', uuids.my_tenant, auth_token='token') @@ -6832,7 +6835,7 @@ class TestNeutronClientForAdminScenarios(test.NoDBTestCase): token_resp = V2Token(token_id=token_value) req_mock.post(auth_url + '/tokens', json=token_resp) - self.flags(url='http://anyhost/', group='neutron') + self.flags(endpoint_override='http://anyhost/', group='neutron') self.flags(auth_type='v2password', group='neutron') self.flags(auth_url=auth_url, group='neutron') self.flags(timeout=30, group='neutron') @@ -6885,7 +6888,7 @@ class TestNeutronClientForAdminScenarios(test.NoDBTestCase): token_value, context_client.httpclient.auth.get_token(neutronapi._SESSION)) self.assertEqual( - CONF.neutron.url, + CONF.neutron.endpoint_override, context_client.httpclient.get_endpoint()) def test_get_client_for_admin(self): diff --git a/releasenotes/notes/rm-neutron-url-conf-2056befe7207bd0b.yaml b/releasenotes/notes/rm-neutron-url-conf-2056befe7207bd0b.yaml new file mode 100644 index 0000000000..30153de832 --- /dev/null +++ b/releasenotes/notes/rm-neutron-url-conf-2056befe7207bd0b.yaml @@ -0,0 +1,6 @@ +--- +upgrade: + - | + The ``[neutron]/url`` configuration option, which was deprecated in the + 17.0.0 Queens release, has now been removed. The same functionality is + available via the ``[neutron]/endpoint_override`` option.