From 4ed02984a3ac36b3c577870ea06bb4226c58a1d9 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 18 May 2023 16:14:24 -0400 Subject: [PATCH] cephadm: make the old command_deploy deprecated with decorator Add a deprecated command decorator. Decorate the old command_deploy with it. By default it just logs if a deprecated command was used, but custom builds of cephadm can set the NO_DEPRECATED var to True and fail if a deprecated command is used. Signed-off-by: John Mulligan --- src/cephadm/cephadm.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index e10621b16f41f..fda4bed863a80 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -89,6 +89,7 @@ DEFAULT_TIMEOUT = None # in seconds DEFAULT_RETRY = 15 DATEFMT = '%Y-%m-%dT%H:%M:%S.%fZ' QUIET_LOG_LEVEL = 9 # DEBUG is 10, so using 9 to be lower level than DEBUG +NO_DEPRECATED = False logger: logging.Logger = None # type: ignore @@ -2339,6 +2340,17 @@ def executes_early(func: FuncT) -> FuncT: return func +def deprecated_command(func: FuncT) -> FuncT: + @wraps(func) + def _deprecated_command(ctx: CephadmContext) -> Any: + logger.warning(f'Deprecated command used: {func}') + if NO_DEPRECATED: + raise Error('running deprecated commands disabled') + return func(ctx) + + return cast(FuncT, _deprecated_command) + + def get_container_info(ctx: CephadmContext, daemon_filter: str, by_name: bool) -> Optional[ContainerInfo]: """ :param ctx: Cephadm context @@ -6261,6 +6273,7 @@ def get_deployment_type(ctx: CephadmContext, daemon_type: str, daemon_id: str) - @default_image +@deprecated_command def command_deploy(ctx): # type: (CephadmContext) -> None daemon_type, daemon_id = ctx.name.split('.', 1) -- 2.39.5