]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/cephadm: move handling of use_agent setting into agent.py
authorAdam King <adking@redhat.com>
Thu, 30 Sep 2021 13:32:31 +0000 (09:32 -0400)
committerAdam King <adking@redhat.com>
Thu, 30 Sep 2021 13:32:31 +0000 (09:32 -0400)
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 <adking@redhat.com>
src/pybind/mgr/cephadm/agent.py
src/pybind/mgr/cephadm/serve.py

index d43f639264855b225f4a5464a8fe969ef6952b86..39f091a496b89e3bba6e8fb7e06cfd0ddb61ca58 100644 (file)
@@ -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:
index f8d4398b56f6b379082d8f517d18ed6fb6af33dd..b3048b1fb5641af25750837cc86b32f8aacab2aa 100644 (file)
@@ -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