Fix to make the WRA configuration optional 03/14703/2
authorvpachchi <vineela.pachchipulusu@windriver.com>
Mon, 7 Jul 2025 06:52:25 +0000 (02:52 -0400)
committervpachchi <vineela.pachchipulusu@windriver.com>
Mon, 7 Jul 2025 08:03:36 +0000 (04:03 -0400)
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 <vineela.pachchipulusu@windriver.com>
o2common/config/config.py
o2ims/adapter/clients/pm_client.py

index cac87b8..74521b7 100644 (file)
@@ -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)
index 2c7da31..a337d76 100644 (file)
@@ -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'],