From: Matthew Oliver Date: Thu, 23 Apr 2020 01:07:19 +0000 (+1000) Subject: cephadm: Check for pool existance for iscsi And NFS X-Git-Tag: v15.2.4~13^2~3^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c76581493c4a2ce1ca89fccdbb63a7d92cf190b2;p=ceph.git cephadm: Check for pool existance for iscsi And NFS Currently both iscsi and NFS require pools to be specified when they are deployed. However, we don't actaully check these pools exist. Leading to broken containers. This patch uses the rados client that is part of the mgrmodule to check that the specified pool exists. As we need to check in 2 different daemons, a helper method: def _check_pool_exists(self, pool, service_name): was added to `cephadm/module.py`. Fixes: https://tracker.ceph.com/issues/45161 Signed-off-by: Matthew Oliver (cherry picked from commit d3de8697e6d389c514d26f5eb62675ac061a56c6) --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 751460b67faa..89af9d14b044 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2521,6 +2521,12 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): spec.service_name(), spec, e)) return r + def _check_pool_exists(self, pool, service_name): + logger.info(f'Checking pool "{pool}" exists for service {service_name}') + if not self.rados.pool_exists(pool): + raise OrchestratorError(f'Cannot find pool "{pool}" for ' + f'service {service_name}') + def _check_daemons(self): # get monmap mtime so we can refresh configs when mons change monmap = self.get('mon_map') @@ -2852,6 +2858,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): return self._add_daemon('iscsi', spec, self._create_iscsi, self._config_iscsi) def _config_iscsi(self, spec): + self._check_pool_exists(spec.pool, spec.service_name()) + logger.info('Saving service %s spec with placement %s' % ( spec.service_name(), spec.placement.pretty_str())) self.spec_store.save(spec) @@ -2944,6 +2952,8 @@ api_secure = {api_secure} return self._add_daemon('nfs', spec, self._create_nfs, self._config_nfs) def _config_nfs(self, spec): + self._check_pool_exists(spec.pool, spec.service_name()) + logger.info('Saving service %s spec with placement %s' % ( spec.service_name(), spec.placement.pretty_str())) self.spec_store.save(spec) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index f13680cab264..a8bd0ae0f93b 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -438,6 +438,7 @@ class TestCephadm(object): assert_rm_service(cephadm_module, 'nfs.name') @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) + @mock.patch("cephadm.module.CephadmOrchestrator.rados", mock.MagicMock()) def test_iscsi(self, cephadm_module): with self._with_host(cephadm_module, 'test'): ps = PlacementSpec(hosts=['test'], count=1)