Skip to content

Commit baa0b4f

Browse files
committed
Fix exception catch when volume mount fails
When we call nova.privsep.fs.mount(), we are catching ProcessExecutionError() (an instance of a class) and that is not allowed in python3. This changes the except statement to catch ProcessExecutionError (class) instead. Closes-Bug: #1984736 Change-Id: I24a269f9809063f864a4f0443d6724dfa8703d9d (cherry picked from commit f996674)
1 parent a869ab1 commit baa0b4f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

nova/tests/unit/virt/libvirt/volume/test_mount.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,32 @@ def test_umount_log_failure(self, mock_log):
580580

581581
mock_log.assert_called()
582582

583+
@mock.patch.object(mount.LOG, 'exception')
584+
def test_mount_failure(self, mock_log_exc):
585+
m = self._get_clean_hostmountstate()
586+
err = processutils.ProcessExecutionError
587+
self.mock_mount.side_effect = err
588+
589+
# Mount vol_a
590+
self.assertRaises(err, self._sentinel_mount, m, mock.sentinel.vol_a)
591+
592+
# Verify the mountpoint got removed after the failure
593+
self.assertEqual({}, m.mountpoints)
594+
595+
# Now try a scenario where the mount failed because the volume was
596+
# already mounted
597+
self.mock_ismount.side_effect = [False, True]
598+
599+
# Mount vol_a
600+
self._sentinel_mount(m, mock.sentinel.vol_a)
601+
602+
# Verify the mountpoint is present despite the error
603+
self.assertEqual(1, len(m.mountpoints))
604+
self.assertIn(mock.sentinel.mountpoint, m.mountpoints)
605+
606+
# Verify we logged an exception
607+
mock_log_exc.assert_called()
608+
583609

584610
class MountManagerTestCase(test.NoDBTestCase):
585611
class FakeHostMountState(object):

nova/virt/libvirt/volume/mount.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def mount(self, fstype, export, vol_name, mountpoint, instance, options):
306306

307307
try:
308308
nova.privsep.fs.mount(fstype, export, mountpoint, options)
309-
except processutils.ProcessExecutionError():
309+
except processutils.ProcessExecutionError:
310310
# Check to see if mountpoint is mounted despite the error
311311
# eg it was already mounted
312312
if os.path.ismount(mountpoint):

0 commit comments

Comments
 (0)