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,
DeleteVimRecordImpl(self.db),
ChangeVnfStateImpl(self.db),
ChangeVnfInstantiationStateImpl(self.db),
+ DeleteNsRecordImpl(self.db),
DeleteVnfRecordImpl(self.db),
GetTaskQueueImpl(self.db),
GetVimCloudImpl(self.db),
from time import time
from osm_common.temporal.activities.ns import (
+ DeleteNsRecord,
GetNsRecord,
GetVnfDetails,
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.")
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
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),
+ )