]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
quobyte: remove dependency to xattr
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Tue, 10 Feb 2015 15:43:21 +0000 (16:43 +0100)
committerMarc Koderer <marc@koderer.com>
Wed, 11 Feb 2015 08:29:05 +0000 (09:29 +0100)
The Quobyte driver introduced an new dependency to xattr
python binding. This driver is the only consumer of xattr.

Instead of introducing new dependencies call getfattr binary
as already done in the quobyte nova volume driver.

Closes-Bug: 1420332
Co-Authored-By: Marc Koderer <marc@koderer.com>
Change-Id: I83f97310313cf7a603996ae64327002cdf0ad5fc
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
cinder/tests/test_quobyte.py
cinder/volume/drivers/quobyte.py
requirements.txt

index d4f0547c6172830954ab4992b9c87aeb032ca401..90b73f7e81450d3264ed9b68fc52904a147edd0c 100644 (file)
@@ -130,8 +130,7 @@ class QuobyteDriverTestCase(test.TestCase):
                 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")
@@ -144,31 +143,32 @@ class QuobyteDriverTestCase(test.TestCase):
             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,
index 2119a0d78f99b19719af8424caf2ecb3d976dbaa..caf3a78e261a719b10b9bac2dc91cc65b95abbdd 100644 (file)
@@ -19,11 +19,10 @@ import os
 
 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
@@ -418,13 +417,19 @@ class QuobyteDriver(remotefs_drv.RemoteFSSnapDriver):
                     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)
index 26c1227f226ed885334b3bd56d326a59b615d9e0..7e53a3f7b5ba4d864d69bec54726eaadda6535f0 100644 (file)
@@ -44,4 +44,3 @@ WebOb>=1.2.3
 wsgiref>=0.1.2
 oslo.i18n>=1.3.0  # Apache-2.0
 oslo.vmware>=0.9.0                      # Apache-2.0
-xattr>=0.4