Fix CPS DB check 87/137487/1
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Wed, 6 Mar 2024 18:25:31 +0000 (19:25 +0100)
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Thu, 7 Mar 2024 08:27:14 +0000 (09:27 +0100)
Fix CPS DB check to use tls authentication

Issue-ID: INT-2263
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Change-Id: I69fa15e849f6703b08a0057c4d633f951c6719f1

src/onaptests/steps/onboard/cps.py

index 04471c2..8f2525c 100644 (file)
@@ -1,6 +1,7 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 """CPS onboard module."""
 import base64
+import ssl
 from abc import ABC
 
 import pg8000
@@ -8,7 +9,8 @@ from kubernetes import client, config
 from onapsdk.configuration import settings
 from onapsdk.cps import Anchor, Dataspace, SchemaSet
 
-from onaptests.utils.exceptions import EnvironmentPreparationException
+from onaptests.utils.exceptions import (EnvironmentPreparationException,
+                                        OnapTestException)
 
 from ..base import BaseStep
 
@@ -294,12 +296,16 @@ class CheckPostgressDataBaseConnectionStep(CpsBaseStep):
 
         self.get_database_credentials()
         if self.login and self.password:
+            ctx = ssl.create_default_context()
+            ctx.check_hostname = False
+            ctx.verify_mode = ssl.CERT_NONE
             db_params = {
                 "user": self.login,
                 "password": self.password,
                 "host": settings.DB_PRIMARY_HOST,
                 "database": settings.DATABASE,
-                "port": settings.DB_PORT
+                "port": settings.DB_PORT,
+                "ssl_context": ctx
             }
             try:
                 connection = pg8000.connect(**db_params)
@@ -310,9 +316,9 @@ class CheckPostgressDataBaseConnectionStep(CpsBaseStep):
                     cursor.close()
                 if connection:
                     connection.close()
-            except pg8000.Error as e:
+            except Exception as e:
                 self._logger.exception(f"Error while connecting to PostgreSQL: {str(e)}")
-                raise
+                raise OnapTestException(e) from e
 
     @BaseStep.store_state
     def execute(self) -> None: