From: gatici Date: Wed, 26 Jul 2023 12:45:17 +0000 (+0300) Subject: OSMENG-1092 Activity Delete NS Record X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F49%2F13749%2F1;p=osm%2FLCM.git OSMENG-1092 Activity Delete NS Record Change-Id: Ieb3ef317e6ad0356bdbbe0d96db0cff87fe8f39e Signed-off-by: gatici --- diff --git a/osm_lcm/nglcm.py b/osm_lcm/nglcm.py index 38ec1836..46e28366 100644 --- a/osm_lcm/nglcm.py +++ b/osm_lcm/nglcm.py @@ -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), diff --git a/osm_lcm/temporal/ns_activities.py b/osm_lcm/temporal/ns_activities.py index 69cf7df2..955028e9 100644 --- a/osm_lcm/temporal/ns_activities.py +++ b/osm_lcm/temporal/ns_activities.py @@ -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.") diff --git a/osm_lcm/tests/test_ns_activities.py b/osm_lcm/tests/test_ns_activities.py index 833f440c..7b67f73a 100644 --- a/osm_lcm/tests/test_ns_activities.py +++ b/osm_lcm/tests/test_ns_activities.py @@ -16,7 +16,11 @@ 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), + )