From: Patricia Reinoso Date: Tue, 11 Jul 2023 15:17:49 +0000 (+0000) Subject: Activity Delete VNF record X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=14406d2258d8925f3b3f7deadf6c503a676a04f6;p=osm%2FLCM.git Activity Delete VNF record Change-Id: I8c557ebc00833a64041e1c70cc9c6fec4c1a769c Signed-off-by: Patricia Reinoso Signed-off-by: Mark Beierl --- diff --git a/osm_lcm/nglcm.py b/osm_lcm/nglcm.py index 1d60e6e..680ffe6 100644 --- a/osm_lcm/nglcm.py +++ b/osm_lcm/nglcm.py @@ -61,6 +61,7 @@ from osm_lcm.temporal.vim_workflows import ( VimUpdateWorkflowImpl, ) from osm_lcm.temporal.vnf_activities import ( + DeleteVnfRecordImpl, GetTaskQueueImpl, GetVnfDescriptorImpl, GetVnfRecordImpl, @@ -195,6 +196,7 @@ class NGLcm: DeleteVimRecordImpl(self.db), ChangeVnfStateImpl(self.db), ChangeVnfInstantiationStateImpl(self.db), + DeleteVnfRecordImpl(self.db), GetTaskQueueImpl(self.db), GetVimCloudImpl(self.db), GetVnfDescriptorImpl(self.db), diff --git a/osm_lcm/temporal/vnf_activities.py b/osm_lcm/temporal/vnf_activities.py index 3ea8c64..dea0551 100644 --- a/osm_lcm/temporal/vnf_activities.py +++ b/osm_lcm/temporal/vnf_activities.py @@ -17,6 +17,7 @@ from temporalio import activity from typing import List, Any from osm_common.temporal.activities.vnf import ( + DeleteVnfRecord, GetTaskQueue, GetVimCloud, GetVnfDescriptor, @@ -174,6 +175,13 @@ class SendNotificationForVnfImpl(SendNotificationForVnf): self.logger.debug("Send notification for VNF not implemented.") +@activity.defn(name=DeleteVnfRecord.__name__) +class DeleteVnfRecordImpl(DeleteVnfRecord): + async def __call__(self, activity_input: DeleteVnfRecord.Input) -> None: + self.db.del_one("vnfrs", {"_id": activity_input.vnfr_uuid}, fail_on_empty=False) + self.logger.debug(f"VNF {activity_input.vnfr_uuid} record deleted from DB.") + + @activity.defn(name=GetModelNames.__name__) class GetModelNamesImpl(GetModelNames): async def __call__( diff --git a/osm_lcm/tests/test_vnf_activities.py b/osm_lcm/tests/test_vnf_activities.py index 374a648..64d9caf 100644 --- a/osm_lcm/tests/test_vnf_activities.py +++ b/osm_lcm/tests/test_vnf_activities.py @@ -22,6 +22,7 @@ from unittest.mock import Mock, patch from osm_common.dbbase import DbException from osm_common.temporal_task_queues.task_queues_mappings import LCM_TASK_QUEUE from osm_lcm.temporal.vnf_activities import ( + DeleteVnfRecordImpl, ChangeVnfInstantiationStateImpl, ChangeVnfStateImpl, GetModelNamesImpl, @@ -269,6 +270,31 @@ class TestGetVnfRecord(asynctest.TestCase): ) +class TestDeleteVnfRecord(asynctest.TestCase): + async def setUp(self): + self.db = Mock() + self.delete_vnf_record = DeleteVnfRecordImpl(self.db) + self.env = ActivityEnvironment() + + async def test_activity__succeeded__expected_record_is_deleted(self): + self.db.del_one.return_value = None + await self.env.run( + self.delete_vnf_record, + DeleteVnfRecordImpl.Input(vnfr_uuid=vnfr_uuid), + ) + self.db.del_one.assert_called_with( + "vnfrs", {"_id": vnfr_uuid}, fail_on_empty=False + ) + + async def test_activity__failed__raise_db_exception(self): + self.db.del_one.side_effect = DbException("Can not connect to Database.") + with self.assertRaises(DbException): + await self.env.run( + self.delete_vnf_record, + DeleteVnfRecordImpl.Input(vnfr_uuid=vnfr_uuid), + ) + + class TestGetVimCloud(asynctest.TestCase): async def setUp(self): self.db = Mock()