From c2b458700a8fa23b271ce475b83fda31f73a016a Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 27 Sep 2019 09:50:40 -0500 Subject: [PATCH] ceph-daemon: add --config to bootstrap Settle on --config|-c too, not --conf. Signed-off-by: Sage Weil --- src/ceph-daemon | 39 +++++++++++++++++++++++++++------------ test_ceph_daemon.sh | 10 ++++++++-- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/ceph-daemon b/src/ceph-daemon index 222a8c2176f..1f8c1e8c519 100755 --- a/src/ceph-daemon +++ b/src/ceph-daemon @@ -7,6 +7,7 @@ UNIT_DIR='/etc/systemd/system' VERSION='unknown development version' import argparse +import configparser import json import logging import os @@ -15,6 +16,15 @@ import sys import tempfile from distutils.spawn import find_executable +try: + from StringIO import StringIO +except: + pass +try: + from io import StringIO +except: + pass + logging.basicConfig(level=logging.INFO) ################################## @@ -68,7 +78,6 @@ def check_unit(unit_name): def get_legacy_fsid(cluster): try: - import configparser config = configparser.ConfigParser() config.read('/etc/ceph/%s.conf' % cluster) if 'global' in config and 'fsid' in config['global']: @@ -107,12 +116,12 @@ def create_daemon_dirs(fsid, daemon_type, daemon_id, uid, gid, os.fchown(f.fileno(), uid, gid) def get_config_and_keyring(): - if args.conf_and_key: + if args.config_and_key: import json - if args.conf_and_key == '-': + if args.config_and_key == '-': j = sys.stdin.read() else: - with open(args.conf_and_key, 'r') as f: + with open(args.config_and_key, 'r') as f: j = f.read() d = json.loads(j) config = d.get('config') @@ -125,7 +134,7 @@ def get_config_and_keyring(): keyring = f.read() else: raise RuntimeError('no keyring') - with open(args.conf, 'r') as f: + with open(args.config, 'r') as f: config = f.read() return (config, keyring) @@ -428,13 +437,20 @@ def command_bootstrap(): tmp_keyring.flush() # config + cp = configparser.ConfigParser() + if args.config: + cp.read(args.config) if args.mon_ip: addr_arg = '[v2:%s:3300,v1:%s:6789]' % (args.mon_ip, args.mon_ip) elif args.mon_addrv: addr_arg = args.mon_addrv else: raise RuntimeError('must specify --mon-ip or --mon-addrv') - config = '[global]\n\tfsid = %s\n\tmon host = %s\n' % (fsid, addr_arg) + cp['global']['fsid'] = fsid; + cp['global']['mon host'] = addr_arg + with StringIO() as f: + cp.write(f) + config = f.getvalue() # create initial monmap, tmp monmap file tmp_monmap = tempfile.NamedTemporaryFile(mode='w') @@ -465,7 +481,6 @@ def command_bootstrap(): '-c', '/dev/null', '--monmap', '/tmp/monmap', '--keyring', '/tmp/keyring', - '--debug-mon', '20', ] + get_daemon_args(fsid, 'mon', mon_id), volume_mounts={ log_dir: '/var/log/ceph:z', @@ -627,9 +642,6 @@ parser.add_argument( '--image', default=DEFAULT_IMAGE, help='container image') -parser.add_argument( - '--conf', '-c', - help='ceph conf file to incorporate') parser.add_argument( '--data-dir', default=DATA_DIR, @@ -707,6 +719,9 @@ parser_shell.add_argument( parser_bootstrap = subparsers.add_parser( 'bootstrap', help='bootstrap a cluster (mon + mgr daemons)') parser_bootstrap.set_defaults(func=command_bootstrap) +parser_bootstrap.add_argument( + '--config', '-c', + help='ceph conf file to incorporate') parser_bootstrap.add_argument( '--mon-id', required=False, @@ -743,7 +758,7 @@ parser_deploy.add_argument( required=True, help='cluster FSID') parser_deploy.add_argument( - '--conf', + '--config', '-c', help='config file for new daemon') parser_deploy.add_argument( '--keyring', @@ -752,7 +767,7 @@ parser_deploy.add_argument( '--key', help='key for new daemon') parser_deploy.add_argument( - '--conf-and-key', + '--config-and-key', help='JSON file with config and key') parser_deploy.add_argument( '--mon-ip', diff --git a/test_ceph_daemon.sh b/test_ceph_daemon.sh index 9734305b41c..938874be9e3 100755 --- a/test_ceph_daemon.sh +++ b/test_ceph_daemon.sh @@ -4,11 +4,17 @@ fsid=0a464092-dfd0-11e9-b903-002590e526e8 ../src/ceph-daemon rm-cluster --fsid $fsid --force +cat < c +[global] +log to file = true +EOF + ../src/ceph-daemon bootstrap \ --mon-id a \ --mgr-id x \ --fsid $fsid \ --mon-ip 10.3.64.23 \ + --config c \ --output-keyring k \ --output-conf c chmod 644 k c @@ -18,7 +24,7 @@ chmod 644 k c --fsid $fsid \ --mon-ip 10.3.64.27 \ --keyring /var/lib/ceph/$fsid/mon.a/keyring \ - --conf c + --config c # mgr.b bin/ceph -c c -k k auth get-or-create mgr.y \ @@ -28,7 +34,7 @@ bin/ceph -c c -k k auth get-or-create mgr.y \ ../src/ceph-daemon deploy --name mgr.y \ --fsid $fsid \ --keyring k-mgr.y \ - --conf c + --config c bin/ceph -c c -k k -s -- 2.39.5