]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph-daemon: add support for args and/or stdin from top of script
authorSage Weil <sage@redhat.com>
Thu, 3 Oct 2019 19:50:19 +0000 (14:50 -0500)
committerSage Weil <sage@redhat.com>
Sat, 5 Oct 2019 01:33:35 +0000 (20:33 -0500)
Allow someone to run this script by prepending injected_{args,stdin} to
the top and then piping it all to a python3 binary.

Signed-off-by: Sage Weil <sage@redhat.com>
src/ceph-daemon

index 59f8a46781e89f50dfca3c0ad146ab22ce584671..1fb71d0a53eb9a45c78708b903e98725cc0e1c53 100755 (executable)
@@ -6,6 +6,27 @@ LOG_DIR='/var/log/ceph'
 UNIT_DIR='/etc/systemd/system'
 VERSION='unknown development version'
 
+"""
+You can invoke ceph-daemon in two ways:
+
+1. The normal way, at the command line.
+
+2. By piping the script to the python3 binary.  In this latter case, you should
+   prepend one or more lines to the beginning of the script.
+
+   For arguments,
+
+       injected_argv = [...]
+
+   e.g.,
+
+       injected_argv = ['ls']
+
+   For reading stdin from the '--config-and-json -' argument,
+
+       injected_stdin = '...'
+"""
+
 import argparse
 import configparser
 import json
@@ -139,7 +160,10 @@ def get_config_and_keyring():
     if args.config_and_keyring:
         import json
         if args.config_and_keyring == '-':
-            j = sys.stdin.read()
+            try:
+                j = injected_stdin
+            except NameError:
+                j = sys.stdin.read()
         else:
             with open(args.config_and_keyring, 'r') as f:
                 j = f.read()
@@ -1194,8 +1218,13 @@ parser_deploy.add_argument(
     '--osd-fsid',
     help='OSD uuid, if creating an OSD container')
 
-args = parser.parse_args()
+# allow argv to be injected
+try:
+    av = injected_argv
+except NameError:
+    av = sys.argv[1:]
 
+args = parser.parse_args(av)
 if 'func' not in args:
     sys.stderr.write('No command specified; pass -h or --help for usage\n')
     sys.exit(1)