From a8912315c07aa882b40774b9471728cfda821b1b Mon Sep 17 00:00:00 2001 From: Waleed Akbar Date: Mon, 29 Jul 2024 11:45:16 +0000 Subject: [PATCH 1/2] Changes to resolve pipeline test error. - added create_kpi_id_request() in kpi_manger test_mesages.py --- src/kpi_manager/tests/test_kpi_manager.py | 2 +- src/kpi_manager/tests/test_messages.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/kpi_manager/tests/test_kpi_manager.py b/src/kpi_manager/tests/test_kpi_manager.py index b41e5139d..f0d9526d3 100755 --- a/src/kpi_manager/tests/test_kpi_manager.py +++ b/src/kpi_manager/tests/test_kpi_manager.py @@ -37,7 +37,7 @@ from kpi_manager.tests.test_messages import create_kpi_descriptor_request, creat from kpi_manager.service.KpiManagerService import KpiManagerService from kpi_manager.client.KpiManagerClient import KpiManagerClient from kpi_manager.tests.test_messages import create_kpi_descriptor_request -from kpi_value_writer.tests.test_messages import create_kpi_id_request +from kpi_manager.tests.test_messages import create_kpi_id_request #from monitoring.service.NameMapping import NameMapping diff --git a/src/kpi_manager/tests/test_messages.py b/src/kpi_manager/tests/test_messages.py index 870660658..7b5c45859 100644 --- a/src/kpi_manager/tests/test_messages.py +++ b/src/kpi_manager/tests/test_messages.py @@ -18,6 +18,12 @@ from common.proto.kpi_sample_types_pb2 import KpiSampleType from common.proto.context_pb2 import DeviceId, LinkId, ServiceId, SliceId,\ ConnectionId, EndPointId + +def create_kpi_id_request(): + _create_kpi_id = kpi_manager_pb2.KpiId() + _create_kpi_id.kpi_id.uuid = str(uuid.uuid4()) + return _create_kpi_id + def create_kpi_descriptor_request(descriptor_name: str = "Test_name"): _create_kpi_request = kpi_manager_pb2.KpiDescriptor() _create_kpi_request.kpi_id.kpi_id.uuid = str(uuid.uuid4()) -- GitLab From 0190accb0e4b575d0d019c84fc27d9391a97d014 Mon Sep 17 00:00:00 2001 From: Waleed Akbar Date: Mon, 29 Jul 2024 13:32:00 +0000 Subject: [PATCH 2/2] To resolve the "test_GetKpiDescriptor" test fail issue. - Test was failing due to a "NotFoundException." - Replaced with None and made approriate changes in files (Kpi_DB.py and KpiManagerServiceImpl) to handle the None value. --- src/kpi_manager/database/Kpi_DB.py | 5 +++-- src/kpi_manager/service/KpiManagerServiceServicerImpl.py | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/kpi_manager/database/Kpi_DB.py b/src/kpi_manager/database/Kpi_DB.py index dcd28489b..4b6064070 100644 --- a/src/kpi_manager/database/Kpi_DB.py +++ b/src/kpi_manager/database/Kpi_DB.py @@ -85,8 +85,9 @@ class KpiDB: # LOGGER.debug(f"{model.__name__} ID found: {str(entity)}") return entity else: - LOGGER.debug(f"{model.__name__} ID not found: {str(id_to_search)}") - raise NotFoundException (model.__name__, id_to_search, extra_details=["Row not found with ID"] ) + LOGGER.debug(f"{model.__name__} ID not found, No matching row: {str(id_to_search)}") + print("{:} ID not found, No matching row: {:}".format(model.__name__, id_to_search)) + return None except Exception as e: session.rollback() LOGGER.debug(f"Failed to retrieve {model.__name__} ID. {str(e)}") diff --git a/src/kpi_manager/service/KpiManagerServiceServicerImpl.py b/src/kpi_manager/service/KpiManagerServiceServicerImpl.py index bea2c78b4..fd2247482 100644 --- a/src/kpi_manager/service/KpiManagerServiceServicerImpl.py +++ b/src/kpi_manager/service/KpiManagerServiceServicerImpl.py @@ -52,8 +52,13 @@ class KpiManagerServiceServicerImpl(KpiManagerServiceServicer): try: kpi_id_to_search = request.kpi_id.uuid row = self.kpi_db_obj.search_db_row_by_id(KpiModel, 'kpi_id', kpi_id_to_search) - response = KpiModel.convert_row_to_KpiDescriptor(row) - return response + if row is None: + print ('No matching row found for kpi id: {:}'.format(kpi_id_to_search)) + LOGGER.info('No matching row found kpi id: {:}'.format(kpi_id_to_search)) + return Empty() + else: + response = KpiModel.convert_row_to_KpiDescriptor(row) + return response except Exception as e: print ('Unable to search kpi id. {:}'.format(e)) LOGGER.info('Unable to search kpi id. {:}'.format(e)) -- GitLab