From 8ea2ab58981dbc98ab9854b756ab4d1cb82055b3 Mon Sep 17 00:00:00 2001 From: junchao Date: Mon, 7 Sep 2020 15:23:26 +0800 Subject: [PATCH] If system health configuration file not exist, healthd should exit --- src/system-health/health_checker/config.py | 5 ++++- src/system-health/scripts/healthd | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/system-health/health_checker/config.py b/src/system-health/health_checker/config.py index d30d6e6b816e..47b5f82b172b 100644 --- a/src/system-health/health_checker/config.py +++ b/src/system-health/health_checker/config.py @@ -45,6 +45,9 @@ def __init__(self): self.ignore_devices = None self.user_defined_checkers = None + def config_file_exists(self): + return os.path.exists(self._config_file) + def load_config(self): """ Load the configuration file from disk. @@ -53,7 +56,7 @@ def load_config(self): 3. If there is any format issues in configuration file, current config entries will reset to default value :return: """ - if not os.path.exists(self._config_file): + if not self.config_file_exists(): if self._last_mtime is not None: self._reset() return diff --git a/src/system-health/scripts/healthd b/src/system-health/scripts/healthd index 5b98f4cc138f..55d332bfb685 100644 --- a/src/system-health/scripts/healthd +++ b/src/system-health/scripts/healthd @@ -73,6 +73,9 @@ class HealthDaemon(DaemonBase): import sonic_platform.platform chassis = sonic_platform.platform.Platform().get_chassis() manager = HealthCheckerManager() + if not manager.config.config_file_exists(): + logger.log_warning("System health configuration file not found, exit...") + return while 1: state, stat = manager.check(chassis) if state == HealthCheckerManager.STATE_RUNNING: