OSMENG-1092 Activity Delete NS Record 49/13749/1
authorgatici <gulsum.atici@canonical.com>
Wed, 26 Jul 2023 12:45:17 +0000 (15:45 +0300)
committergatici <gulsum.atici@canonical.com>
Wed, 26 Jul 2023 12:45:17 +0000 (15:45 +0300)
Change-Id: Ieb3ef317e6ad0356bdbbe0d96db0cff87fe8f39e
Signed-off-by: gatici <gulsum.atici@canonical.com>
osm_lcm/nglcm.py
osm_lcm/temporal/ns_activities.py
osm_lcm/tests/test_ns_activities.py

index 38ec183..46e2836 100644 (file)
@@ -44,6 +44,7 @@ from osm_lcm.temporal.juju_paas_activities import (
 from osm_lcm.temporal.lcm_activities import NsLcmNoOpImpl, UpdateNsLcmOperationStateImpl
 from osm_lcm.temporal.lcm_workflows import NsNoOpWorkflowImpl
 from osm_lcm.temporal.ns_activities import (
+    DeleteNsRecordImpl,
     GetVnfDetailsImpl,
     GetNsRecordImpl,
     UpdateNsStateImpl,
@@ -200,6 +201,7 @@ class NGLcm:
             DeleteVimRecordImpl(self.db),
             ChangeVnfStateImpl(self.db),
             ChangeVnfInstantiationStateImpl(self.db),
+            DeleteNsRecordImpl(self.db),
             DeleteVnfRecordImpl(self.db),
             GetTaskQueueImpl(self.db),
             GetVimCloudImpl(self.db),
index 69cf7df..955028e 100644 (file)
@@ -18,6 +18,7 @@ from temporalio import activity
 from time import time
 
 from osm_common.temporal.activities.ns import (
+    DeleteNsRecord,
     GetNsRecord,
     GetVnfDetails,
     UpdateNsState,
@@ -57,3 +58,10 @@ class UpdateNsStateImpl(UpdateNsState):
         self.logger.debug(
             f"Updated NS {activity_input.ns_uuid} to {activity_input.state.name}"
         )
+
+
+@activity.defn(name=DeleteNsRecord.__name__)
+class DeleteNsRecordImpl(DeleteNsRecord):
+    async def __call__(self, activity_input: DeleteNsRecord.Input) -> None:
+        self.db.del_one("nsrs", {"_id": activity_input.ns_uuid}, fail_on_empty=False)
+        self.logger.debug(f"VNF {activity_input.ns_uuid} record deleted from DB.")
index 833f440..7b67f73 100644 (file)
 
 import asynctest
 
-from osm_lcm.temporal.ns_activities import GetNsRecordImpl, GetVnfDetailsImpl
+from osm_lcm.temporal.ns_activities import (
+    GetNsRecordImpl,
+    GetVnfDetailsImpl,
+    DeleteNsRecordImpl,
+)
 from osm_common.dbbase import DbException
 from temporalio.testing import ActivityEnvironment
 from unittest.mock import Mock
@@ -93,3 +97,28 @@ class TestGetNsRecord(asynctest.TestCase):
                 self.get_ns_record_impl,
                 GetNsRecordImpl.Input(nsr_uuid=sample_nsr["_id"]),
             )
+
+
+class TestDeleteNsRecord(asynctest.TestCase):
+    async def setUp(self):
+        self.db = Mock()
+        self.delete_ns_record = DeleteNsRecordImpl(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_ns_record,
+            DeleteNsRecordImpl.Input(ns_uuid=ns_uuid),
+        )
+        self.db.del_one.assert_called_with(
+            "nsrs", {"_id": ns_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_ns_record,
+                DeleteNsRecordImpl.Input(ns_uuid=ns_uuid),
+            )