From: Daniel Arndt Date: Thu, 20 Apr 2023 20:14:58 +0000 (-0300) Subject: Tests for get_vnf_record_ids, rename function X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=0d2142a1985c5dfcbfe94f434570002210991174;p=osm%2FLCM.git Tests for get_vnf_record_ids, rename function Change-Id: Idbefa175b650fef08b87c9f602efc59a3ea4cad3 Signed-off-by: Daniel Arndt --- diff --git a/osm_lcm/nglcm.py b/osm_lcm/nglcm.py index 5ddae3f..3aeeee2 100644 --- a/osm_lcm/nglcm.py +++ b/osm_lcm/nglcm.py @@ -62,7 +62,7 @@ class NGLcm: :param config_file: two level dictionary with configuration. Top level should contain 'database', 'storage', :return: None """ - self.db = None + self.db: Database = None self.logger = logging.getLogger("lcm") self._load_configuration(config_file) self._configure_logging() @@ -161,7 +161,7 @@ class NGLcm: ] activities = [ ns_data_activity_instance.update_ns_state, - ns_operation_instance.get_vnf_records, + ns_operation_instance.get_vnf_record_ids, nslcm_activity_instance.update_ns_lcm_operation_state, nslcm_activity_instance.no_op, paas_connector_instance.create_model, diff --git a/osm_lcm/temporal/ns_activities.py b/osm_lcm/temporal/ns_activities.py index c48628a..12ffc76 100644 --- a/osm_lcm/temporal/ns_activities.py +++ b/osm_lcm/temporal/ns_activities.py @@ -32,15 +32,17 @@ from osm_lcm.data_utils.database.database import Database class NsOperations: - def __init__(self, db): - self.db = db + def __init__(self, db: Database): + self.db: Database = db self.logger = logging.getLogger(f"lcm.act.{self.__class__.__name__}") @activity.defn(name=ACTIVITY_GET_VNF_RECORD_IDS) - async def get_vnf_records( - self, get_vnf_records_input: GetVnfRecordIdsInput + async def get_vnf_record_ids( + self, get_vnf_record_ids_input: GetVnfRecordIdsInput ) -> GetVnfRecordIdsOutput: - vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": get_vnf_records_input.ns_uuid}) + vnfrs = self.db.get_list( + "vnfrs", {"nsr-id-ref": get_vnf_record_ids_input.ns_uuid} + ) return GetVnfRecordIdsOutput(vnfr_ids=[vnfr["id"] for vnfr in vnfrs]) diff --git a/osm_lcm/temporal/ns_workflows.py b/osm_lcm/temporal/ns_workflows.py index 7f13810..f76e31f 100644 --- a/osm_lcm/temporal/ns_workflows.py +++ b/osm_lcm/temporal/ns_workflows.py @@ -62,7 +62,6 @@ class NsInstantiateWorkflow(LcmOperationWorkflow): retry_policy=LcmOperationWorkflow.no_retry_policy, ) - # TODO: Provide the correct VNFR ids to the VNF instantiate workflow vnf_record_ids_output: GetVnfRecordIdsOutput = value_to_type( GetVnfRecordIdsOutput, await workflow.execute_activity( diff --git a/osm_lcm/tests/test_ns_activities.py b/osm_lcm/tests/test_ns_activities.py new file mode 100644 index 0000000..623f072 --- /dev/null +++ b/osm_lcm/tests/test_ns_activities.py @@ -0,0 +1,58 @@ +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from unittest.mock import Mock + +import asynctest +from osm_common.dataclasses.temporal_dataclasses import GetVnfRecordIdsInput +from osm_common.dbbase import DbException +from temporalio.testing import ActivityEnvironment + +from osm_lcm.temporal.ns_activities import NsOperations + +ns_uuid = "00000000-0000-0000-0000-000000000000" +get_vnf_record_ids_input = GetVnfRecordIdsInput(ns_uuid=ns_uuid) + + +class TestGetModelInfo(asynctest.TestCase): + def setUp(self): + self.db = Mock() + self.env = ActivityEnvironment() + self.ns_operations_activity = NsOperations(self.db) + + async def test_get_vnfr_ids(self): + self.db.get_list.return_value = [ + {"id": "00000000-0000-0000-0000-000000000000"}, + {"id": "00000000-0000-0000-0000-000000000000"}, + ] + result = await self.env.run( + self.ns_operations_activity.get_vnf_record_ids, get_vnf_record_ids_input + ) + + assert result.vnfr_ids == [ + "00000000-0000-0000-0000-000000000000", + "00000000-0000-0000-0000-000000000000", + ] + + self.db.get_list.assert_called_with("vnfrs", {"nsr-id-ref": ns_uuid}) + + async def test_activity_raises_db_exception(self): + self.db.get_list.side_effect = DbException("not found") + with self.assertRaises(DbException): + await self.env.run( + self.ns_operations_activity.get_vnf_record_ids, get_vnf_record_ids_input + )