Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ceph: allow '-' with -i and -o for stdin/stdout #16359

Merged
merged 1 commit into from Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions qa/workunits/cephtool/test.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
18 changes: 12 additions & 6 deletions src/ceph.in
Expand Up @@ -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')
Expand Down Expand Up @@ -964,16 +964,22 @@ 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

# 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
Expand Down Expand Up @@ -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:
Expand Down