From 1b74a3db0c23423bb5a188eafb4346711d0b13a2 Mon Sep 17 00:00:00 2001 From: Adam King Date: Thu, 30 Sep 2021 09:32:31 -0400 Subject: [PATCH] mgr/cephadm: move handling of use_agent setting into agent.py The serve function itself should only really be calling other functions. The actual handling of the setting is better placed in the agent's own file. Signed-off-by: Adam King --- src/pybind/mgr/cephadm/agent.py | 23 +++++++++++++++++++++++ src/pybind/mgr/cephadm/serve.py | 19 ++----------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/pybind/mgr/cephadm/agent.py b/src/pybind/mgr/cephadm/agent.py index d43f6392648..39f091a496b 100644 --- a/src/pybind/mgr/cephadm/agent.py +++ b/src/pybind/mgr/cephadm/agent.py @@ -319,6 +319,29 @@ class CephadmAgentHelpers: ) self.mgr.spec_store.save(spec) + def _handle_use_agent_setting(self) -> bool: + need_apply = False + if self.mgr.use_agent: + # on the off chance there are still agents hanging around from + # when we turned the config option off, we need to redeploy them + # we can tell they're in that state if we don't have a keyring for + # them in the host cache + for agent in self.mgr.cache.get_daemons_by_service('agent'): + if agent.hostname not in self.mgr.cache.agent_keys: + self.mgr._schedule_daemon_action(agent.name(), 'redeploy') + if 'agent' not in self.mgr.spec_store: + self.mgr.agent_helpers._apply_agent() + need_apply = True + else: + if 'agent' in self.mgr.spec_store: + self.mgr.spec_store.rm('agent') + need_apply = True + self.mgr.cache.agent_counter = {} + self.mgr.cache.agent_timestamp = {} + self.mgr.cache.agent_keys = {} + self.mgr.cache.agent_ports = {} + return need_apply + class SSLCerts: def __init__(self, mgr: "CephadmOrchestrator") -> None: diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index f8d4398b56f..b3048b1fb56 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -91,23 +91,8 @@ class CephadmServe: self._purge_deleted_services() - if self.mgr.use_agent: - # on the off chance there are still agents hanging around from - # when we turned the config option off, we need to redeploy them - # we can tell they're in that state if we don't have a keyring for - # them in the host cache - for agent in self.mgr.cache.get_daemons_by_service('agent'): - if agent.hostname not in self.mgr.cache.agent_keys: - self.mgr._schedule_daemon_action(agent.name(), 'redeploy') - if 'agent' not in self.mgr.spec_store: - self.mgr.agent_helpers._apply_agent() - else: - if 'agent' in self.mgr.spec_store: - self.mgr.spec_store.rm('agent') - self.mgr.cache.agent_counter = {} - self.mgr.cache.agent_timestamp = {} - self.mgr.cache.agent_keys = {} - self.mgr.cache.agent_ports = {} + if self.mgr.agent_helpers._handle_use_agent_setting(): + continue if self.mgr.upgrade.continue_upgrade(): continue -- 2.39.5