Raise on non-existing file in qemu_img_info

I'm not sure why we silence the exception, right now it causes us a very
hard to debug failure. No code in Ironic seems to rely on this behavior.

Change-Id: I3740b600c60ed1b39808d18af2b5074e7e07a149
This commit is contained in:
Dmitry Tantsur 2024-01-15 17:24:27 +01:00
parent 5e1ca2a437
commit 87a739fe17
No known key found for this signature in database
GPG Key ID: 315B2AF9FD216C60
2 changed files with 3 additions and 6 deletions

View File

@ -488,7 +488,7 @@ def dd(src, dst, conv_flags=None):
def qemu_img_info(path):
"""Return an object containing the parsed output from qemu-img info."""
if not os.path.exists(path):
return imageutils.QemuImgInfo()
raise FileNotFoundError(_("File %s does not exist") % path)
out, err = utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path,

View File

@ -603,13 +603,10 @@ class OtherFunctionTestCase(base.IronicLibTestCase):
disk_utils.is_block_device, device)
mock_os.assert_has_calls([mock.call(device)] * 2)
@mock.patch.object(imageutils, 'QemuImgInfo', autospec=True)
@mock.patch.object(os.path, 'exists', return_value=False, autospec=True)
def test_qemu_img_info_path_doesnt_exist(self, path_exists_mock,
qemu_img_info_mock):
disk_utils.qemu_img_info('noimg')
def test_qemu_img_info_path_doesnt_exist(self, path_exists_mock):
self.assertRaises(FileNotFoundError, disk_utils.qemu_img_info, 'noimg')
path_exists_mock.assert_called_once_with('noimg')
qemu_img_info_mock.assert_called_once_with()
@mock.patch.object(utils, 'execute', return_value=('out', 'err'),
autospec=True)