From: vpachchi Date: Mon, 7 Jul 2025 06:52:25 +0000 (-0400) Subject: Fix to make the WRA configuration optional X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=7107e04ccfc37670c47b74ae811a0b688f0ac9c2;p=pti%2Fo2.git 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 --- 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'],