From 6e8e322718529e50bf2035507b970058ddaa836a Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 3 Mar 2016 14:24:38 -0500 Subject: [PATCH] deprecate ``volume_api_class`` and ``network_api_class`` Both of these options only had one real in tree sensible option. Deprecate these so they can be removed and turned into constants in Newton. This adds a new ``use_neutron`` config option to replace the network_api_class option. Change-Id: Ia79269e2bca0468edde830fc82a15b234e1abcbf --- nova/network/__init__.py | 40 ++++++++++++++++-- nova/tests/unit/network/test_config.py | 41 +++++++++++++++++++ nova/volume/__init__.py | 9 ++-- .../rm_volume_manager-78fed5be43d285b3.yaml | 15 +++++++ 4 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 nova/tests/unit/network/test_config.py create mode 100644 releasenotes/notes/rm_volume_manager-78fed5be43d285b3.yaml diff --git a/nova/network/__init__.py b/nova/network/__init__.py index 27a0a802c2ce..845f658037cc 100644 --- a/nova/network/__init__.py +++ b/nova/network/__init__.py @@ -15,19 +15,51 @@ # under the License. import oslo_config.cfg +from oslo_log import log as logging from oslo_utils import importutils +from nova.i18n import _LW + +LOG = logging.getLogger(__name__) + +NOVA_NET_API = 'nova.network.api.API' +NEUTRON_NET_API = 'nova.network.neutronv2.api.API' + _network_opts = [ oslo_config.cfg.StrOpt('network_api_class', - default='nova.network.api.API', - help='The full class name of the ' - 'network API class to use'), + default=NOVA_NET_API, + help='DEPRECATED: The full class name of the ' + 'network API class to use. ``use_neutron`` ' + 'should be used instead.', + deprecated_for_removal=True), + oslo_config.cfg.BoolOpt('use_neutron', + default=False, + help=""" +Whether to use Neutron or Nova Network as the back end for networking. +Defaults to False (indicating Nova network). Set to True to use neutron. +""") + ] oslo_config.cfg.CONF.register_opts(_network_opts) def API(skip_policy_check=False): - network_api_class = oslo_config.cfg.CONF.network_api_class + legacy_class = oslo_config.cfg.CONF.network_api_class + use_neutron = oslo_config.cfg.CONF.use_neutron + + if legacy_class == NEUTRON_NET_API and not use_neutron: + # If they specified neutron via class, we should respect that + network_api_class = legacy_class + LOG.warn(_LW("Config mismatch. The network_api_class specifies %s, " + "however use_neutron is not set to True. Using Neutron " + "networking for now, however please set use_neutron to " + "True in your configuration as network_api_class is " + "deprecated and will be removed."), legacy_class) + elif use_neutron: + network_api_class = NEUTRON_NET_API + else: + network_api_class = NOVA_NET_API + cls = importutils.import_class(network_api_class) return cls(skip_policy_check=skip_policy_check) diff --git a/nova/tests/unit/network/test_config.py b/nova/tests/unit/network/test_config.py new file mode 100644 index 000000000000..afae030f1106 --- /dev/null +++ b/nova/tests/unit/network/test_config.py @@ -0,0 +1,41 @@ +# Copyright 2016 HPE, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import nova.network +import nova.test + + +class NetworkAPIConfigTest(nova.test.NoDBTestCase): + """Test the transition from legacy to use_neutron config options.""" + + def test_default(self): + netapi = nova.network.API() + self.assertIsInstance(netapi, nova.network.api.API) + + def test_use_neutron(self): + self.flags(use_neutron=True) + netapi = nova.network.API() + self.assertIsInstance(netapi, nova.network.neutronv2.api.API) + + def test_dont_use_neutron(self): + self.flags(use_neutron=False) + netapi = nova.network.API() + self.assertIsInstance(netapi, nova.network.api.API) + + def test_legacy_use_neutron(self): + """use neutron even if config is false because of legacy option.""" + self.flags(use_neutron=False) + self.flags(network_api_class='nova.network.neutronv2.api.API') + netapi = nova.network.API() + self.assertIsInstance(netapi, nova.network.neutronv2.api.API) diff --git a/nova/volume/__init__.py b/nova/volume/__init__.py index d447dfdb94ef..b57e84387954 100644 --- a/nova/volume/__init__.py +++ b/nova/volume/__init__.py @@ -18,10 +18,11 @@ import oslo_config.cfg from oslo_utils import importutils _volume_opts = [ - oslo_config.cfg.StrOpt('volume_api_class', - default='nova.volume.cinder.API', - help='The full class name of the ' - 'volume API class to use'), + oslo_config.cfg.StrOpt( + 'volume_api_class', + default='nova.volume.cinder.API', + help='DEPRECATED: The full class name of the volume API class to use', + deprecated_for_removal=True) ] oslo_config.cfg.CONF.register_opts(_volume_opts) diff --git a/releasenotes/notes/rm_volume_manager-78fed5be43d285b3.yaml b/releasenotes/notes/rm_volume_manager-78fed5be43d285b3.yaml new file mode 100644 index 000000000000..8f3e4927c7df --- /dev/null +++ b/releasenotes/notes/rm_volume_manager-78fed5be43d285b3.yaml @@ -0,0 +1,15 @@ +--- +upgrade: + + - A new ``use_neutron`` option is introduced which replaces the + obtuse ``network_api_class`` option. This defaults to 'False' to + match existing defaults, however if ``network_api_class`` is set + to the known Neutron value Neutron networking will still be used + as before. + +deprecations: + + - Deprecate ``volume_api_class`` and ``network_api_class`` config + options. We only have one sensible backend for either of + these. These options will be removed and turned into constants in + Newton.