SyncCommandResult should store actual exception

This commit changes ExecuteCommandMixin to store the
actual exception in SyncCommandResult instead of just
the message in the exception. This is required in the
API side where the result.command_error is trasformed
to base.ExceptionType.

Closes-bug: 1430896
Change-Id: I222bfc11868e73c7da03c84723f1450e38aa1a2f
This commit is contained in:
Ramakrishnan G 2015-03-11 00:17:50 +00:00
parent 8173927dd3
commit 1e04c8fffb
2 changed files with 6 additions and 9 deletions
ironic_python_agent
extensions
tests/extensions

@ -235,10 +235,7 @@ class ExecuteCommandMixin(object):
except Exception as e:
# Other errors are considered command execution errors, and are
# recorded as an
result = SyncCommandResult(command_name,
kwargs,
False,
six.text_type(e))
result = SyncCommandResult(command_name, kwargs, False, e)
self.command_results[result.id] = result
return result

@ -105,16 +105,16 @@ class TestExecuteCommandMixin(test_base.BaseTestCase):
'fake.sleep', sleep_info={"time": 1})
def test_execute_command_other_exception(self):
msg = 'foo bar baz'
fake_ext = self.agent.ext_mgr['fake'].obj
fake_ext.execute = mock.Mock()
fake_ext.execute.side_effect = Exception(msg)
exc = errors.CommandExecutionError('foo bar baz')
fake_ext.execute.side_effect = exc
result = self.agent.execute_command(
'fake.sleep', sleep_info={"time": 1}
)
self.assertEqual(result.command_status,
base.AgentCommandStatus.FAILED)
self.assertEqual(result.command_error, {'error': msg})
self.assertEqual(base.AgentCommandStatus.FAILED,
result.command_status)
self.assertEqual(exc, result.command_error)
class TestExtensionDecorators(test_base.BaseTestCase):