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
This commit is contained in:
Tom Patzig 2015-10-26 20:28:05 +01:00
parent 321c9c901d
commit 64172b01cd
2 changed files with 11 additions and 6 deletions

View 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)])

View 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)