]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: start decorators.py in cephadmlib
authorAdam King <adking@redhat.com>
Fri, 15 Sep 2023 13:44:58 +0000 (09:44 -0400)
committerAdam King <adking@redhat.com>
Sun, 24 Sep 2023 13:44:27 +0000 (09:44 -0400)
Originally, wanted to move all the decorators into
their own files. Unfortunately, that isn't possible
at this time as most of them depend on things that
are still within cephadm.py This includes

list_daemons
_rm_cluster
is_fsid
termcolor
ContainerInfo
Ceph

and I'm sure I'm missing some others. We'll have to
revisit this again later when more of these things
have moved, or they can be slowly moved as their
dependencies are.

Signed-off-by: Adam King <adking@redhat.com>
src/cephadm/cephadm.py
src/cephadm/cephadmlib/decorators.py [new file with mode: 0644]

index ecbe6dcd46be6e1bbaec026cb8604a44a4d6715b..041babd683b9c0c2962e014511b1e5d198f1c6d3 100755 (executable)
@@ -77,7 +77,6 @@ from cephadmlib.constants import (
     LOGROTATE_DIR,
     LOG_DIR,
     LOG_DIR_MODE,
-    NO_DEPRECATED,
     PIDS_LIMIT_UNLIMITED_PODMAN_VERSION,
     SYSCTL_DIR,
     UNIT_DIR,
@@ -144,6 +143,11 @@ from cephadmlib.container_types import (
     InitContainer,
     is_container_running,
 )
+from cephadmlib.decorators import (
+    deprecated_command,
+    executes_early,
+    require_image
+)
 
 FuncT = TypeVar('FuncT', bound=Callable)
 
@@ -1636,19 +1640,6 @@ def infer_image(func: FuncT) -> FuncT:
     return cast(FuncT, _infer_image)
 
 
-def require_image(func: FuncT) -> FuncT:
-    """
-    Require the global --image flag to be set
-    """
-    @wraps(func)
-    def _require_image(ctx: CephadmContext) -> Any:
-        if not ctx.image:
-            raise Error('This command requires the global --image option to be set')
-        return func(ctx)
-
-    return cast(FuncT, _require_image)
-
-
 def default_image(func: FuncT) -> FuncT:
     @wraps(func)
     def _default_image(ctx: CephadmContext) -> Any:
@@ -1683,27 +1674,6 @@ def update_default_image(ctx: CephadmContext) -> None:
         ctx.image = _get_default_image(ctx)
 
 
-def executes_early(func: FuncT) -> FuncT:
-    """Decorator that indicates the command function is meant to have no
-    dependencies and no environmental requirements and can therefore be
-    executed as non-root and with no logging, etc. Commands that have this
-    decorator applied must be simple and self-contained.
-    """
-    cast(Any, func)._execute_early = True
-    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
diff --git a/src/cephadm/cephadmlib/decorators.py b/src/cephadm/cephadmlib/decorators.py
new file mode 100644 (file)
index 0000000..73d81d3
--- /dev/null
@@ -0,0 +1,47 @@
+# decorators.py - decorators used by cephadm and their helpers
+
+import logging
+from functools import wraps
+from typing import Any, Callable, TypeVar, cast
+
+from .context import CephadmContext
+from .constants import NO_DEPRECATED
+from .exceptions import Error
+
+FuncT = TypeVar('FuncT', bound=Callable)
+
+logger = logging.getLogger()
+
+
+def require_image(func: FuncT) -> FuncT:
+    """
+    Require the global --image flag to be set
+    """
+    @wraps(func)
+    def _require_image(ctx: CephadmContext) -> Any:
+        if not ctx.image:
+            raise Error('This command requires the global --image option to be set')
+        return func(ctx)
+
+    return cast(FuncT, _require_image)
+
+
+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 executes_early(func: FuncT) -> FuncT:
+    """Decorator that indicates the command function is meant to have no
+    dependencies and no environmental requirements and can therefore be
+    executed as non-root and with no logging, etc. Commands that have this
+    decorator applied must be simple and self-contained.
+    """
+    cast(Any, func)._execute_early = True
+    return func