From b95a5c15fccb4288cf7a26fd2e83c5358832d662 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Wed, 8 Nov 2023 06:25:06 +0000 Subject: [PATCH] Fix Bug 2304: Flavor Not getting Updated in Mongodb nsrs after Vertical scaling Change-Id: I37cdd030613cfe56ab3a75dc74a4a55f7858d7d7 Signed-off-by: Rahul Kumar --- NG-RO/osm_ng_ro/ns.py | 52 +++++++++++++++++++ NG-RO/osm_ng_ro/ns_thread.py | 16 ++---- NG-RO/osm_ng_ro/tests/test_ns.py | 23 ++++++-- NG-RO/osm_ng_ro/tests/test_ns_thread.py | 6 ++- ...after_Vertical_scale-2dab98ac5b1072e7.yaml | 22 ++++++++ 5 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 releasenotes/notes/bug_fix_2304_Flavor_Not_getting_Updated_in_Mongodb_nsrs_after_Vertical_scale-2dab98ac5b1072e7.yaml diff --git a/NG-RO/osm_ng_ro/ns.py b/NG-RO/osm_ng_ro/ns.py index 9678366d..85b8c08d 100644 --- a/NG-RO/osm_ng_ro/ns.py +++ b/NG-RO/osm_ng_ro/ns.py @@ -3121,6 +3121,10 @@ class Ns(object): ): target_vim, vim_info = next(k_v for k_v in vdu["vim_info"].items()) self._assign_vim(target_vim) + ns_preffix = "nsrs:{}".format(nsr_id) + flavor_text = ns_preffix + ":flavor." + vdu["ns-flavor-id"] + extra_dict["depends_on"] = [flavor_text] + extra_dict["params"].update({"flavor_id": "TASK-" + flavor_text}) target_record = "vnfrs:{}:vdur.{}.vim_info.{}".format( vnf["_id"], vdu_index, target_vim ) @@ -3142,9 +3146,36 @@ class Ns(object): ) return task + def verticalscale_flavor_task( + self, vdu, vnf, vdu_index, action_id, nsr_id, task_index, extra_dict + ): + target_vim, vim_info = next(k_v for k_v in vdu["vim_info"].items()) + self._assign_vim(target_vim) + db_nsr = self.db.get_one("nsrs", {"_id": nsr_id}) + target_record = "nsrs:{}:flavor.{}.vim_info.{}".format( + nsr_id, len(db_nsr["flavor"]) - 1, target_vim + ) + target_record_id = "nsrs:{}:flavor.{}".format(nsr_id, len(db_nsr["flavor"]) - 1) + deployment_info = { + "action_id": action_id, + "nsr_id": nsr_id, + "task_index": task_index, + } + task = Ns._create_task( + deployment_info=deployment_info, + target_id=target_vim, + item="flavor", + action="CREATE", + target_record=target_record, + target_record_id=target_record_id, + extra_dict=extra_dict, + ) + return task + def verticalscale(self, session, indata, version, nsr_id, *args, **kwargs): task_index = 0 extra_dict = {} + flavor_extra_dict = {} now = time() action_id = indata.get("action_id", str(uuid4())) step = "" @@ -3166,6 +3197,13 @@ class Ns(object): "vcpus": numVirtualCpu, "disk": sizeOfStorage, } + flavor_data = { + "ram": virtualMemory, + "vcpus": numVirtualCpu, + "disk": sizeOfStorage, + } + flavor_extra_dict["find_params"] = {"flavor_data": flavor_data} + flavor_extra_dict["params"] = {"flavor_data": flavor_dict} db_new_tasks = [] step = "Creating Tasks for vertical scaling" with self.write_lock: @@ -3177,7 +3215,21 @@ class Ns(object): extra_dict["params"] = { "vim_vm_id": vdu["vim-id"], "flavor_dict": flavor_dict, + "vdu-id-ref": vdu["vdu-id-ref"], + "count-index": vdu["count-index"], + "vnf_instance_id": vnf_instance_id, } + task = self.verticalscale_flavor_task( + vdu, + db_vnfr, + vdu_index, + action_id, + nsr_id, + task_index, + flavor_extra_dict, + ) + db_new_tasks.append(task) + task_index += 1 task = self.verticalscale_task( vdu, db_vnfr, diff --git a/NG-RO/osm_ng_ro/ns_thread.py b/NG-RO/osm_ng_ro/ns_thread.py index b1949b3a..66de3487 100644 --- a/NG-RO/osm_ng_ro/ns_thread.py +++ b/NG-RO/osm_ng_ro/ns_thread.py @@ -1519,20 +1519,12 @@ class VimInteractionResize(VimInteractionBase): target_vim = self.my_vims[ro_task["target_id"]] try: + params = task["params"] + params_copy = deepcopy(params) + target_flavor_uuid = task_depends[params_copy["flavor_id"]] vim_vm_id = "" if task.get("params"): - vim_vm_id = task["params"].get("vim_vm_id") - flavor_dict = task["params"].get("flavor_dict") - self.logger.info("flavor_dict %s", flavor_dict) - - try: - target_flavor_uuid = target_vim.get_flavor_id_from_data(flavor_dict) - except Exception as e: - self.logger.info("Cannot find any flavor matching %s.", str(e)) - try: - target_flavor_uuid = target_vim.new_flavor(flavor_dict) - except Exception as e: - self.logger.error("Error creating flavor at VIM %s.", str(e)) + self.logger.info("vim_vm_id %s", vim_vm_id) if target_flavor_uuid is not None: resized_status = target_vim.resize_instance( diff --git a/NG-RO/osm_ng_ro/tests/test_ns.py b/NG-RO/osm_ng_ro/tests/test_ns.py index b5c81fd9..0fc4cfac 100644 --- a/NG-RO/osm_ng_ro/tests/test_ns.py +++ b/NG-RO/osm_ng_ro/tests/test_ns.py @@ -331,11 +331,14 @@ expected_result_vertical_scale = { "params": { "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396", "flavor_dict": "flavor_dict", + "flavor_id": "TASK-nsrs:993166fe-723e-4680-ac4b-b1af2541ae31:flavor.0", }, + "depends_on": ["nsrs:993166fe-723e-4680-ac4b-b1af2541ae31:flavor.0"], } vdu = { "id": vdu_id, "vim_info": {target_vim: {"interfaces": []}}, + "ns-flavor-id": "0", } vnf = {"_id": vnf_id} extra_dict_vertical_scale = { @@ -3210,11 +3213,25 @@ class TestNs(unittest.TestCase): self, assign_vim ): self.ns = Ns() - extra_dict = {} + extra_dict = {"params": {}} vdu_index = "1" task_index = 1 - expected_result = deepcopy(expected_result_vertical_scale) - expected_result.pop("params") + expected_result = { + "target_id": "vim:f9f370ac-0d44-41a7-9000-457f2332bc35", + "action_id": "bb937f49-3870-4169-b758-9732e1ff40f3", + "nsr_id": "993166fe-723e-4680-ac4b-b1af2541ae31", + "task_id": "bb937f49-3870-4169-b758-9732e1ff40f3:1", + "status": "SCHEDULED", + "action": "EXEC", + "item": "verticalscale", + "target_record": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.1.vim_info.vim:f9f370ac-0d44-41a7-9000-457f2332bc35", + "target_record_id": "vnfrs:665b4165-ce24-4320-bf19-b9a45bade49f:vdur.bb9c43f9-10a2-4569-a8a8-957c3528b6d1", + "params": { + "flavor_id": "TASK-nsrs:993166fe-723e-4680-ac4b-b1af2541ae31:flavor.0" + }, + "depends_on": ["nsrs:993166fe-723e-4680-ac4b-b1af2541ae31:flavor.0"], + } + task = self.ns.verticalscale_task( vdu, vnf, vdu_index, action_id, nsr_id_2, task_index, extra_dict ) diff --git a/NG-RO/osm_ng_ro/tests/test_ns_thread.py b/NG-RO/osm_ng_ro/tests/test_ns_thread.py index ad3efe82..7e4388fc 100644 --- a/NG-RO/osm_ng_ro/tests/test_ns_thread.py +++ b/NG-RO/osm_ng_ro/tests/test_ns_thread.py @@ -1921,12 +1921,16 @@ class TestVimInteractionResize(unittest.TestCase): "params": { "vim_vm_id": "f37b18ef-3caa-4dc9-ab91-15c669b16396", "flavor_dict": "flavor_dict", + "flavor_id": "TASK-nsrs:993166fe-723e-4680-ac4b-b1af2541ae31:flavor.0", }, } }, } + task_depends = { + "TASK-nsrs:993166fe-723e-4680-ac4b-b1af2541ae31:flavor.0": "1" + } task_index = "task_index_1" - result = instance.exec(ro_task, task_index, self.task_depends) + result = instance.exec(ro_task, task_index, task_depends) self.assertEqual(result[0], "DONE") self.assertEqual(result[1].get("vim_status"), "ACTIVE") diff --git a/releasenotes/notes/bug_fix_2304_Flavor_Not_getting_Updated_in_Mongodb_nsrs_after_Vertical_scale-2dab98ac5b1072e7.yaml b/releasenotes/notes/bug_fix_2304_Flavor_Not_getting_Updated_in_Mongodb_nsrs_after_Vertical_scale-2dab98ac5b1072e7.yaml new file mode 100644 index 00000000..97bb2394 --- /dev/null +++ b/releasenotes/notes/bug_fix_2304_Flavor_Not_getting_Updated_in_Mongodb_nsrs_after_Vertical_scale-2dab98ac5b1072e7.yaml @@ -0,0 +1,22 @@ +####################################################################################### +# 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. +####################################################################################### +--- +fixes: + - | + Bug Fix 2304 Flavor Not getting Updated in Mongodb nsrs after Vertical scaling, + because In vertical scale feature Ro task creation is not not added for flavor. + This fix will add the new flavor in nsrs after scaling and it's refrence in vnfrs. -- 2.25.1