]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/cephadm: move `forall_hosts()` to utils module
authorSebastian Wagner <sebastian.wagner@suse.com>
Wed, 22 Jul 2020 12:39:26 +0000 (14:39 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Wed, 22 Jul 2020 12:45:35 +0000 (14:45 +0200)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/utils.py

index f395096a5ad8fc4001ab75d4c969cd3346ee3de4..b4d461e9eb401c06ca211d83bf9cc7338050e0a9 100644 (file)
@@ -45,6 +45,7 @@ from .schedule import HostAssignment, HostPlacementSpec
 from .inventory import Inventory, SpecStore, HostCache, EventStore
 from .upgrade import CEPH_UPGRADE_ORDER, CephadmUpgrade
 from .template import TemplateMgr
+from .utils import forall_hosts
 
 try:
     import remoto
@@ -86,37 +87,6 @@ CEPH_DATEFMT = '%Y-%m-%dT%H:%M:%S.%fZ'
 CEPH_TYPES = set(CEPH_UPGRADE_ORDER)
 
 
-def forall_hosts(f: Callable[..., T]) -> Callable[..., List[T]]:
-    @wraps(f)
-    def forall_hosts_wrapper(*args) -> List[T]:
-
-        # Some weired logic to make calling functions with multiple arguments work.
-        if len(args) == 1:
-            vals = args[0]
-            self = None
-        elif len(args) == 2:
-            self, vals = args
-        else:
-            assert 'either f([...]) or self.f([...])'
-
-        def do_work(arg):
-            if not isinstance(arg, tuple):
-                arg = (arg, )
-            try:
-                if self:
-                    return f(self, *arg)
-                return f(*arg)
-            except Exception as e:
-                logger.exception(f'executing {f.__name__}({args}) failed.')
-                raise
-
-        assert CephadmOrchestrator.instance is not None
-        return CephadmOrchestrator.instance._worker_pool.map(do_work, vals)
-
-
-    return forall_hosts_wrapper
-
-
 class CephadmCompletion(orchestrator.Completion):
     def evaluate(self):
         self.finalize(None)
index 4000a3329fc854511d5b4a1887212c4619497981..a933fbc6dd76ca4a3b0a1e56d949685d816743da 100644 (file)
@@ -1,8 +1,13 @@
-import re
+import logging
+from functools import wraps
+from typing import Optional, Callable, TypeVar, List
 
 from orchestrator import OrchestratorError
 
-from typing import Optional
+
+T = TypeVar('T')
+logger = logging.getLogger(__name__)
+
 
 def name_to_config_section(name: str) -> str:
     """
@@ -37,3 +42,35 @@ def name_to_auth_entity(daemon_type,  # type: str
         return daemon_type + "." + daemon_id
     else:
         raise OrchestratorError("unknown auth entity name")
+
+
+def forall_hosts(f: Callable[..., T]) -> Callable[..., List[T]]:
+    @wraps(f)
+    def forall_hosts_wrapper(*args) -> List[T]:
+        from cephadm.module import CephadmOrchestrator
+
+        # Some weired logic to make calling functions with multiple arguments work.
+        if len(args) == 1:
+            vals = args[0]
+            self = None
+        elif len(args) == 2:
+            self, vals = args
+        else:
+            assert 'either f([...]) or self.f([...])'
+
+        def do_work(arg):
+            if not isinstance(arg, tuple):
+                arg = (arg, )
+            try:
+                if self:
+                    return f(self, *arg)
+                return f(*arg)
+            except Exception as e:
+                logger.exception(f'executing {f.__name__}({args}) failed.')
+                raise
+
+        assert CephadmOrchestrator.instance is not None
+        return CephadmOrchestrator.instance._worker_pool.map(do_work, vals)
+
+
+    return forall_hosts_wrapper
\ No newline at end of file