From: Adam King Date: Thu, 27 Aug 2020 16:22:49 +0000 (-0400) Subject: mgr/cephadm: Verify non-empty list in get_active_daemon functions X-Git-Tag: v16.1.0~1281^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F36858%2Fhead;p=ceph.git mgr/cephadm: Verify non-empty list in get_active_daemon functions The get_active_daemon functions for monitoring stack daemons were just returning the first or last daemon in the given list without checking the list actually contained any daemons Fixes: https://tracker.ceph.com/issues/47171 Signed-off-by: Adam King --- diff --git a/src/pybind/mgr/cephadm/services/monitoring.py b/src/pybind/mgr/cephadm/services/monitoring.py index cc4d1416b65a..e14e17fdc230 100644 --- a/src/pybind/mgr/cephadm/services/monitoring.py +++ b/src/pybind/mgr/cephadm/services/monitoring.py @@ -61,7 +61,10 @@ class GrafanaService(CephadmService): def get_active_daemon(self, daemon_descrs: List[DaemonDescription]) -> DaemonDescription: # Use the least-created one as the active daemon - return daemon_descrs[-1] + if daemon_descrs: + return daemon_descrs[-1] + # if empty list provided, return empty Daemon Desc + return DaemonDescription() def config_dashboard(self, daemon_descrs: List[DaemonDescription]): # TODO: signed cert @@ -141,7 +144,10 @@ class AlertmanagerService(CephadmService): def get_active_daemon(self, daemon_descrs: List[DaemonDescription]) -> DaemonDescription: # TODO: if there are multiple daemons, who is the active one? - return daemon_descrs[0] + if daemon_descrs: + return daemon_descrs[0] + # if empty list provided, return empty Daemon Desc + return DaemonDescription() def config_dashboard(self, daemon_descrs: List[DaemonDescription]): dd = self.get_active_daemon(daemon_descrs) @@ -231,7 +237,10 @@ class PrometheusService(CephadmService): def get_active_daemon(self, daemon_descrs: List[DaemonDescription]) -> DaemonDescription: # TODO: if there are multiple daemons, who is the active one? - return daemon_descrs[0] + if daemon_descrs: + return daemon_descrs[0] + # if empty list provided, return empty Daemon Desc + return DaemonDescription() def config_dashboard(self, daemon_descrs: List[DaemonDescription]): dd = self.get_active_daemon(daemon_descrs)