Catch OSError thrown when hexdump is missing
Change c5bf7b088f
introduced
a new requirement via a pre-existing ironic-lib method being
called that utilizes hexdump. Hexdump is not always present
and since we did not explicitly call it out as a new
requirement, we should at least somewhat gracefully handle
the exception.
Change-Id: Id0223ef1417f6e419770ceb56b2a3b80c6118a85
Closes-Bug: #1732470
This commit is contained in:
@@ -154,9 +154,17 @@ def _message_format(msg, image_info, device, partition_uuids):
|
|||||||
result_msg = msg + 'root_uuid={}'
|
result_msg = msg + 'root_uuid={}'
|
||||||
message = result_msg.format(image_info['id'], device, root_uuid)
|
message = result_msg.format(image_info['id'], device, root_uuid)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
# NOTE(TheJulia): ironic-lib disk_utils.get_disk_identifier
|
||||||
|
# can raise OSError if hexdump is not found.
|
||||||
root_uuid = disk_utils.get_disk_identifier(device)
|
root_uuid = disk_utils.get_disk_identifier(device)
|
||||||
result_msg = msg + 'root_uuid={}'
|
result_msg = msg + 'root_uuid={}'
|
||||||
message = result_msg.format(image_info['id'], device, root_uuid)
|
message = result_msg.format(image_info['id'], device, root_uuid)
|
||||||
|
except OSError as e:
|
||||||
|
LOG.warning('Failed to call get_disk_identifier: '
|
||||||
|
'Unable to obtain the root_uuid parameter: '
|
||||||
|
'The hexdump tool may be missing in IPA: %s', e)
|
||||||
|
message = result_msg.format(image_info['id'], device)
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
|
@@ -887,6 +887,21 @@ class TestStandbyExtension(base.IronicAgentTest):
|
|||||||
'efi_system_partition_uuid=efi_id')
|
'efi_system_partition_uuid=efi_id')
|
||||||
self.assertEqual(expected_msg, result_msg)
|
self.assertEqual(expected_msg, result_msg)
|
||||||
|
|
||||||
|
@mock.patch('ironic_lib.disk_utils.get_disk_identifier',
|
||||||
|
autospec=True)
|
||||||
|
def test__message_format_whole_disk_missing_oserror(self,
|
||||||
|
ident_mock):
|
||||||
|
ident_mock.side_effect = OSError
|
||||||
|
image_info = _build_fake_image_info()
|
||||||
|
msg = 'image ({}) already present on device {}'
|
||||||
|
device = '/dev/fake'
|
||||||
|
partition_uuids = {}
|
||||||
|
result_msg = standby._message_format(msg, image_info,
|
||||||
|
device, partition_uuids)
|
||||||
|
expected_msg = ('image (fake_id) already present on device '
|
||||||
|
'/dev/fake')
|
||||||
|
self.assertEqual(expected_msg, result_msg)
|
||||||
|
|
||||||
|
|
||||||
class TestImageDownload(base.IronicAgentTest):
|
class TestImageDownload(base.IronicAgentTest):
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user