Do not silently swallow errors in the write_image deploy step

Calling join() does not raise, we need to explicitly check the result.

Change-Id: I81d3d727af220c2b50358edab8139f07874611f0
Story: #2008240
Task: #41083
This commit is contained in:
Dmitry Tantsur 2020-10-09 11:22:09 +02:00
parent bd127d193b
commit 420ebc0d73
4 changed files with 28 additions and 1 deletions

View File

@ -79,6 +79,17 @@ class BaseCommandResult(encoding.SerializableComparable):
""":returns: result of completed command."""
return self
def wait(self):
"""Join the result and extract its value.
Raises if the command failed.
"""
self.join()
if self.command_error is not None:
raise self.command_error
else:
return self.command_result
class SyncCommandResult(BaseCommandResult):
"""A result from a command that executes synchronously."""

View File

@ -2139,7 +2139,7 @@ class GenericHardwareManager(HardwareManager):
ext = ext_base.get_extension('standby')
cmd = ext.prepare_image(image_info=image_info, configdrive=configdrive)
# The result is asynchronous, wait here.
cmd.join()
return cmd.wait()
def generate_tls_certificate(self, ip_address):
"""Generate a TLS certificate for the IP address."""

View File

@ -149,6 +149,12 @@ class TestExtensionDecorators(test_base.IronicAgentTest):
result.command_result)
self.agent.force_heartbeat.assert_called_once_with()
def test_wait_async_command_success(self):
result = self.extension.execute('fake_async_command', param='v1')
self.assertIsInstance(result, base.AsyncCommandResult)
result = result.wait()
self.assertEqual({'result': 'fake_async_command: v1'}, result)
def test_async_command_success_without_agent(self):
extension = FakeExtension(agent=None)
result = extension.execute('fake_async_command', param='v1')
@ -182,6 +188,11 @@ class TestExtensionDecorators(test_base.IronicAgentTest):
self.assertIsNone(result.command_result)
self.agent.force_heartbeat.assert_called_once_with()
def test_wait_async_command_execution_failure(self):
result = self.extension.execute('fake_async_command', param='v2')
self.assertIsInstance(result, base.AsyncCommandResult)
self.assertRaises(ExecutionError, result.wait)
def test_async_command_name(self):
self.assertEqual(
'other_async_name',

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fixes the ``write_image`` deploy step to actually check and return any
errors during its execution.