iso-wrapper: Capture debug information for mounting
Occasionally we have seen the mount command fail. The default error message says to set some environment variables and try again. We can just always set the environment and only print the output on failure. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
77ee882c21
commit
63c0bbc5c9
@ -411,7 +411,15 @@ def mount(image, logger=None):
|
||||
# use guestmount to mount the image, which doesn't require root privileges
|
||||
# LIBGUESTFS_BACKEND=direct: running qemu directly without libvirt
|
||||
with util.temp_dir(prefix='iso-mount-') as mount_dir:
|
||||
run(["LIBGUESTFS_BACKEND=direct", "guestmount", "-a", image, "-m", "/dev/sda", mount_dir])
|
||||
env = {'LIBGUESTFS_BACKEND': 'direct', 'LIBGUESTFS_DEBUG': '1', 'LIBGUESTFS_TRACE': '1'}
|
||||
cmd = ["guestmount", "-a", image, "-m", "/dev/sda", mount_dir]
|
||||
ret, out = run(cmd, env=env, can_fail=True)
|
||||
if ret != 0:
|
||||
# The mount command failed, something is wrong. Log the output and raise an exception.
|
||||
if logger:
|
||||
logger.log_error('Command %s exited with %s and output:\n%s'
|
||||
% (cmd, ret, out))
|
||||
raise RuntimeError('Failed to mount %s' % image)
|
||||
try:
|
||||
yield mount_dir
|
||||
finally:
|
||||
|
@ -41,6 +41,7 @@ class TestIsoUtils(unittest.TestCase):
|
||||
@mock.patch('pungi.util.run_unmount_cmd')
|
||||
@mock.patch('pungi.wrappers.iso.run')
|
||||
def test_mount_iso(self, mock_run, mock_unmount):
|
||||
mock_run.return_value = (0, '')
|
||||
with iso.mount('dummy') as temp_dir:
|
||||
self.assertTrue(os.path.isdir(temp_dir))
|
||||
self.assertEqual(len(mock_run.call_args_list), 1)
|
||||
@ -50,6 +51,7 @@ class TestIsoUtils(unittest.TestCase):
|
||||
@mock.patch('pungi.util.run_unmount_cmd')
|
||||
@mock.patch('pungi.wrappers.iso.run')
|
||||
def test_mount_iso_always_unmounts(self, mock_run, mock_unmount):
|
||||
mock_run.return_value = (0, '')
|
||||
try:
|
||||
with iso.mount('dummy') as temp_dir:
|
||||
self.assertTrue(os.path.isdir(temp_dir))
|
||||
@ -59,3 +61,15 @@ class TestIsoUtils(unittest.TestCase):
|
||||
self.assertEqual(len(mock_run.call_args_list), 1)
|
||||
self.assertEqual(len(mock_unmount.call_args_list), 1)
|
||||
self.assertFalse(os.path.isdir(temp_dir))
|
||||
|
||||
@mock.patch('pungi.util.run_unmount_cmd')
|
||||
@mock.patch('pungi.wrappers.iso.run')
|
||||
def test_mount_iso_raises_on_error(self, mock_run, mock_unmount):
|
||||
log = mock.Mock()
|
||||
mock_run.return_value = (1, 'Boom')
|
||||
with self.assertRaises(RuntimeError):
|
||||
with iso.mount('dummy', logger=log) as temp_dir:
|
||||
self.assertTrue(os.path.isdir(temp_dir))
|
||||
self.assertEqual(len(mock_run.call_args_list), 1)
|
||||
self.assertEqual(len(mock_unmount.call_args_list), 0)
|
||||
self.assertEqual(len(log.mock_calls), 1)
|
||||
|
Loading…
Reference in New Issue
Block a user