From: Rushil Chugh Date: Thu, 5 Mar 2015 22:16:26 +0000 (-0500) Subject: Fixing mount when state_path is configured with a final '/' X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ea2d255be4369b4f63312f371da4bb169859044d;p=openstack-build%2Fcinder-build.git Fixing mount when state_path is configured with a final '/' 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 --- diff --git a/cinder/tests/test_nfs.py b/cinder/tests/test_nfs.py index ccd50711f..594f24f50 100644 --- a/cinder/tests/test_nfs.py +++ b/cinder/tests/test_nfs.py @@ -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 diff --git a/cinder/tests/volume/drivers/netapp/dataontap/test_nfs_base.py b/cinder/tests/volume/drivers/netapp/dataontap/test_nfs_base.py index 1009777a8..a8cac6d35 100644 --- a/cinder/tests/volume/drivers/netapp/dataontap/test_nfs_base.py +++ b/cinder/tests/volume/drivers/netapp/dataontap/test_nfs_base.py @@ -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()): diff --git a/cinder/volume/drivers/nfs.py b/cinder/volume/drivers/nfs.py index 627fbc344..706c212b6 100644 --- a/cinder/volume/drivers/nfs.py +++ b/cinder/volume/drivers/nfs.py @@ -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)