Merge "Scality SOFS: enhance how the remoteFS mount is detected"

This commit is contained in:
Jenkins 2015-07-08 13:48:44 +00:00 committed by Gerrit Code Review
commit 16eaa4d5e1
3 changed files with 29 additions and 13 deletions

View 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):

View File

@ -31,6 +31,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__)
@ -95,17 +96,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

View File

@ -526,3 +526,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()