Skip to content

Commit

Permalink
Remove CONF from brick remotefs
Browse files Browse the repository at this point in the history
Move the remotefs CONF options back into their
corresponding volume drivers.

Partial-Bug: #1230066
Change-Id: Ie37a803dc0f895ffd9dc2c7daf8255e6096ccee2
  • Loading branch information
Chet Burgess committed Oct 1, 2013
1 parent a86e12a commit 7dffd48
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 56 deletions.
30 changes: 9 additions & 21 deletions cinder/brick/remotefs/remotefs.py
Expand Up @@ -20,31 +20,13 @@
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
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):

Expand All @@ -53,10 +35,16 @@ def __init__(self, mount_type, root_helper,

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)
Expand Down
11 changes: 6 additions & 5 deletions cinder/tests/brick/test_brick_connector.py
Expand Up @@ -65,10 +65,12 @@ def test_factory(self):
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)
Expand Down Expand Up @@ -563,9 +565,8 @@ def setUp(self):
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()
Expand Down
24 changes: 21 additions & 3 deletions cinder/tests/brick/test_brick_remotefs.py
Expand Up @@ -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):
Expand Down Expand Up @@ -80,3 +79,22 @@ def test_mount_nfs_should_not_remount(self):
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)
8 changes: 6 additions & 2 deletions cinder/tests/test_netapp_nfs.py
Expand Up @@ -33,12 +33,17 @@
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


Expand Down Expand Up @@ -169,8 +174,7 @@ def _custom_setup(self):
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
Expand Down
3 changes: 2 additions & 1 deletion cinder/tests/test_nexenta.py
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions cinder/tests/test_nfs.py
Expand Up @@ -135,10 +135,10 @@ def setUp(self):
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)

Expand Down
5 changes: 3 additions & 2 deletions cinder/volume/drivers/glusterfs.py
Expand Up @@ -24,7 +24,6 @@

from oslo.config import cfg

from cinder.brick.remotefs import remotefs
from cinder import compute
from cinder import db
from cinder import exception
Expand All @@ -50,6 +49,9 @@
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
Expand All @@ -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):
Expand Down
24 changes: 21 additions & 3 deletions cinder/volume/drivers/nfs.py
Expand Up @@ -51,7 +51,14 @@
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.')),
]


Expand All @@ -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
Expand Down Expand Up @@ -361,8 +371,16 @@ def __init__(self, execute=putils.execute, *args, **kwargs):
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)
Expand Down
29 changes: 12 additions & 17 deletions etc/cinder/cinder.conf.sample
Expand Up @@ -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
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7dffd48

Please sign in to comment.