]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: make the old command_deploy deprecated with decorator
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 18 May 2023 20:14:24 +0000 (16:14 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 15 Jun 2023 20:35:34 +0000 (16:35 -0400)
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 <jmulligan@redhat.com>
src/cephadm/cephadm.py

index 1dd12885c67a615507d107dc7fc6e5b19b77d831..847bb3f8e63b228d985a4642f0acda6fcf724766 100755 (executable)
@@ -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
 
@@ -2340,6 +2341,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
@@ -6226,6 +6238,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)