]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fixing mount when state_path is configured with a final '/'
authorRushil Chugh <rushil@netapp.com>
Thu, 5 Mar 2015 22:16:26 +0000 (17:16 -0500)
committerRushil Chugh <rushil@netapp.com>
Tue, 17 Mar 2015 17:23:15 +0000 (17:23 +0000)
If state_path variable is configured with a final '/' on path, then
mount_path variable is created with wrong syntax. This causes
a failure when the c-vol process tries to mount the filesystem.

This patch proposes to fix the aforementioned problem by checking
the validity of the mount point and fixing the mount point in case
it has an incorrect value.

Closes-bug: 1425551

Change-Id: I9fe50fe07953fb5e94da467a7446528e5030e41b

cinder/tests/test_nfs.py
cinder/tests/volume/drivers/netapp/dataontap/test_nfs_base.py
cinder/volume/drivers/nfs.py

index ccd50711f959e40ed95eefe92dd0c087b8d6180d..594f24f50342e785c4d4c08c448c082503fdab5b 100644 (file)
@@ -346,6 +346,7 @@ class NfsDriverTestCase(test.TestCase):
     TEST_NFS_EXPORT2_OPTIONS = '-o intr'
     TEST_SIZE_IN_GB = 1
     TEST_MNT_POINT = '/mnt/nfs'
+    TEST_MNT_POINT_BASE_EXTRA_SLASH = '/opt/stack/data/cinder//mnt'
     TEST_MNT_POINT_BASE = '/mnt/test'
     TEST_LOCAL_PATH = '/mnt/nfs/volume-123'
     TEST_FILE_NAME = 'test.txt'
@@ -441,6 +442,22 @@ class NfsDriverTestCase(test.TestCase):
         self.assertEqual('/mnt/test/2f4f60214cf43c595666dd815f0360a4',
                          drv._get_mount_point_for_share(self.TEST_NFS_EXPORT1))
 
+    def test_get_mount_point_for_share_given_extra_slash_in_state_path(self):
+        """_get_mount_point_for_share should calculate correct value."""
+        # This test gets called with the extra slash
+        self.configuration.nfs_mount_point_base = (
+            self.TEST_MNT_POINT_BASE_EXTRA_SLASH)
+
+        # The driver gets called with the correct configuration and removes
+        # the extra slash
+        drv = nfs.NfsDriver(configuration=self.configuration)
+
+        self.assertEqual('/opt/stack/data/cinder/mnt', drv.base)
+
+        self.assertEqual(
+            '/opt/stack/data/cinder/mnt/2f4f60214cf43c595666dd815f0360a4',
+            drv._get_mount_point_for_share(self.TEST_NFS_EXPORT1))
+
     def test_get_capacity_info(self):
         """_get_capacity_info should calculate correct value."""
         mox = self._mox
index 1009777a81dbf77d6774c5ec4eb8c3969a2dd2a9..a8cac6d35dca7174132b98f360013208f41f70cf 100644 (file)
@@ -29,8 +29,10 @@ from cinder.volume.drivers import nfs
 class NetAppNfsDriverTestCase(test.TestCase):
     def setUp(self):
         super(NetAppNfsDriverTestCase, self).setUp()
+        configuration = mock.Mock()
+        configuration.nfs_mount_point_base = '/mnt/test'
 
-        kwargs = {'configuration': mock.Mock()}
+        kwargs = {'configuration': configuration}
 
         with mock.patch.object(utils, 'get_root_helper',
                                return_value=mock.Mock()):
index 627fbc344d8b5a0c5ceb34c56b58cfda58e20b19..706c212b61f9b2c2cf7ff0f37d5acd8461d813a1 100644 (file)
@@ -91,6 +91,7 @@ class NfsDriver(remotefs.RemoteFSDriver):
         self.base = getattr(self.configuration,
                             'nfs_mount_point_base',
                             CONF.nfs_mount_point_base)
+        self.base = os.path.realpath(self.base)
         opts = getattr(self.configuration,
                        'nfs_mount_options',
                        CONF.nfs_mount_options)