mock.patch.object(self._driver, '_execute'),
mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver'
'.read_proc_mount'),
- mock.patch('xattr.getxattr')
- ) as (mock_execute, mock_open, mock_getxattr):
+ ) as (mock_execute, mock_open):
# Content of /proc/mount (not mounted yet).
mock_open.return_value = StringIO.StringIO(
"/dev/sda5 / ext4 rw,relatime,data=ordered 0 0")
mount_call = mock.call(
'mount.quobyte', self.TEST_QUOBYTE_VOLUME,
self.TEST_MNT_POINT, run_as_root=False)
- mock_execute.assert_has_calls([mkdir_call, mount_call],
- any_order=False)
- mock_getxattr.assert_called_once_with(self.TEST_MNT_POINT,
- 'quobyte.info')
+
+ getfattr_call = mock.call(
+ 'getfattr', '-n', 'quobyte.info', self.TEST_MNT_POINT,
+ run_as_root=False)
+
+ mock_execute.assert_has_calls(
+ [mkdir_call, mount_call, getfattr_call], any_order=False)
def test_mount_quobyte_already_mounted_detected_seen_in_proc_mount(self):
with contextlib.nested(
mock.patch.object(self._driver, '_execute'),
mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver'
'.read_proc_mount'),
- mock.patch('xattr.getxattr')
- ) as (mock_execute, mock_open, mock_getxattr):
+ ) as (mock_execute, mock_open):
# Content of /proc/mount (already mounted).
mock_open.return_value = StringIO.StringIO(
"quobyte@%s %s fuse rw,nosuid,nodev,noatime,user_id=1000"
",group_id=100,default_permissions,allow_other 0 0"
% (self.TEST_QUOBYTE_VOLUME, self.TEST_MNT_POINT))
- mock_getxattr.return_value = "non-empty string"
self._driver._mount_quobyte(self.TEST_QUOBYTE_VOLUME,
self.TEST_MNT_POINT)
- self.assertFalse(mock_execute.called)
- mock_getxattr.assert_called_once_with(self.TEST_MNT_POINT,
- 'quobyte.info')
+ mock_execute.assert_called_once_with(
+ 'getfattr', '-n', 'quobyte.info', self.TEST_MNT_POINT,
+ run_as_root=False)
def test_mount_quobyte_should_suppress_and_log_already_mounted_error(self):
"""Based on /proc/mount, the file system is not mounted yet. However,
from oslo_concurrency import processutils
from oslo_config import cfg
-import xattr
from cinder import compute
from cinder import exception
-from cinder.i18n import _, _LE, _LI, _LW
+from cinder.i18n import _, _LI, _LW
from cinder.image import image_utils
from cinder.openstack.common import fileutils
from cinder.openstack.common import log as logging
raise
if mounted:
- try:
- xattr.getxattr(mount_path, 'quobyte.info')
- except Exception as exc:
- msg = _LE("The mount %(mount_path)s is not a valid"
- " Quobyte USP volume. Error: %(exc)s") \
- % {'mount_path': mount_path, 'exc': exc}
- raise exception.VolumeDriverException(msg)
- if not os.access(mount_path, os.W_OK | os.X_OK):
- LOG.warn(_LW("Volume is not writable. Please broaden the file"
- " permissions. Mount: %s"), mount_path)
+ self._validate_volume(mount_path)
+
+ def _validate_volume(self, mount_path):
+ """Wraps execute calls for checking validity of a Quobyte volume"""
+ command = ['getfattr', "-n", "quobyte.info", mount_path]
+ try:
+ self._execute(*command, run_as_root=False)
+ except processutils.ProcessExecutionError as exc:
+ msg = (_("The mount %(mount_path)s is not a valid"
+ " Quobyte USP volume. Error: %(exc)s")
+ % {'mount_path': mount_path, 'exc': exc})
+ raise exception.VolumeDriverException(msg)
+
+ if not os.access(mount_path, os.W_OK | os.X_OK):
+ LOG.warn(_LW("Volume is not writable. Please broaden the file"
+ " permissions. Mount: %s"), mount_path)