]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph: print command output to stdout even on error
authorSage Weil <sage@newdream.net>
Sat, 20 Feb 2021 16:58:47 +0000 (11:58 -0500)
committerNathan Cutler <ncutler@suse.com>
Thu, 8 Apr 2021 16:15:07 +0000 (18:15 +0200)
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>
(cherry picked from commit 9425eee579adc2408602fb1734dc5aecf58ee4f2)

Conflicts:
src/ceph.in
- nautilus has to support Python 2, so preserve the "u" prefix on the string
  literal

src/ceph.in

index 28562eccb3219cb44989bc3778fb04a339776d43..f281aa18a921507d30f19f8fdc2a21e71ad446c0 100755 (executable)
@@ -1213,18 +1213,6 @@ def main():
                               errno.errorcode.get(ret, 'Unknown'), outs),
                           file=sys.stderr)
 
-        if ret < 0:
-            ret = -ret
-            errstr = errno.errorcode.get(ret, 'Unknown')
-            print(u'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:
@@ -1250,12 +1238,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(u'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: