From 2c440edebf7cd4e535bcb680bd7131f0d22daf7a Mon Sep 17 00:00:00 2001 From: Adam King Date: Thu, 27 Aug 2020 12:22:49 -0400 Subject: [PATCH] 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 --- src/pybind/mgr/cephadm/services/monitoring.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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) -- 2.47.3