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:
Julia Kreger 2017-11-15 17:13:58 -05:00
parent bf3580e937
commit 71fda732d2
2 changed files with 26 additions and 3 deletions

View File

@ -154,9 +154,17 @@ def _message_format(msg, image_info, device, partition_uuids):
result_msg = msg + 'root_uuid={}'
message = result_msg.format(image_info['id'], device, root_uuid)
else:
root_uuid = disk_utils.get_disk_identifier(device)
result_msg = msg + 'root_uuid={}'
message = result_msg.format(image_info['id'], device, root_uuid)
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)
result_msg = msg + '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

View File

@ -887,6 +887,21 @@ class TestStandbyExtension(base.IronicAgentTest):
'efi_system_partition_uuid=efi_id')
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):