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: v16.2.8~186^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=55db6a9753aa6937ec7a78120680cfe5192f6478;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 (cherry picked from commit 110d294dc607ece48291d96bda08c5cce2c8ecd7) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index c49f0b55b37..f73ffc7f5e5 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -8542,11 +8542,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) @@ -8569,7 +8569,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: @@ -8582,11 +8581,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)