From 8b37c780bf4383526d59ff09ef30a540202e793c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 27 Jan 2020 08:59:24 -0600 Subject: [PATCH] mgr/cephadm: prime cached service state with newly created services If we create a service, add the expected state to our cache, so that it immediately appears in the get_services result. Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 17 +++++++++++++++++ src/pybind/mgr/cephadm/tests/test_cephadm.py | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 27854c8887dbd..75a9dae034526 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1569,7 +1569,24 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): ] + extra_args, stdin=j) self.log.debug('create_daemon code %s out %s' % (code, out)) + if not code: + # prime cached service state with what we (should have) + # just created + sd = { + 'style': 'cephadm:v1', + 'name': '%s.%s' % (daemon_type, daemon_id), + 'fsid': self._cluster_fsid, + 'enabled': True, + 'state': 'running', + } + data = self.service_cache[host].data + if data: + data.append(sd) + else: + data = [sd] + self.service_cache[host] = orchestrator.OutdatableData(data) self.service_cache.invalidate(host) + self.event.set() return "{} {} on host '{}'".format( 'Reconfigured' if reconfig else 'Deployed', name, host) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 2f20230841565..61372d6efde69 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -88,6 +88,8 @@ class TestCephadm(object): cephadm_module._cluster_fsid = "fsid" cephadm_module.service_cache_timeout = 10 with self._with_host(cephadm_module, 'test'): + c = cephadm_module.describe_service(refresh=True) + wait(cephadm_module, c) c = cephadm_module.service_action('redeploy', 'rgw', service_id='myrgw.foobar') assert wait(cephadm_module, c) == ["Deployed rgw.myrgw.foobar on host 'test'"] @@ -143,6 +145,8 @@ class TestCephadm(object): def test_remove_osds(self, cephadm_module): cephadm_module._cluster_fsid = "fsid" with self._with_host(cephadm_module, 'test'): + c = cephadm_module.describe_service(refresh=True) + wait(cephadm_module, c) c = cephadm_module.remove_osds(['0']) out = wait(cephadm_module, c) assert out == ["Removed osd.0 from host 'test'"] @@ -186,6 +190,8 @@ class TestCephadm(object): def test_remove_rgw(self, cephadm_module): cephadm_module._cluster_fsid = "fsid" with self._with_host(cephadm_module, 'test'): + c = cephadm_module.describe_service(refresh=True) + wait(cephadm_module, c) c = cephadm_module.remove_rgw('myrgw') out = wait(cephadm_module, c) assert out == ["Removed rgw.myrgw.foobar from host 'test'"] -- 2.39.5