]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: add host to get_daemons_by_type, metadata_up_to_date to refresh functions
authorAdam King <adking@redhat.com>
Tue, 26 Oct 2021 11:58:15 +0000 (07:58 -0400)
committerAdam King <adking@redhat.com>
Tue, 26 Oct 2021 11:58:15 +0000 (07:58 -0400)
Signed-off-by: Adam King <adking@redhat.com>
src/pybind/mgr/cephadm/agent.py
src/pybind/mgr/cephadm/inventory.py
src/pybind/mgr/cephadm/serve.py

index 8998c1e63f561821fddc3429621f606fda09da7c..cb5f9acdf05eb1a928610ebaa2e5c9be5d3d0ca7 100644 (file)
@@ -325,7 +325,7 @@ class CephadmAgentHelpers:
         if host not in [h.hostname for h in self.mgr.cache.get_non_draining_hosts()]:
             return False
         # if we haven't deployed an agent on the host yet, don't say an agent is down
-        if not [a for a in self.mgr.cache.get_daemons_by_type('agent') if a.hostname == host]:
+        if not self.mgr.cache.get_daemons_by_type('agent', host=host):
             return False
         # if we don't have a timestamp, it's likely because of a mgr fail over.
         # just set the timestamp to now. However, if host was offline before, we
@@ -421,8 +421,7 @@ class CephadmAgentHelpers:
 
                 try:
                     # try to schedule redeploy of agent in case it is individually down
-                    agent = [a for a in self.mgr.cache.get_daemons_by_type(
-                        'agent') if a.hostname == host][0]
+                    agent = self.mgr.cache.get_daemons_by_type('agent', host=host)[0]
                     with self.mgr.agent_helpers.agent_lock(host):
                         daemon_spec = CephadmDaemonDeploySpec.from_daemon_description(agent)
                         self.mgr._daemon_action(daemon_spec, action='redeploy')
@@ -432,8 +431,7 @@ class CephadmAgentHelpers:
             return True
         else:
             try:
-                agent = [a for a in self.mgr.cache.get_daemons_by_type(
-                    'agent') if a.hostname == host][0]
+                agent = self.mgr.cache.get_daemons_by_type('agent', host=host)[0]
                 assert agent.daemon_id is not None
                 assert agent.hostname is not None
             except Exception as e:
index 2336706ac589feb6ee813323ac50df75887bdd69..62a055d6bbc8504680585e6ea76df6f34b6209f9 100644 (file)
@@ -817,8 +817,7 @@ class HostCache():
                 r.append(dd)
         return r
 
-    def get_error_daemons(self):
-        # type: () -> List[orchestrator.DaemonDescription]
+    def get_error_daemons(self) -> List[orchestrator.DaemonDescription]:
         r = []
         for host, dm in self.daemons.items():
             for name, dd in dm.items():
@@ -866,12 +865,13 @@ class HostCache():
                     result.append(d)
         return result
 
-    def get_daemons_by_type(self, service_type):
-        # type: (str) -> List[orchestrator.DaemonDescription]
+    def get_daemons_by_type(self, service_type: str, host: str = '') -> List[orchestrator.DaemonDescription]:
         assert service_type not in ['keepalived', 'haproxy']
 
         result = []   # type: List[orchestrator.DaemonDescription]
-        for host, dm in self.daemons.items():
+        for h, dm in self.daemons.items():
+            if host and h != host:
+                continue
             for name, d in dm.items():
                 if d.daemon_type in service_to_daemon_types(service_type):
                     result.append(d)
@@ -915,6 +915,8 @@ class HostCache():
             seconds=self.mgr.daemon_cache_timeout)
         if host not in self.last_daemon_update or self.last_daemon_update[host] < cutoff:
             return True
+        if not self.mgr.cache.host_metadata_up_to_date(host):
+            return True
         return False
 
     def host_needs_facts_refresh(self, host):
@@ -926,6 +928,8 @@ class HostCache():
             seconds=self.mgr.facts_cache_timeout)
         if host not in self.last_facts_update or self.last_facts_update[host] < cutoff:
             return True
+        if not self.mgr.cache.host_metadata_up_to_date(host):
+            return True
         return False
 
     def host_needs_autotune_memory(self, host):
@@ -961,6 +965,8 @@ class HostCache():
             seconds=self.mgr.device_cache_timeout)
         if host not in self.last_device_update or self.last_device_update[host] < cutoff:
             return True
+        if not self.mgr.cache.host_metadata_up_to_date(host):
+            return True
         return False
 
     def host_needs_network_refresh(self, host):
@@ -975,6 +981,8 @@ class HostCache():
             seconds=self.mgr.device_cache_timeout)
         if host not in self.last_network_update or self.last_network_update[host] < cutoff:
             return True
+        if not self.mgr.cache.host_metadata_up_to_date(host):
+            return True
         return False
 
     def host_needs_osdspec_preview_refresh(self, host: str) -> bool:
index 4a721b50fa301bdefae29bfd1cceeae42a4b61cc..e95f4b0c8e6aa4bb88a36016edb5acf42d682395 100644 (file)
@@ -261,47 +261,32 @@ class CephadmServe:
                 or host not in [h.hostname for h in self.mgr.cache.get_non_draining_hosts()]
                 or host in agents_down
             ):
-                if (
-                    self.mgr.cache.host_needs_daemon_refresh(host)
-                    or not self.mgr.cache.host_metadata_up_to_date(host)
-                ):
+                if self.mgr.cache.host_needs_daemon_refresh(host):
                     self.log.debug('refreshing %s daemons' % host)
                     r = self._refresh_host_daemons(host)
                     if r:
                         failures.append(r)
 
-                if (
-                    self.mgr.cache.host_needs_facts_refresh(host)
-                    or not self.mgr.cache.host_metadata_up_to_date(host)
-                ):
+                if self.mgr.cache.host_needs_facts_refresh(host):
                     self.log.debug(('Refreshing %s facts' % host))
                     r = self._refresh_facts(host)
                     if r:
                         failures.append(r)
 
-                if (
-                    self.mgr.cache.host_needs_network_refresh(host)
-                    or not self.mgr.cache.host_metadata_up_to_date(host)
-                ):
+                if self.mgr.cache.host_needs_network_refresh(host):
                     self.log.debug(('Refreshing %s networks' % host))
                     r = self._refresh_host_networks(host)
                     if r:
                         failures.append(r)
 
-                if (
-                    self.mgr.cache.host_needs_device_refresh(host)
-                    or not self.mgr.cache.host_metadata_up_to_date(host)
-                ):
+                if self.mgr.cache.host_needs_device_refresh(host):
                     self.log.debug('refreshing %s devices' % host)
                     r = self._refresh_host_devices(host)
                     if r:
                         failures.append(r)
                 self.mgr.cache.metadata_up_to_date[host] = True
-            elif not [a for a in self.mgr.cache.get_daemons_by_type('agent') if a.hostname == host]:
-                if (
-                    self.mgr.cache.host_needs_daemon_refresh(host)
-                    or not self.mgr.cache.host_metadata_up_to_date(host)
-                ):
+            elif not self.mgr.cache.get_daemons_by_type('agent', host=host):
+                if self.mgr.cache.host_needs_daemon_refresh(host):
                     self.log.debug('refreshing %s daemons' % host)
                     r = self._refresh_host_daemons(host)
                     if r: