From 110d294dc607ece48291d96bda08c5cce2c8ecd7 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 6 Jan 2022 16:26:37 -0500 Subject: [PATCH] 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 --- src/cephadm/cephadm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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) -- 2.39.5