def execute_run(command, timeout=NODE_COMMAND_TIMEOUT, jsonresult=False,
catch_exitcodes=None):
try:
result = run(command, timeout=timeout)
except (CommandTimeout, NetworkError):
raise NodeCommandTimeoutError(
'Timeout reached while execute remote command'
)
if result.return_code != 0:
if not catch_exitcodes or result.return_code not in catch_exitcodes:
raise NodeCommandError(
'Remote command `{0}` execution failed (exit code = {1})'
.format(command, result.return_code)
)
raise NodeCommandWrongExitCode(code=result.return_code)
if jsonresult:
try:
result = json.loads(result)
except (ValueError, TypeError):
raise NodeCommandError(
u'Invalid json output of remote command: {}'.format(result))
return result
评论列表
文章目录