Improve error reporting for shell commands
Currently when a shell command fails, only the stdout is included in the error message. In some cases this is not useful because the relevant error information is in stderr. This change adds stderr to the error message so a user may have enough information to resolve the problem. Change-Id: I595f7fd1a398c453ddc7757c551625c5bfa88d3a Fixes: rhbz#1031786
This commit is contained in:
@@ -47,7 +47,9 @@ def execute(cmd, workdir=None, can_fail=True, mask_list=None,
|
||||
logging.debug(block_fmt % {'title': 'STDERR',
|
||||
'content': masked_err})
|
||||
if can_fail:
|
||||
msg = 'Failed to execute command: %s' % masked_out
|
||||
msg = ('Failed to execute command, '
|
||||
'stdout: %s\nstderr: %s' %
|
||||
(masked_out, masked_err))
|
||||
raise ExecuteRuntimeError(msg, stdout=out, stderr=err)
|
||||
return proc.returncode, out
|
||||
|
||||
@@ -102,7 +104,9 @@ class ScriptRunner(object):
|
||||
if re.search(pattern, err):
|
||||
raise NetworkError(masked_err, stdout=out, stderr=err)
|
||||
else:
|
||||
msg = 'Failed to run remote script: %s' % masked_out
|
||||
msg = ('Failed to run remote script, '
|
||||
'stdout: %s\nstderr: %s' %
|
||||
(masked_out, masked_err))
|
||||
raise ScriptRuntimeError(msg, stdout=out, stderr=err)
|
||||
return obj.returncode, out
|
||||
|
||||
|
||||
@@ -87,7 +87,8 @@ class ParameterTestCase(PackstackTestCaseMixin, TestCase):
|
||||
use_shell=True, mask_list=['password'])
|
||||
raise AssertionError('Masked execution failed.')
|
||||
except ExecuteRuntimeError, ex:
|
||||
should_be = ('Failed to execute command: mask the %s\n' % STR_MASK)
|
||||
should_be = ('Failed to execute command, stdout: mask the %s\n\n'
|
||||
'stderr: ' % STR_MASK)
|
||||
self.assertEqual(str(ex), should_be)
|
||||
|
||||
script = ScriptRunner()
|
||||
|
||||
Reference in New Issue
Block a user