From: Tom Patzig Date: Mon, 26 Oct 2015 19:28:05 +0000 (+0100) Subject: Execute mount.nfs check with absolute path X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=64172b01cd5d8eda3aa282262d7ca060066161d7;p=openstack-build%2Fcinder-build.git Execute mount.nfs check with absolute path 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 --- diff --git a/cinder/tests/unit/test_nfs.py b/cinder/tests/unit/test_nfs.py index 6af7f772f..3c8ce6c82 100644 --- a/cinder/tests/unit/test_nfs.py +++ b/cinder/tests/unit/test_nfs.py @@ -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)]) diff --git a/cinder/volume/drivers/nfs.py b/cinder/volume/drivers/nfs.py index 9aea7337f..c5ecf3407 100644 --- a/cinder/volume/drivers/nfs.py +++ b/cinder/volume/drivers/nfs.py @@ -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)