]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph: allow '-' with -i and -o for stdin/stdout 16359/head
authorSage Weil <sage@redhat.com>
Mon, 17 Jul 2017 13:38:52 +0000 (09:38 -0400)
committerSage Weil <sage@redhat.com>
Mon, 17 Jul 2017 13:38:52 +0000 (09:38 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
qa/workunits/cephtool/test.sh
src/ceph.in

index 2395f1baef73130ec70aec5c8a0ce94eb040717d..9586d81c0dfd92d3da1aee89193f9ccba7403965 100755 (executable)
@@ -2326,6 +2326,12 @@ function test_mon_tell_help_command()
   expect_false ceph tell mon.zzz help
 }
 
+function test_mon_stdin_stdout()
+{
+  echo foo | ceph config-key put test_key -i -
+  ceph config-key get test_key -o - | grep -c foo | grep -q 1
+}
+
 function test_osd_tell_help_command()
 {
   ceph tell osd.1 help
@@ -2411,6 +2417,7 @@ MON_TESTS+=" mon_deprecated_commands"
 MON_TESTS+=" mon_caps"
 MON_TESTS+=" mon_cephdf_commands"
 MON_TESTS+=" mon_tell_help_command"
+MON_TESTS+=" mon_stdin_stdout"
 
 OSD_TESTS+=" osd_bench"
 OSD_TESTS+=" osd_negative_filestore_merge_threshold"
index 6a6672a8592f0c14744169d61cd68f901eee0426..311ec64e65c9e4095ad7c5fcec1f66e9e98dec79 100755 (executable)
@@ -264,9 +264,9 @@ def parse_cmdargs(args=None, target=''):
     parser.add_argument('-c', '--conf', dest='cephconf',
                         help='ceph configuration file')
     parser.add_argument('-i', '--in-file', dest='input_file',
-                        help='input file')
+                        help='input file, or "-" for stdin')
     parser.add_argument('-o', '--out-file', dest='output_file',
-                        help='output file')
+                        help='output file, or "-" for stdout')
 
     parser.add_argument('--id', '--user', dest='client_id',
                         help='client id for authentication')
@@ -964,8 +964,11 @@ def main():
     inbuf = b''
     if parsed_args.input_file:
         try:
-            with open(parsed_args.input_file, 'rb') as f:
-                inbuf = f.read()
+            if parsed_args.input_file == '-':
+                inbuf = sys.stdin.read()
+            else:
+                with open(parsed_args.input_file, 'rb') as f:
+                    inbuf = f.read()
         except Exception as e:
             print('Can\'t open input file {0}: {1}'.format(parsed_args.input_file, e), file=sys.stderr)
             return 1
@@ -973,7 +976,10 @@ def main():
     # prepare output file, if any
     if parsed_args.output_file:
         try:
-            outf = open(parsed_args.output_file, 'wb')
+            if parsed_args.output_file == '-':
+                outf = sys.stdout
+            else:
+                outf = open(parsed_args.output_file, 'wb')
         except Exception as e:
             print('Can\'t open output file {0}: {1}'.format(parsed_args.output_file, e), file=sys.stderr)
             return 1
@@ -1099,7 +1105,7 @@ def main():
 
         sys.stdout.flush()
 
-    if parsed_args.output_file:
+    if parsed_args.output_file and parsed_args.output_file != '-':
         outf.close()
 
     if final_ret: