From 7107e04ccfc37670c47b74ae811a0b688f0ac9c2 Mon Sep 17 00:00:00 2001 From: vpachchi Date: Mon, 7 Jul 2025 02:52:25 -0400 Subject: [PATCH] Fix to make the WRA configuration optional Test Plan: PASS - Verify that the regression testing works PASS - Confirm that if Elasticsearch is not available, the watcher skips the performance measurement (PM) portion as intended. Change-Id: I4fd4752ded27ce0b6879ebf713a6c15a3de7f35e Signed-off-by: vpachchi --- o2common/config/config.py | 18 ++++++++++++------ o2ims/adapter/clients/pm_client.py | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/o2common/config/config.py b/o2common/config/config.py index cac87b8..74521b7 100644 --- a/o2common/config/config.py +++ b/o2common/config/config.py @@ -442,13 +442,19 @@ def get_es_access_info(ip=None): Defaults to None and will use environment variable. Returns: - dict: Dictionary containing Elasticsearch connection details + Dictionary containing Elasticsearch connection details, + None if [PM] section is missing """ - # Get values from config file - username = config.conf.PM.ES_USERNAME - password = config.conf.PM.ES_PASSWORD - port = config.conf.PM.ES_PORT - path = config.conf.PM.ES_PATH + # Get values from config file (safely, [PM] section is optional) + pm_section = getattr(config.conf, "PM", None) + if pm_section is None: + logger.warning("No [PM] section found in config.") + return None + + username = getattr(pm_section, "ES_USERNAME", None) + password = getattr(pm_section, "ES_PASSWORD", None) + port = getattr(pm_section, "ES_PORT", None) + path = getattr(pm_section, "ES_PATH", None) # Allow environment variables to override config file username = os.getenv('ES_USERNAME', username) diff --git a/o2ims/adapter/clients/pm_client.py b/o2ims/adapter/clients/pm_client.py index 2c7da31..a337d76 100644 --- a/o2ims/adapter/clients/pm_client.py +++ b/o2ims/adapter/clients/pm_client.py @@ -68,6 +68,8 @@ class EsPmClientImp(object): # Get ES connection info using OAM floating IP es_config = config.get_es_access_info(ip=oam_ip) + if es_config is None: + return None es_client = Elasticsearch( es_config['url'], -- 2.16.6