]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Scality SOFS: enhance how the remoteFS mount is detected
authorJordan Pittier <jordan.pittier@scality.com>
Thu, 4 Jun 2015 15:32:49 +0000 (17:32 +0200)
committerJordan Pittier <jordan.pittier@scality.com>
Thu, 18 Jun 2015 09:46:45 +0000 (11:46 +0200)
Previously we relied on a special "sys" dir being present at the root
of the mount point. This was weak. We now read the mount table and look
for a fuse-based FS mounted at the correct location.

Also, for the unit test, we slowly try to use mock instead of mox.

Change-Id: I055858e66db09fe7c5b1688c9fa05077948f342d

cinder/tests/unit/test_scality.py
cinder/volume/drivers/scality.py
cinder/volume/utils.py

index 3626803869f6dec14c34a7606907142f17dd45d8..52f93dd502bf9eb7deffbb7019ef6ed3390acb43 100644 (file)
@@ -86,7 +86,6 @@ class ScalityDriverTestCase(test.TestCase):
         open(self.TEST_CONFIG, "w+").close()
 
     def _create_fake_mount(self):
-        self._makedirs(os.path.join(self.TEST_MOUNT, 'sys'))
         self._makedirs(os.path.join(self.TEST_MOUNT, self.TEST_VOLDIR))
 
     def _remove_fake_config(self):
@@ -102,13 +101,6 @@ class ScalityDriverTestCase(test.TestCase):
         self.configuration.scality_sofs_volume_dir = self.TEST_VOLDIR
         self.configuration.volume_dd_blocksize = '1M'
 
-    def _execute_wrapper(self, cmd, *args, **kwargs):
-        try:
-            kwargs.pop('run_as_root')
-        except KeyError:
-            pass
-        utils.execute(cmd, *args, **kwargs)
-
     def _set_access_wrapper(self, is_visible):
 
         def _access_wrapper(path, flags):
@@ -139,7 +131,7 @@ class ScalityDriverTestCase(test.TestCase):
         super(ScalityDriverTestCase, self).setUp()
 
         self._driver = scality.ScalityDriver(configuration=self.configuration)
-        self._driver.set_execute(self._execute_wrapper)
+        self._driver.set_execute(lambda *args, **kwargs: None)
         self._create_fake_mount()
         self._create_fake_config()
         self.addCleanup(self._remove_fake_config)
@@ -167,7 +159,12 @@ class ScalityDriverTestCase(test.TestCase):
         self._set_access_wrapper(True)
         voldir_path = os.path.join(self.TEST_MOUNT, self.TEST_VOLDIR)
         os.rmdir(voldir_path)
-        self._driver.do_setup(None)
+        fake_mounts = [['tmpfs /dev/shm\n'],
+                       ['fuse ' + self.TEST_MOUNT + '\n']]
+        with mock.patch.object(scality.volume_utils, 'read_proc_mounts',
+                               side_effect=fake_mounts) as mock_get_mounts:
+            self._driver.do_setup(None)
+        self.assertEqual(2, mock_get_mounts.call_count)
         self.assertTrue(os.path.isdir(voldir_path))
 
     def test_local_path(self):
index d4edc0ea4baeeee6b91de3435c0208830d30edd4..ca355e32ffdac251e6d91279192a08a3cb33d596 100644 (file)
@@ -32,6 +32,7 @@ from cinder.image import image_utils
 from cinder.openstack.common import fileutils
 from cinder import utils
 from cinder.volume import driver
+from cinder.volume import utils as volume_utils
 
 
 LOG = logging.getLogger(__name__)
@@ -96,17 +97,25 @@ class ScalityDriver(driver.VolumeDriver):
     def _mount_sofs(self):
         config = self.configuration.scality_sofs_config
         mount_path = self.configuration.scality_sofs_mount_point
-        sysdir = os.path.join(mount_path, 'sys')
 
         fileutils.ensure_tree(mount_path)
-        if not os.path.isdir(sysdir):
+        if not self._sofs_is_mounted():
             self._execute('mount', '-t', 'sofs', config, mount_path,
                           run_as_root=True)
-        if not os.path.isdir(sysdir):
+        if not self._sofs_is_mounted():
             msg = _("Cannot mount Scality SOFS, check syslog for errors")
             LOG.warning(msg)
             raise exception.VolumeBackendAPIException(data=msg)
 
+    def _sofs_is_mounted(self):
+        mount_path = self.configuration.scality_sofs_mount_point.rstrip('/')
+        for mount in volume_utils.read_proc_mounts():
+            parts = mount.split()
+            if (parts[0].endswith('fuse') and
+                    parts[1].rstrip('/') == mount_path):
+                        return True
+        return False
+
     def _size_bytes(self, size_in_g):
         return int(size_in_g) * units.Gi
 
index aa14e7fc99e71f58d743be835df76596d86fda3d..ce31efe80ffae15b013342d56f518336c628c15a 100644 (file)
@@ -525,3 +525,13 @@ def matching_backend_name(src_volume_type, volume_type):
 
 def hosts_are_equivalent(host_1, host_2):
     return extract_host(host_1) == extract_host(host_2)
+
+
+def read_proc_mounts():
+    """Read the /proc/mounts file.
+
+    It's a dummy function but it eases the writing of unit tests as mocking
+    __builtin__open() for a specific file only is not trivial.
+    """
+    with open('/proc/mounts') as mounts:
+        return mounts.readlines()