From: Ricardo Marques Date: Fri, 24 Apr 2020 09:59:21 +0000 (+0100) Subject: cephadm: Infer config on "cephadm shell" X-Git-Tag: v15.2.4~13^2~3^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ae9fc2587cc8e596f62ae31fe9a97c21021d3dc2;p=ceph.git cephadm: Infer config on "cephadm shell" Fixes: https://tracker.ceph.com/issues/44792 Signed-off-by: Ricardo Marques (cherry picked from commit eb732dcbc5afd0218849afbf70c09a7f9c06d731) --- diff --git a/doc/cephadm/install.rst b/doc/cephadm/install.rst index 36aea18b6341..81779ab64cf0 100644 --- a/doc/cephadm/install.rst +++ b/doc/cephadm/install.rst @@ -114,10 +114,12 @@ host. However, we recommend enabling easy access to the the ``ceph`` command. There are several ways to do this: * The ``cephadm shell`` command launches a bash shell in a container - with all of the Ceph packages installed. By default, if + with all of the Ceph packages installed. By default, if configuration and keyring files are found in ``/etc/ceph`` on the host, they are passed into the container environment so that the - shell is fully functional:: + shell is fully functional. Note that when executed on a MON host, + ``cephadm shell`` will infer the ``config`` from the MON container + instead of using the default configuration:: # cephadm shell diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index aaf4386cc017..7c4dc03eb54c 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -1080,6 +1080,36 @@ def infer_fsid(func): return _infer_fsid +def infer_config(func): + """ + If we find a MON daemon, use the config from that container + """ + @wraps(func) + def _infer_config(): + if args.config: + logger.debug('Using specified config: %s' % args.config) + return func() + config = None + if args.fsid: + name = args.name + if not name: + daemon_list = list_daemons(detail=False) + for daemon in daemon_list: + if daemon['name'].startswith('mon.'): + name = daemon['name'] + break + if name: + config = '/var/lib/ceph/{}/{}/config'.format(args.fsid, name) + if config: + logger.info('Inferring config %s' % config) + args.config = config + elif os.path.exists(SHELL_DEFAULT_CONF): + logger.debug('Using default config: %s' % SHELL_DEFAULT_CONF) + args.config = SHELL_DEFAULT_CONF + return func() + + return _infer_config + def _get_default_image(): if DEFAULT_IMAGE_IS_MASTER: yellow = '\033[93m' @@ -2716,6 +2746,7 @@ def command_run(): ################################## @infer_fsid +@infer_config @infer_image def command_shell(): # type: () -> int @@ -2737,8 +2768,6 @@ def command_shell(): # use /etc/ceph files by default, if present. we do this instead of # making these defaults in the arg parser because we don't want an error # if they don't exist. - if not args.config and os.path.exists(SHELL_DEFAULT_CONF): - args.config = SHELL_DEFAULT_CONF if not args.keyring and os.path.exists(SHELL_DEFAULT_KEYRING): args.keyring = SHELL_DEFAULT_KEYRING