From: John Mulligan Date: Thu, 6 Jan 2022 21:26:37 +0000 (-0500) Subject: cephadm: split cli parsing & ctx setup from logging setup X-Git-Tag: v17.1.0~65^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=110d294dc607ece48291d96bda08c5cce2c8ecd7;p=ceph.git cephadm: split cli parsing & ctx setup from logging setup Split the parsing and processing of the CLI from the logging setup in the cephadm main func. Move logging setup to occur after we've determined that there's a runnable command func. This is preparatory work to allow running `cephadm --help` without being root. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 4a5d5ed4f65..2ea74ef1c01 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -8483,11 +8483,11 @@ def cephadm_init_ctx(args: List[str]) -> CephadmContext: return ctx -def cephadm_init(args: List[str]) -> CephadmContext: +def cephadm_init_logging(ctx: CephadmContext, args: List[str]) -> None: + """Configure the logging for cephadm as well as updating the system + to have the expected log dir and logrotate configuration. + """ global logger - ctx = cephadm_init_ctx(args) - - # Logger configuration if not os.path.exists(LOG_DIR): os.makedirs(LOG_DIR) dictConfig(logging_config) @@ -8510,7 +8510,6 @@ def cephadm_init(args: List[str]) -> CephadmContext: if handler.name == 'console': handler.setLevel(logging.DEBUG) logger.debug('%s\ncephadm %s' % ('-' * 80, args)) - return ctx def main() -> None: @@ -8523,11 +8522,12 @@ def main() -> None: av: List[str] = [] av = sys.argv[1:] - ctx = cephadm_init(av) + ctx = cephadm_init_ctx(av) if not ctx.has_function(): sys.stderr.write('No command specified; pass -h or --help for usage\n') sys.exit(1) + cephadm_init_logging(ctx, av) try: # podman or docker? ctx.container_engine = find_container_engine(ctx)