cinder/cinder/tests/unit/test_volume_configuration.py
Patrick East 76016fffc9 Add support for shared "backend_defaults" config
This gives a new config section that is shared for
all enabled_backends in a cinder.conf. This is optional
but can be used like:

[DEFAULT]
...
enabled_backends=lvm-1,lvm-2
...

[backend_defaults]
image_volume_cache_enabled = True
volume_clear = none
iscsi_helper = tgtadm
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver

[lvm-1]
volume_group = stack-volumes-lvm-1

[lvm-2]
volume_group = stack-volumes-lvmd-2
lvm_type = thin

This also sets up the config helper to be easily
refactored to remove support for DEFAULT stanza
configured backends.

DocImpact: Need to document upgrade path and new
recommended config.
Implements: blueprint shared-backend-config
Change-Id: I2f94118b32076f264b3cf21caa259785fd415167
2017-07-11 18:58:58 +00:00

86 lines
3.1 KiB
Python

# Copyright (c) 2012 Rackspace Hosting
# All Rights Reserved.
#
# 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.
"""Tests for the configuration wrapper in volume drivers."""
from oslo_config import cfg
from cinder import test
from cinder.volume import configuration
volume_opts = [
cfg.StrOpt('str_opt', default='STR_OPT'),
cfg.BoolOpt('bool_opt', default=False)
]
more_volume_opts = [
cfg.IntOpt('int_opt', default=1),
]
CONF = cfg.CONF
CONF.register_opts(volume_opts)
CONF.register_opts(more_volume_opts)
class VolumeConfigurationTest(test.TestCase):
def test_group_grafts_opts(self):
c = configuration.Configuration(volume_opts, config_group='foo')
self.assertEqual(c.str_opt, 'STR_OPT')
self.assertEqual(c.bool_opt, False)
self.assertEqual(c.str_opt, CONF.backend_defaults.str_opt)
self.assertEqual(c.bool_opt, CONF.backend_defaults.bool_opt)
self.assertIsNone(CONF.foo.str_opt)
self.assertIsNone(CONF.foo.bool_opt)
def test_opts_no_group(self):
c = configuration.Configuration(volume_opts)
self.assertEqual(c.str_opt, CONF.str_opt)
self.assertEqual(c.bool_opt, CONF.bool_opt)
def test_grafting_multiple_opts(self):
c = configuration.Configuration(volume_opts, config_group='foo')
c.append_config_values(more_volume_opts)
self.assertEqual(c.str_opt, 'STR_OPT')
self.assertEqual(c.bool_opt, False)
self.assertEqual(c.int_opt, 1)
# We get the right values, but they are coming from the backend_default
# group of CONF no the 'foo' one.
self.assertEqual(c.str_opt, CONF.backend_defaults.str_opt)
self.assertEqual(c.bool_opt, CONF.backend_defaults.bool_opt)
self.assertEqual(c.int_opt, CONF.backend_defaults.int_opt)
self.assertIsNone(CONF.foo.str_opt)
self.assertIsNone(CONF.foo.bool_opt)
self.assertIsNone(CONF.foo.int_opt)
def test_safe_get(self):
c = configuration.Configuration(volume_opts, config_group='foo')
self.assertIsNone(c.safe_get('none_opt'))
def test_backend_specific_value(self):
c = configuration.Configuration(volume_opts, config_group='foo')
# Set some new non-default value
CONF.set_override('str_opt', 'bar', group='backend_defaults')
actual_value = c.str_opt
self.assertEqual('bar', actual_value)
CONF.set_override('str_opt', 'notbar', group='foo')
actual_value = c.str_opt
# Make sure that we pick up the backend value and not the shared group
# value...
self.assertEqual('notbar', actual_value)