Merge "Fix exception catch when volume mount fails"

This commit is contained in:
Zuul 2023-08-25 10:44:22 +00:00 committed by Gerrit Code Review
commit 3a3a75698a
2 changed files with 27 additions and 1 deletions

View File

@ -580,6 +580,32 @@ class HostMountStateTestCase(test.NoDBTestCase):
mock_log.assert_called()
@mock.patch.object(mount.LOG, 'exception')
def test_mount_failure(self, mock_log_exc):
m = self._get_clean_hostmountstate()
err = processutils.ProcessExecutionError
self.mock_mount.side_effect = err
# Mount vol_a
self.assertRaises(err, self._sentinel_mount, m, mock.sentinel.vol_a)
# Verify the mountpoint got removed after the failure
self.assertEqual({}, m.mountpoints)
# Now try a scenario where the mount failed because the volume was
# already mounted
self.mock_ismount.side_effect = [False, True]
# Mount vol_a
self._sentinel_mount(m, mock.sentinel.vol_a)
# Verify the mountpoint is present despite the error
self.assertEqual(1, len(m.mountpoints))
self.assertIn(mock.sentinel.mountpoint, m.mountpoints)
# Verify we logged an exception
mock_log_exc.assert_called()
class MountManagerTestCase(test.NoDBTestCase):
class FakeHostMountState(object):

View File

@ -306,7 +306,7 @@ class _HostMountState(object):
try:
nova.privsep.fs.mount(fstype, export, mountpoint, options)
except processutils.ProcessExecutionError():
except processutils.ProcessExecutionError:
# Check to see if mountpoint is mounted despite the error
# eg it was already mounted
if os.path.ismount(mountpoint):