From 0a23a6aa7c2dbad8aa541e37e1a260e8a93e8029 Mon Sep 17 00:00:00 2001 From: Paul Cuzner Date: Mon, 30 May 2022 13:54:33 +1200 Subject: [PATCH] mgr/cephadm: Add new host rescan command Adds a host rescan command to invoke cephadm's rescan-disks subcommand Signed-off-by: Paul Cuzner (cherry picked from commit cc9eb1812e9aa138d7af7426b42657ace9020bea) --- src/pybind/mgr/cephadm/module.py | 26 +++++++++++++++++++++++ src/pybind/mgr/orchestrator/_interface.py | 11 ++++++++++ src/pybind/mgr/orchestrator/module.py | 10 +++++++++ 3 files changed, 47 insertions(+) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 0f69382684c..59c4d50dd1f 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1866,6 +1866,32 @@ Then run the following: return f"Ceph cluster {self._cluster_fsid} on {hostname} has exited maintenance mode" + @handle_orch_error + @host_exists() + def rescan_host(self, hostname: str) -> str: + """Use cephadm to issue a disk rescan on each HBA + + Some HBAs and external enclosures don't automatically register + device insertion with the kernel, so for these scenarios we need + to manually rescan + + :param hostname: (str) host name + """ + self.log.info(f'disk rescan request sent to host "{hostname}"') + _out, _err, _code = CephadmServe(self)._run_cephadm(hostname, cephadmNoImage, "disk-rescan", + [], no_fsid=True, error_ok=True) + if not _err: + raise OrchestratorError('Unexpected response from cephadm disk-rescan call') + + msg = _err[0].split('\n')[-1] + log_msg = f'disk rescan: {msg}' + if msg.upper().startswith('OK'): + self.log.info(log_msg) + else: + self.log.warning(log_msg) + + return f'{msg}' + def get_minimal_ceph_conf(self) -> str: _, config, _ = self.check_mon_command({ "prefix": "config generate-minimal-conf", diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 83dbccf5df2..2208a587495 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -418,6 +418,17 @@ class Orchestrator(object): """ raise NotImplementedError() + def rescan_host(self, hostname: str) -> OrchResult: + """Use cephadm to issue a disk rescan on each HBA + + Some HBAs and external enclosures don't automatically register + device insertion with the kernel, so for these scenarios we need + to manually rescan + + :param hostname: (str) host name + """ + raise NotImplementedError() + def get_inventory(self, host_filter: Optional['InventoryFilter'] = None, refresh: bool = False) -> OrchResult[List['InventoryHost']]: """ Returns something that was created by `ceph-volume inventory`. diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index a113b098929..4e7ddf247ef 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -456,6 +456,16 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule, return HandleCommandResult(stdout=completion.result_str()) + @_cli_write_command('orch host rescan') + def _host_rescan(self, hostname: str, with_summary: bool = False) -> HandleCommandResult: + """Perform a disk rescan on a host""" + completion = self.rescan_host(hostname) + raise_if_exception(completion) + + if with_summary: + return HandleCommandResult(stdout=completion.result_str()) + return HandleCommandResult(stdout=completion.result_str().split('.')[0]) + @_cli_read_command('orch device ls') def _list_devices(self, hostname: Optional[List[str]] = None, -- 2.47.3