From 4a5f5bd4372d20d6169e67b591e3888dbd18c37e Mon Sep 17 00:00:00 2001 From: gatici Date: Wed, 26 Jul 2023 15:45:17 +0300 Subject: [PATCH] OSMENG-1092 Activity Delete NS Record Change-Id: Ieb3ef317e6ad0356bdbbe0d96db0cff87fe8f39e Signed-off-by: gatici --- osm_lcm/nglcm.py | 2 ++ osm_lcm/temporal/ns_activities.py | 8 ++++++++ osm_lcm/tests/test_ns_activities.py | 31 ++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/osm_lcm/nglcm.py b/osm_lcm/nglcm.py index 38ec183..46e2836 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 69cf7df..955028e 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 833f440..7b67f73 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), + ) -- 2.25.1