From 3cf54d9c92475d970a312561be6273f3c340b9e9 Mon Sep 17 00:00:00 2001 From: Paul Cuzner Date: Wed, 3 Feb 2021 14:45:15 +1300 Subject: [PATCH] mgr/cephadm:updates to support orch status changes 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 (cherry picked from commit 81caa2643ec4a36d6d6185a4fb215eaf4b532aef) Conflicts: src/pybind/mgr/rook/module.py --- src/pybind/mgr/cephadm/module.py | 18 +++++++++------ src/pybind/mgr/orchestrator/_interface.py | 9 ++++---- src/pybind/mgr/orchestrator/module.py | 27 ++++++++++------------- src/pybind/mgr/rook/module.py | 12 +++++----- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 1d7538aee194d..48cae0a4b5357 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -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 """ diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index d5f4397b5a035..4ed5a2855f128 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -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. diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index 4b159845657dd..28c862dc4f201 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -1353,30 +1353,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) diff --git a/src/pybind/mgr/rook/module.py b/src/pybind/mgr/rook/module.py index c6a6293b4d5bb..4bee44c15fd12 100644 --- a/src/pybind/mgr/rook/module.py +++ b/src/pybind/mgr/rook/module.py @@ -8,7 +8,7 @@ from ceph.deployment import inventory from ceph.deployment.service_spec import ServiceSpec, NFSServiceSpec, RGWSpec, PlacementSpec try: - from typing import List, Dict, Optional, Callable, Any + from typing import List, Dict, Optional, Callable, Any, Tuple from ceph.deployment.drive_group import DriveGroupSpec except ImportError: pass # just for type checking @@ -117,18 +117,18 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator): return False, "Rook version unsupported." return True, '' - def available(self): + 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, **kwargs): super(RookOrchestrator, self).__init__(*args, **kwargs) -- 2.39.5