ceph: log stderr in error when exec with output file

In order to properly debug errors, we need to merge stderr inside the
`err` reported so that we don't only see the stdout.
We were doing this when executing without file output, doing the same
for the output file.

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han committed 2020-10-07 14:47:09 +02:00
1 parent c95eaea1e0
commit 9b980d136f
1 file changed
+3
+3
View File
@@ -199,6 +199,9 @@ func (*CommandExecutor) ExecuteCommandWithOutputFile(command, outfileArg string,
// #nosec G204 Rook controls the input to the exec arguments
cmd := exec.Command(command, arg...)
cmdOut, err := cmd.CombinedOutput()
if err != nil {
cmdOut = []byte(fmt.Sprintf("%s. %s", string(cmdOut), string(err.(*exec.ExitError).Stderr)))
}
// if there was anything that went to stdout/stderr then log it, even before we return an error
if string(cmdOut) != "" {
logger.Debug(string(cmdOut))