From e4daac6012a0166b246c495e7fc915bccf47513f Mon Sep 17 00:00:00 2001 From: Jordan Pittier Date: Fri, 27 Nov 2015 18:32:21 +0100 Subject: [PATCH] Scality SOFS: don't always read /proc/mounts twice If the Scale Out FS is correcty mounted and found in /proc/mounts then there's no need to read /proc/mounts again. Change-Id: I8fa33cc80d2491d98986053f678cdf7983132bf9 --- cinder/tests/unit/test_scality.py | 15 +++++++++++++++ cinder/volume/drivers/scality.py | 9 +++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cinder/tests/unit/test_scality.py b/cinder/tests/unit/test_scality.py index c82cd9d65..59787d755 100644 --- a/cinder/tests/unit/test_scality.py +++ b/cinder/tests/unit/test_scality.py @@ -149,6 +149,21 @@ class ScalityDriverTestCase(test.TestCase): _FAKE_MNT_POINT) self.assertEqual(expected_args, mock_execute.call_args[0]) + @mock.patch("cinder.volume.utils.read_proc_mounts") + @mock.patch("oslo_concurrency.processutils.execute") + @mock.patch("oslo_utils.fileutils.ensure_tree", mock.Mock()) + @mock.patch("os.symlink", mock.Mock()) + def test_ensure_shares_mounted_when_sofs_mounted(self, mock_execute, + mock_read_proc_mounts): + mock_read_proc_mounts.return_value = _FAKE_MOUNTS_TABLE[1] + + self.drv._ensure_shares_mounted() + + # Because SOFS is mounted from the beginning, we shouldn't read + # /proc/mounts more than once. + mock_read_proc_mounts.assert_called_once_with() + self.assertFalse(mock_execute.called) + def test_find_share_when_no_shares_mounted(self): self.assertRaises(exception.RemoteFSNoSharesMounted, self.drv._find_share, 'ignored') diff --git a/cinder/volume/drivers/scality.py b/cinder/volume/drivers/scality.py index 046455570..64e4c9348 100644 --- a/cinder/volume/drivers/scality.py +++ b/cinder/volume/drivers/scality.py @@ -135,10 +135,11 @@ class ScalityDriver(remotefs_drv.RemoteFSSnapDriver): if not self._sofs_is_mounted(): self._execute('mount', '-t', 'sofs', self.sofs_config, self.sofs_mount_point, run_as_root=True) - if not self._sofs_is_mounted(): - msg = _("Cannot mount Scality SOFS, check syslog for errors") - LOG.error(msg) - raise exception.VolumeBackendAPIException(data=msg) + # Check whether the mount command succeeded + if not self._sofs_is_mounted(): + msg = _("Cannot mount Scality SOFS, check syslog for errors") + LOG.error(msg) + raise exception.VolumeBackendAPIException(data=msg) fileutils.ensure_tree(self.sofs_abs_volume_dir) -- 2.45.2