Skip to content

Commit

Permalink
ceph: print command output to stdout even on error
Browse files Browse the repository at this point in the history
Currently in the case where the mon returns a command error code, we print
the error stream and Error ... message but not the command output.  Usually
there isn't any, so we haven't noticed until now, but there is not reason
why shouldn't return both an error code and some output.

Restructure the code so that the error message goes *after* the JSON output,
where it will be a bit more obvious to the user (if the stdout scrolled
the terminal, for instance).  (This is not a change in behavior since
previously we weren't seeing the stdout at all.)

Signed-off-by: Sage Weil <sage@newdream.net>
  • Loading branch information
liewegas committed Feb 26, 2021
1 parent 791952c commit 9425eee
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/ceph.in
Original file line number Diff line number Diff line change
Expand Up @@ -1250,18 +1250,6 @@ def main():
errno.errorcode.get(ret, 'Unknown'), outs),
file=sys.stderr)

if ret < 0:
ret = -ret
errstr = errno.errorcode.get(ret, 'Unknown')
print('Error {0}: {1}'.format(errstr, outs), file=sys.stderr)
if len(targets) > 1:
final_ret = ret
else:
return ret

if outs:
print(prefix + outs, file=sys.stderr)

sys.stdout.flush()

if parsed_args.output_file:
Expand All @@ -1287,12 +1275,23 @@ def main():
except IOError as e:
if e.errno != errno.EPIPE:
raise e
final_e = None
try:
sys.stdout.flush()
except IOError as e:
if e.errno != errno.EPIPE:
raise e
final_e = e

if ret < 0:
ret = -ret
errstr = errno.errorcode.get(ret, 'Unknown')
print('Error {0}: {1}'.format(errstr, outs), file=sys.stderr)
final_ret = ret
elif outs:
print(prefix + outs, file=sys.stderr)

if final_e:
raise final_e

# Block until command completion (currently scrub and deep_scrub only)
if block:
Expand Down

0 comments on commit 9425eee

Please sign in to comment.