avocado.core.exceptions: Modifications to CmdError for serialization

In order to serialize the CmdError class, we need to
allow passing None command and CmdResult objects to
the class constructor.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 805abde1
...@@ -106,15 +106,18 @@ class TestWarn(TestBaseException): ...@@ -106,15 +106,18 @@ class TestWarn(TestBaseException):
class CmdError(Exception): class CmdError(Exception):
def __init__(self, command, result): def __init__(self, command=None, result=None):
self.command = command self.command = command
self.result = result self.result = result
def __str__(self): def __str__(self):
if self.result.exit_status is None: if self.result is not None:
msg = "Command '%s' failed and is not responding to signals" if self.result.exit_status is None:
msg %= self.command msg = "Command '%s' failed and is not responding to signals"
msg %= self.command
else:
msg = "Command '%s' failed (rc=%d)"
msg %= (self.command, self.result.exit_status)
return msg
else: else:
msg = "Command '%s' failed (rc=%d)" return "CmdError"
msg %= (self.command, self.result.exit_status)
return msg
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册