]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm:updates to support orch status changes
authorPaul Cuzner <pcuzner@redhat.com>
Wed, 3 Feb 2021 01:45:15 +0000 (14:45 +1300)
committerPaul Cuzner <pcuzner@redhat.com>
Wed, 3 Feb 2021 01:45:15 +0000 (14:45 +1300)
The available function definition has been updated in
cephadm/rook and Orchestrator base class to provide a
module specific dictionary holding any specific info that
would be pertinent to share with the user. This in turn
changed the _status method for cephadm, but the UX
remains the same (i.e. admin must use --detail to see
the worker pool size).

Signed-off-by: Paul Cuzner <pcuzner@redhat.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/module.py
src/pybind/mgr/rook/module.py

index ae7f4a02929d9450fe2b3f07eece81f00d27ec20..5d61a5cad8b10f7bd767be502b52c157ebfe3d6b 100644 (file)
@@ -529,9 +529,6 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
                     # start the process
                     self._kick_serve_loop()
 
-    def is_paused(self) -> bool:
-        return self.paused
-
     def pause(self) -> None:
         if not self.paused:
             self.log.info('Paused')
@@ -678,17 +675,24 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
             return False, "loading remoto library:{}".format(
                 remoto_import_error)
 
-    def available(self) -> Tuple[bool, str]:
+    def available(self) -> Tuple[bool, str, Dict[str, Any]]:
         """
         The cephadm orchestrator is always available.
         """
         ok, err = self.can_run()
         if not ok:
-            return ok, err
+            return ok, err, {}
         if not self.ssh_key or not self.ssh_pub:
-            return False, 'SSH keys not set. Use `ceph cephadm set-priv-key` and `ceph cephadm set-pub-key` or `ceph cephadm generate-key`'
+            return False, 'SSH keys not set. Use `ceph cephadm set-priv-key` and `ceph cephadm set-pub-key` or `ceph cephadm generate-key`', {}
+
+        # mypy is unable to determine type for _processes since it's private
+        worker_count: int = self._worker_pool._processes  # type: ignore
+        ret = {
+            "workers": worker_count,
+            "paused": self.paused,
+        }
 
-        return True, str(self._worker_pool._processes)  # type: ignore
+        return True, err, ret
 
     def process(self, completions: List[CephadmCompletion]) -> None:  # type: ignore
         """
index 1c0fae6666187e9006e009d9e782cec041ce3d5c..e18d934ce0bf38671fc18d5a1872f3ee669a31e7 100644 (file)
@@ -703,7 +703,7 @@ class Orchestrator(object):
         return True
 
     @_hide_in_features
-    def available(self) -> Tuple[bool, str]:
+    def available(self) -> Tuple[bool, str, Dict[str, Any]]:
         """
         Report whether we can talk to the orchestrator.  This is the
         place to give the user a meaningful message if the orchestrator
@@ -724,7 +724,9 @@ class Orchestrator(object):
                 ... if OrchestratorClientMixin().available()[0]:  # wrong.
                 ...     OrchestratorClientMixin().get_hosts()
 
-        :return: two-tuple of boolean, string
+        :return: boolean representing whether the module is available/usable
+        :return: string describing any error 
+        :return: dict containing any module specific information
         """
         raise NotImplementedError()
 
@@ -786,9 +788,6 @@ class Orchestrator(object):
     def resume(self) -> None:
         raise NotImplementedError()
 
-    def is_paused(self) -> bool:
-        raise NotImplementedError()
-
     def add_host(self, host_spec: HostSpec) -> Completion[str]:
         """
         Add a host to the orchestrator inventory.
index 5a82319e389d58a5a22a962d1a38c4aa70504413..0c950999790b42edb8a7e632895c05b0458f2200 100644 (file)
@@ -1351,30 +1351,27 @@ Usage:
         if o is None:
             raise NoOrchestrator()
 
-        avail, msg = self.available()
+        avail, why, module_details = self.available()
         result: Dict[str, Any] = {
+            "available": avail,
             "backend": o,
-            "paused": self.is_paused(),
         }
 
-        if avail is not None:
-            result['available'] = avail
-            if avail:
-                if o == "cephadm" and detail:
-                    result['workers'] = msg
-            else:
-                result['reason'] = msg
+        if avail:
+            result.update(module_details)
+        else:
+            result['reason'] = why
 
         if format != Format.plain:
             output = to_format(result, format, many=False, cls=None)
         else:
             output = "Backend: {0}".format(result['backend'])
-            if 'available' in result:
-                output += f"\nAvailable: {'Yes' if result['available'] else 'No'}"
-                if 'reason' in result:
-                    output += ' ({0})'.format(result['reason'])
-            output += f"\nPaused: {'Yes' if result['paused'] else 'No'}"
-            if 'workers' in result:
+            output += f"\nAvailable: {'Yes' if result['available'] else 'No'}"
+            if 'reason' in result:
+                output += ' ({0})'.format(result['reason'])
+            if 'paused' in result:
+                output += f"\nPaused: {'Yes' if result['paused'] else 'No'}"
+            if 'workers' in result and detail:
                 output += f"\nHost Parallelism: {result['workers']}"
         return HandleCommandResult(stdout=output)
 
index becbe8ef416101b9348a5b7c5fa89820eea61bde..82eaf68f368911fab13e30189731843f39d7edbc 100644 (file)
@@ -125,18 +125,18 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
             return False, "Rook version unsupported."
         return True, ''
 
-    def available(self) -> Tuple[bool, str]:
+    def available(self) -> Tuple[bool, str, Dict[str, Any]]:
         if not kubernetes_imported:
-            return False, "`kubernetes` python module not found"
+            return False, "`kubernetes` python module not found", {}
         elif not self._rook_env.has_namespace():
-            return False, "ceph-mgr not running in Rook cluster"
+            return False, "ceph-mgr not running in Rook cluster", {}
 
         try:
             self.k8s.list_namespaced_pod(self._rook_env.namespace)
         except ApiException as e:
-            return False, "Cannot reach Kubernetes API: {}".format(e)
+            return False, "Cannot reach Kubernetes API: {}".format(e), {}
         else:
-            return True, ""
+            return True, "", {}
 
     def __init__(self, *args: Any, **kwargs: Any) -> None:
         super(RookOrchestrator, self).__init__(*args, **kwargs)