Activity Delete VNF record 63/13663/6
authorPatricia Reinoso <patricia.reinoso@canonical.com>
Tue, 11 Jul 2023 15:17:49 +0000 (15:17 +0000)
committerMark Beierl <mark.beierl@canonical.com>
Thu, 20 Jul 2023 18:29:55 +0000 (18:29 +0000)
Change-Id: I8c557ebc00833a64041e1c70cc9c6fec4c1a769c
Signed-off-by: Patricia Reinoso <patricia.reinoso@canonical.com>
Signed-off-by: Mark Beierl <mark.beierl@canonical.com>
osm_lcm/nglcm.py
osm_lcm/temporal/vnf_activities.py
osm_lcm/tests/test_vnf_activities.py

index 1d60e6e..680ffe6 100644 (file)
@@ -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),
index 3ea8c64..dea0551 100644 (file)
@@ -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__(
index 374a648..64d9caf 100644 (file)
@@ -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()