From c811d98c8b3991a9c298fce914f091b2a9ac215f Mon Sep 17 00:00:00 2001 From: Tom Patzig Date: Mon, 11 Jan 2016 20:55:01 +0100 Subject: [PATCH] Execute mount.nfs check as root 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 | 10 +++++----- cinder/volume/drivers/nfs.py | 14 +++++--------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/cinder/tests/unit/test_nfs.py b/cinder/tests/unit/test_nfs.py index 1f9e831e0..ca3724bb5 100644 --- a/cinder/tests/unit/test_nfs.py +++ b/cinder/tests/unit/test_nfs.py @@ -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): diff --git a/cinder/volume/drivers/nfs.py b/cinder/volume/drivers/nfs.py index 2201b06d8..4afc5162a 100644 --- a/cinder/volume/drivers/nfs.py +++ b/cinder/volume/drivers/nfs.py @@ -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 -- 2.45.2