]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove CONF from brick remotefs
authorChet Burgess <cfb@metacloud.com>
Thu, 26 Sep 2013 04:57:25 +0000 (21:57 -0700)
committerChet Burgess <cfb@metacloud.com>
Tue, 1 Oct 2013 23:24:16 +0000 (16:24 -0700)
Move the remotefs CONF options back into their
corresponding volume drivers.

Partial-Bug: #1230066
Change-Id: Ie37a803dc0f895ffd9dc2c7daf8255e6096ccee2

cinder/brick/remotefs/remotefs.py
cinder/tests/brick/test_brick_connector.py
cinder/tests/brick/test_brick_remotefs.py
cinder/tests/test_netapp_nfs.py
cinder/tests/test_nexenta.py
cinder/tests/test_nfs.py
cinder/volume/drivers/glusterfs.py
cinder/volume/drivers/nfs.py
etc/cinder/cinder.conf.sample

index 73e3c3ccae7ba56ee88a8a85a19e427ab1db64c3..e0fbd2bca5043ef45c2e66896bc0bc8725f7597c 100644 (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)
index 648efdeb9be5d9986542f691f45d8dbafbe95602..262ef66f9e8916697985d527777a7d7ee1cfb1c4 100644 (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()
index 7bd28e2a386c97aa62dcdb730c8d29055a3473e5..32ae8c447447824f182fd291d9fcd920c82df3a3 100644 (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)
index d92bd2a88e2f0c1c82eab378b650f9c6be86fe64..d87773aabbf047dc879bcab0d64ae554713cd2ec 100644 (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
index 0965cdcd075005a61ae54e68f32d0857da04de85..cdafafa5d54459bd9f34b7919a0d584da1ad0288 100644 (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())
index 25ce710fed639bd0e9bca4b5438c47a0fb9b101d..c221019021f1a26a9aae00117fbaacfb77dce745 100644 (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)
 
index 4ee4db4b1eb5b963878d2ae534f79e0d84db7534..bd4293fbe9e03f9c0427a26b2638b58b1c18e766 100644 (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):
index 10d204024f45d0fccf9ec6901afe46d819637a34..f85ca913c67fc107be723836a9fdf65b69d3206f 100644 (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)
index 801af9744009c3c3ed17940b9546aa2479203620..0d76d5a795b1aa9b9df88eac69c789b764006b48 100644 (file)
 #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
 #
 # (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
 # 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