From: Chet Burgess Date: Thu, 26 Sep 2013 04:57:25 +0000 (-0700) Subject: Remove CONF from brick remotefs X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7dffd48672091c92d4c9a239fe41fd613b85348b;p=openstack-build%2Fcinder-build.git Remove CONF from brick remotefs Move the remotefs CONF options back into their corresponding volume drivers. Partial-Bug: #1230066 Change-Id: Ie37a803dc0f895ffd9dc2c7daf8255e6096ccee2 --- diff --git a/cinder/brick/remotefs/remotefs.py b/cinder/brick/remotefs/remotefs.py index 73e3c3cca..e0fbd2bca 100644 --- a/cinder/brick/remotefs/remotefs.py +++ b/cinder/brick/remotefs/remotefs.py @@ -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) diff --git a/cinder/tests/brick/test_brick_connector.py b/cinder/tests/brick/test_brick_connector.py index 648efdeb9..262ef66f9 100644 --- a/cinder/tests/brick/test_brick_connector.py +++ b/cinder/tests/brick/test_brick_connector.py @@ -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() diff --git a/cinder/tests/brick/test_brick_remotefs.py b/cinder/tests/brick/test_brick_remotefs.py index 7bd28e2a3..32ae8c447 100644 --- a/cinder/tests/brick/test_brick_remotefs.py +++ b/cinder/tests/brick/test_brick_remotefs.py @@ -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) diff --git a/cinder/tests/test_netapp_nfs.py b/cinder/tests/test_netapp_nfs.py index d92bd2a88..d87773aab 100644 --- a/cinder/tests/test_netapp_nfs.py +++ b/cinder/tests/test_netapp_nfs.py @@ -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 diff --git a/cinder/tests/test_nexenta.py b/cinder/tests/test_nexenta.py index 0965cdcd0..cdafafa5d 100644 --- a/cinder/tests/test_nexenta.py +++ b/cinder/tests/test_nexenta.py @@ -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()) diff --git a/cinder/tests/test_nfs.py b/cinder/tests/test_nfs.py index 25ce710fe..c22101902 100644 --- a/cinder/tests/test_nfs.py +++ b/cinder/tests/test_nfs.py @@ -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) diff --git a/cinder/volume/drivers/glusterfs.py b/cinder/volume/drivers/glusterfs.py index 4ee4db4b1..bd4293fbe 100644 --- a/cinder/volume/drivers/glusterfs.py +++ b/cinder/volume/drivers/glusterfs.py @@ -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): diff --git a/cinder/volume/drivers/nfs.py b/cinder/volume/drivers/nfs.py index 10d204024..f85ca913c 100644 --- a/cinder/volume/drivers/nfs.py +++ b/cinder/volume/drivers/nfs.py @@ -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) diff --git a/etc/cinder/cinder.conf.sample b/etc/cinder/cinder.conf.sample index 801af9744..0d76d5a79 100644 --- a/etc/cinder/cinder.conf.sample +++ b/etc/cinder/cinder.conf.sample @@ -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= - -# 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= + # # Options defined in cinder.volume.drivers.rbd