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
This commit is contained in:
Sean Dague 2016-03-03 14:24:38 -05:00
parent 3be36fcb7b
commit 6e8e322718
4 changed files with 97 additions and 8 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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.