Merge "Fix NFS "already mounted" detection"

This commit is contained in:
Zuul 2018-12-05 19:35:59 +00:00 committed by Gerrit Code Review
commit 96b993c1b2
2 changed files with 14 additions and 5 deletions

View File

@ -123,10 +123,15 @@ class RemoteFsClient(executor.Executor):
except processutils.ProcessExecutionError as exc:
if 'already mounted' in exc.stderr:
LOG.info("Already mounted: %s", share)
else:
LOG.error("Failed to mount %(share)s, reason: %(reason)s",
{'share': share, 'reason': exc.stderr})
raise
# The error message can say "busy or already mounted" when the
# share didn't actually mount, so look for it.
if share in self._read_mounts():
return
LOG.error("Failed to mount %(share)s, reason: %(reason)s",
{'share': share, 'reason': exc.stderr})
raise
def _mount_nfs(self, nfs_share, mount_path, flags=None):
"""Mount nfs share using present mount types."""

View File

@ -86,9 +86,13 @@ class RemoteFsClientTestCase(base.TestCase):
def test_mount_race(self, mock_execute):
err_msg = 'mount.nfs: /var/asdf is already mounted'
mock_execute.side_effect = putils.ProcessExecutionError(stderr=err_msg)
mounts = {'192.0.2.20:/share': '/var/asdf/'}
client = remotefs.RemoteFsClient("nfs", root_helper='true',
nfs_mount_point_base='/var/asdf')
client._do_mount('nfs', '192.0.2.20:/share', '/var/asdf')
with mock.patch.object(client, '_read_mounts',
return_value=mounts):
client._do_mount('nfs', '192.0.2.20:/share', '/var/asdf')
@mock.patch.object(priv_rootwrap, 'execute')
def test_mount_failure(self, mock_execute):