From: Adam King Date: Tue, 26 Oct 2021 11:58:15 +0000 (-0400) Subject: mgr/cephadm: add host to get_daemons_by_type, metadata_up_to_date to refresh functions X-Git-Tag: v17.1.0~494^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8a1aa9c4dbddb9ccc4331c9310fb2b685b9d8122;p=ceph.git mgr/cephadm: add host to get_daemons_by_type, metadata_up_to_date to refresh functions Signed-off-by: Adam King --- diff --git a/src/pybind/mgr/cephadm/agent.py b/src/pybind/mgr/cephadm/agent.py index 8998c1e63f5..cb5f9acdf05 100644 --- a/src/pybind/mgr/cephadm/agent.py +++ b/src/pybind/mgr/cephadm/agent.py @@ -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: diff --git a/src/pybind/mgr/cephadm/inventory.py b/src/pybind/mgr/cephadm/inventory.py index 2336706ac58..62a055d6bbc 100644 --- a/src/pybind/mgr/cephadm/inventory.py +++ b/src/pybind/mgr/cephadm/inventory.py @@ -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: diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index 4a721b50fa3..e95f4b0c8e6 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -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: