Remove CONF from brick remotefs

Move the remotefs CONF options back into their
corresponding volume drivers.

Partial-Bug: #1230066
Change-Id: Ie37a803dc0f895ffd9dc2c7daf8255e6096ccee2
This commit is contained in:
Chet Burgess 2013-09-25 21:57:25 -07:00
parent a86e12aad5
commit 7dffd48672
9 changed files with 82 additions and 56 deletions

View File

@ -20,8 +20,6 @@
import hashlib
import os
from oslo.config import cfg
from cinder.brick import exception
from cinder.openstack.common.gettextutils import _
from cinder.openstack.common import log as logging
@ -29,22 +27,6 @@ from cinder.openstack.common import processutils as putils
LOG = logging.getLogger(__name__)
remotefs_client_opts = [
cfg.StrOpt('nfs_mount_point_base',
default='$state_path/mnt',
help='Base dir containing mount points for nfs shares'),
cfg.StrOpt('nfs_mount_options',
default=None,
help='Mount options passed to the nfs client. See section '
'of the nfs man page for details'),
cfg.StrOpt('glusterfs_mount_point_base',
default='$state_path/mnt',
help='Base dir containing mount points for gluster shares'),
]
CONF = cfg.CONF
CONF.register_opts(remotefs_client_opts)
class RemoteFsClient(object):
@ -53,10 +35,16 @@ class RemoteFsClient(object):
self._mount_type = mount_type
if mount_type == "nfs":
self._mount_base = CONF.nfs_mount_point_base
self._mount_options = CONF.nfs_mount_options
self._mount_base = kwargs.get('nfs_mount_point_base', None)
if not self._mount_base:
raise exception.InvalidParameterValue(
err=_('nfs_mount_point_base required'))
self._mount_options = kwargs.get('nfs_mount_options', None)
elif mount_type == "glusterfs":
self._mount_base = CONF.glusterfs_mount_point_base
self._mount_base = kwargs.get('glusterfs_mount_point_base', None)
if not self._mount_base:
raise exception.InvalidParameterValue(
err=_('glusterfs_mount_point_base required'))
self._mount_options = None
else:
raise exception.ProtocolNotSupported(protocol=mount_type)

View File

@ -65,10 +65,12 @@ class ConnectorTestCase(test.TestCase):
obj = connector.InitiatorConnector.factory('aoe', None)
self.assertEqual(obj.__class__.__name__, "AoEConnector")
obj = connector.InitiatorConnector.factory('nfs', None)
obj = connector.InitiatorConnector.factory(
'nfs', None, nfs_mount_point_base='/mnt/test')
self.assertEqual(obj.__class__.__name__, "RemoteFsConnector")
obj = connector.InitiatorConnector.factory('glusterfs', None)
obj = connector.InitiatorConnector.factory(
'glusterfs', None, glusterfs_mount_point_base='/mnt/test')
self.assertEqual(obj.__class__.__name__, "RemoteFsConnector")
obj = connector.InitiatorConnector.factory('local', None)
@ -563,9 +565,8 @@ class RemoteFsConnectorTestCase(ConnectorTestCase):
self.connection_properties = {
'export': self.TEST_DEV,
'name': '9c592d52-ce47-4263-8c21-4ecf3c029cdb'}
self.connector = connector.RemoteFsConnector('nfs', root_helper='sudo')
self.connector._remotefsclient._mount_options = None
self.connector._remotefsclient._mount_base = '/mnt/test'
self.connector = connector.RemoteFsConnector(
'nfs', root_helper='sudo', nfs_mount_point_base='/mnt/test')
def tearDown(self):
self.mox.VerifyAll()

View File

@ -34,9 +34,8 @@ class BrickRemoteFsTestCase(test.TestCase):
def setUp(self):
super(BrickRemoteFsTestCase, self).setUp()
self._mox = mox.Mox()
self._nfsclient = remotefs.RemoteFsClient('nfs', 'sudo')
self._nfsclient._mount_options = None
self._nfsclient._mount_base = self.TEST_MNT_BASE
self._nfsclient = remotefs.RemoteFsClient(
'nfs', 'sudo', nfs_mount_point_base=self.TEST_MNT_BASE)
self.addCleanup(self._mox.UnsetStubs)
def test_get_hash_str(self):
@ -80,3 +79,22 @@ class BrickRemoteFsTestCase(test.TestCase):
client.mount(self.TEST_EXPORT)
mox.VerifyAll()
def test_nfs_mount_options(self):
opts = 'test_nfs_mount_options'
client = remotefs.RemoteFsClient(
'nfs', 'sudo', nfs_mount_point_base=self.TEST_MNT_BASE,
nfs_mount_options=opts)
self.assertEqual(opts, client._mount_options)
def test_nfs_mount_point_base(self):
base = '/mnt/test/nfs/mount/point/base'
client = remotefs.RemoteFsClient('nfs', 'sudo',
nfs_mount_point_base=base)
self.assertEqual(base, client._mount_base)
def test_glusterfs_mount_point_base(self):
base = '/mnt/test/glusterfs/mount/point/base'
client = remotefs.RemoteFsClient('glusterfs', 'sudo',
glusterfs_mount_point_base=base)
self.assertEqual(base, client._mount_base)

View File

@ -33,12 +33,17 @@ from cinder.volume.drivers.netapp import api
from cinder.volume.drivers.netapp import nfs as netapp_nfs
from oslo.config import cfg
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
def create_configuration():
configuration = mox.MockObject(conf.Configuration)
configuration.append_config_values(mox.IgnoreArg())
configuration.nfs_mount_point_base = '/mnt/test'
configuration.nfs_mount_options = None
return configuration
@ -169,8 +174,7 @@ class NetappDirectCmodeNfsDriverTestCase(test.TestCase):
kwargs = {}
kwargs['netapp_mode'] = 'proxy'
kwargs['configuration'] = create_configuration()
self._driver = netapp_nfs.NetAppDirectCmodeNfsDriver(
**kwargs)
self._driver = netapp_nfs.NetAppDirectCmodeNfsDriver(**kwargs)
def test_check_for_setup_error(self):
mox = self.mox

View File

@ -381,12 +381,13 @@ class TestNexentaNfsDriver(test.TestCase):
def setUp(self):
super(TestNexentaNfsDriver, self).setUp()
self.stubs = stubout.StubOutForTesting()
self.configuration = mox_lib.MockObject(conf.Configuration)
self.configuration.nexenta_shares_config = None
self.configuration.nexenta_mount_point_base = '$state_path/mnt'
self.configuration.nexenta_sparsed_volumes = True
self.configuration.nexenta_volume_compression = 'on'
self.configuration.nfs_mount_point_base = '/mnt/test'
self.configuration.nfs_mount_options = None
self.nms_mock = self.mox.CreateMockAnything()
for mod in ('appliance', 'folder', 'server', 'volume', 'netstorsvc'):
setattr(self.nms_mock, mod, self.mox.CreateMockAnything())

View File

@ -135,10 +135,10 @@ class NfsDriverTestCase(test.TestCase):
self.configuration.nfs_sparsed_volumes = True
self.configuration.nfs_used_ratio = 0.95
self.configuration.nfs_oversub_ratio = 1.0
self.configuration.nfs_mount_point_base = self.TEST_MNT_POINT_BASE
self.configuration.nfs_mount_options = None
self._driver = nfs.NfsDriver(configuration=self.configuration)
self._driver.shares = {}
self._driver._remotefsclient._mount_options = None
self._driver._remotefsclient._mount_base = self.TEST_MNT_POINT_BASE
self.addCleanup(self.stubs.UnsetAll)
self.addCleanup(self._mox.UnsetStubs)

View File

@ -24,7 +24,6 @@ import time
from oslo.config import cfg
from cinder.brick.remotefs import remotefs
from cinder import compute
from cinder import db
from cinder import exception
@ -50,6 +49,9 @@ volume_opts = [
cfg.BoolOpt('glusterfs_qcow2_volumes',
default=False,
help=('Create volumes as QCOW2 files rather than raw files.')),
cfg.StrOpt('glusterfs_mount_point_base',
default='$state_path/mnt',
help='Base dir containing mount points for gluster shares.'),
]
CONF = cfg.CONF
@ -70,7 +72,6 @@ class GlusterfsDriver(nfs.RemoteFsDriver):
def __init__(self, *args, **kwargs):
super(GlusterfsDriver, self).__init__(*args, **kwargs)
self.configuration.append_config_values(volume_opts)
self.configuration.append_config_values(remotefs.remotefs_client_opts)
self._nova = None
def do_setup(self, context):

View File

@ -51,7 +51,14 @@ volume_opts = [
default=1.0,
help=('This will compare the allocated to available space on '
'the volume destination. If the ratio exceeds this '
'number, the destination will no longer be valid.'))
'number, the destination will no longer be valid.')),
cfg.StrOpt('nfs_mount_point_base',
default='$state_path/mnt',
help=('Base dir containing mount points for nfs shares.')),
cfg.StrOpt('nfs_mount_options',
default=None,
help=('Mount options passed to the nfs client. See section '
'of the nfs man page for details.')),
]
@ -64,6 +71,9 @@ class RemoteFsDriver(driver.VolumeDriver):
VERSION = "0.0.0"
def __init__(self, *args, **kwargs):
super(RemoteFsDriver, self).__init__(*args, **kwargs)
def check_for_setup_error(self):
"""Just to override parent behavior."""
pass
@ -361,8 +371,16 @@ class NfsDriver(RemoteFsDriver):
super(NfsDriver, self).__init__(*args, **kwargs)
self.configuration.append_config_values(volume_opts)
root_helper = utils.get_root_helper()
self._remotefsclient = remotefs.RemoteFsClient('nfs', root_helper,
execute=execute)
base = getattr(self.configuration,
'nfs_mount_point_base',
CONF.nfs_mount_point_base)
opts = getattr(self.configuration,
'nfs_mount_options',
CONF.nfs_mount_options)
self._remotefsclient = remotefs.RemoteFsClient(
'nfs', root_helper, execute=execute,
nfs_mount_point_base=base,
nfs_mount_options=opts)
def set_execute(self, execute):
super(NfsDriver, self).set_execute(execute)

View File

@ -268,23 +268,6 @@
#volumes_dir=$state_path/volumes
#
# Options defined in cinder.brick.remotefs.remotefs
#
# Base dir containing mount points for nfs shares (string
# value)
#nfs_mount_point_base=$state_path/mnt
# Mount options passed to the nfs client. See section of the
# nfs man page for details (string value)
#nfs_mount_options=<None>
# Base dir containing mount points for gluster shares (string
# value)
#glusterfs_mount_point_base=$state_path/mnt
#
# Options defined in cinder.common.config
#
@ -1193,6 +1176,10 @@
# (boolean value)
#glusterfs_qcow2_volumes=false
# Base dir containing mount points for gluster shares. (string
# value)
#glusterfs_mount_point_base=$state_path/mnt
#
# Options defined in cinder.volume.drivers.gpfs
@ -1409,6 +1396,14 @@
# destination will no longer be valid. (floating point value)
#nfs_oversub_ratio=1.0
# Base dir containing mount points for nfs shares. (string
# value)
#nfs_mount_point_base=$state_path/mnt
# Mount options passed to the nfs client. See section of the
# nfs man page for details. (string value)
#nfs_mount_options=<None>
#
# Options defined in cinder.volume.drivers.rbd