]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Execute mount.nfs check with absolute path
authorTom Patzig <tom.patzig@sap.com>
Mon, 26 Oct 2015 19:28:05 +0000 (20:28 +0100)
committerTom Patzig <tom.patzig@sap.com>
Wed, 4 Nov 2015 21:13:13 +0000 (22:13 +0100)
Currently the existence of mount.nfs is checked by executing
the relative binary 'mount.nfs' 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.
The change runs the mount.nfs check by using the absolute binary
path /sbin/mount.nfs. This seems to be common for most distributions
(SUSE, RedHat, CentOS, Ubuntu, Debian). The check can still be executed
as non privileged user, by not relying on correctly set PATH variable
and using the absolute path.

Change-Id: I3c1ecfdadd9ea492d58d69cbdf33045b002668c7
Closes-Bug: #1510150

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

index 6af7f772f426670c6b4ce826381f5186959ded69..3c8ce6c821f99af86c325a6d3a54e7a3b51ed07e 100644 (file)
@@ -1283,13 +1283,13 @@ class NfsDriverDoSetupTestCase(test.TestCase):
             errno.ENOENT, 'No such file or directory.')
 
         with self.assertRaisesRegex(exception.NfsException,
-                                    'mount.nfs is not installed'):
+                                    '/sbin/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('mount.nfs',
+            [mock.call('/sbin/mount.nfs',
                        check_exit_code=False,
                        run_as_root=False)])
 
@@ -1313,7 +1313,7 @@ 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('mount.nfs',
+            [mock.call('/sbin/mount.nfs',
                        check_exit_code=False,
                        run_as_root=False)])
 
index 9aea7337f921107eee87003a5e8ad8e4039dd4e9..c5ecf34074f35cabb40c4dd2fed19fdb69a2657e 100644 (file)
@@ -143,9 +143,14 @@ class NfsDriver(driver.ExtendVD, remotefs.RemoteFSDriver):
 
         self.shares = {}  # address : options
 
-        # Check if mount.nfs is installed on this system; note that we don't
-        # need to be root to see if the package is installed.
-        package = 'mount.nfs'
+        # 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'
         try:
             self._execute(package, check_exit_code=False,
                           run_as_root=False)