]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Execute mount.nfs check as root
authorTom Patzig <tom.patzig@sap.com>
Mon, 11 Jan 2016 19:55:01 +0000 (20:55 +0100)
committerTom Patzig <tom.patzig@sap.com>
Mon, 11 Jan 2016 20:04:51 +0000 (21:04 +0100)
Currently the existence of 'mount.nfs' is checked with a
non-root user, in this case cinder. This results, for example on SUSE,
in the error:

      NfsException: mount.nfs is not installed

Because mount.nfs is located under /sbin, unprivileged users do not
have /sbin in their PATH to search for executables.
This change switches the parameter run_as_root to true, to find
the binary in privileged directories, as well.

Change-Id: Id1dcc9a7653f1317532da2eb83aa1ecbb5cf5ec8
Closes-Bug: #1510150

cinder/tests/unit/test_nfs.py
cinder/volume/drivers/nfs.py

index 1f9e831e03006ac5853aec9919cfd0b6cad2708d..ca3724bb5003b71e0efc55354e2d1f97dd217d45 100644 (file)
@@ -1142,15 +1142,15 @@ class NfsDriverDoSetupTestCase(test.TestCase):
             errno.ENOENT, 'No such file or directory.')
 
         with self.assertRaisesRegex(exception.NfsException,
-                                    '/sbin/mount.nfs is not installed'):
+                                    'mount.nfs is not installed'):
             drv.do_setup(self.context)
 
         mock_os_path_exists.assert_has_calls(
             [mock.call(self.configuration.nfs_shares_config)])
         mock_execute.assert_has_calls(
-            [mock.call('/sbin/mount.nfs',
+            [mock.call('mount.nfs',
                        check_exit_code=False,
-                       run_as_root=False)])
+                       run_as_root=True)])
 
     def test_setup_should_throw_exception_if_mount_nfs_command_fails(self):
         """do_setup should throw error if mount.nfs fails with OSError
@@ -1172,9 +1172,9 @@ class NfsDriverDoSetupTestCase(test.TestCase):
         mock_os_path_exists.assert_has_calls(
             [mock.call(self.configuration.nfs_shares_config)])
         mock_execute.assert_has_calls(
-            [mock.call('/sbin/mount.nfs',
+            [mock.call('mount.nfs',
                        check_exit_code=False,
-                       run_as_root=False)])
+                       run_as_root=True)])
 
     @mock.patch.object(os, 'rename')
     def test_update_migrated_available_volume(self, rename_volume):
index 2201b06d8cf24f0d8e5f162610798ee89cc33bf8..4afc5162adb5013a8fdd85bb9ef459d6ced50a6f 100644 (file)
@@ -142,17 +142,13 @@ class NfsDriver(driver.ExtendVD, remotefs.RemoteFSDriver):
 
         self.shares = {}  # address : options
 
-        # Check if /sbin/mount.nfs is installed on this system;
-        # note that we don't need to be root, to see if the package
-        # is installed.
-        # We rely on the absolute path /sbin/mount.nfs; this seems to be
-        # common on most distributions (SUSE, RedHat, CentOS, Ubuntu, Debian)
-        # and it does not depend on correct PATH of the executing user,
-        # when trying to find the relative binary.
-        package = '/sbin/mount.nfs'
+        # Check if mount.nfs is installed on this system; note that we
+        # need to be root, to also find mount.nfs on distributions, where
+        # it is not located in an unprivileged users PATH (e.g. /sbin).
+        package = 'mount.nfs'
         try:
             self._execute(package, check_exit_code=False,
-                          run_as_root=False)
+                          run_as_root=True)
         except OSError as exc:
             if exc.errno == errno.ENOENT:
                 msg = _('%s is not installed') % package