Feature 10909: Heal operation for VDU. Fix virtual machine deletion and volume deleti... 06/12006/2
authorpalaciosj <jmpalacios@indra.es>
Thu, 5 May 2022 14:59:36 +0000 (14:59 +0000)
committeraticig <gulsum.atici@canonical.com>
Mon, 13 Jun 2022 13:44:08 +0000 (15:44 +0200)
Change-Id: Iffe66e3dcb87b0b24ee09fd74129b26dfd87c320
Signed-off-by: palaciosj <jmpalacios@indra.es>
NG-RO/osm_ng_ro/ns.py
NG-RO/osm_ng_ro/ns_thread.py
releasenotes/notes/Feature_10909_Heal_fix_volume_deletion-93881695b38ec312.yaml [new file with mode: 0644]

index bc8e628..0a40367 100644 (file)
@@ -1693,12 +1693,17 @@ class Ns(object):
             target_id = db_task.pop("target_id")
             common_id = db_task.get("common_id")
 
             target_id = db_task.pop("target_id")
             common_id = db_task.get("common_id")
 
+            # Do not chek tasks with vim_status DELETED
+            # because in manual heealing there are two tasks for the same vdur:
+            #   one with vim_status deleted and the other one with the actual VM status.
+
             if common_id:
                 if self.db.set_one(
                     "ro_tasks",
                     q_filter={
                         "target_id": target_id,
                         "tasks.common_id": common_id,
             if common_id:
                 if self.db.set_one(
                     "ro_tasks",
                     q_filter={
                         "target_id": target_id,
                         "tasks.common_id": common_id,
+                        "vim_info.vim_status.ne": "DELETED",
                     },
                     update_dict={"to_check_at": now, "modified_at": now},
                     push={"tasks": db_task},
                     },
                     update_dict={"to_check_at": now, "modified_at": now},
                     push={"tasks": db_task},
@@ -1711,6 +1716,7 @@ class Ns(object):
                 q_filter={
                     "target_id": target_id,
                     "tasks.target_record": db_task["target_record"],
                 q_filter={
                     "target_id": target_id,
                     "tasks.target_record": db_task["target_record"],
+                    "vim_info.vim_status.ne": "DELETED",
                 },
                 update_dict={"to_check_at": now, "modified_at": now},
                 push={"tasks": db_task},
                 },
                 update_dict={"to_check_at": now, "modified_at": now},
                 push={"tasks": db_task},
@@ -1760,6 +1766,9 @@ class Ns(object):
                 db_ro_task["vim_info"]["created_items"] = db_task.get(
                     "created_items", {}
                 )
                 db_ro_task["vim_info"]["created_items"] = db_task.get(
                     "created_items", {}
                 )
+                db_ro_task["vim_info"]["volumes_to_hold"] = db_task.get(
+                    "volumes_to_hold", []
+                )
                 db_ro_task["vim_info"]["vim_id"] = db_task.get("vim_id", None)
 
             nb_ro_tasks += 1
                 db_ro_task["vim_info"]["vim_id"] = db_task.get("vim_id", None)
 
             nb_ro_tasks += 1
@@ -1774,16 +1783,23 @@ class Ns(object):
 
     def _prepare_created_items_for_healing(
         self,
 
     def _prepare_created_items_for_healing(
         self,
-        target_id,
-        existing_vdu,
+        nsr_id,
+        target_record,
     ):
     ):
-        # Only ports are considered because created volumes are persistent
-        ports_list = {}
-        vim_interfaces = existing_vdu["vim_info"][target_id].get("interfaces", [])
-        for iface in vim_interfaces:
-            ports_list["port:" + iface["vim_interface_id"]] = True
+        created_items = {}
+        # Get created_items from ro_task
+        ro_tasks = self.db.get_list("ro_tasks", {"tasks.nsr_id": nsr_id})
+        for ro_task in ro_tasks:
+            for task in ro_task["tasks"]:
+                if (
+                    task["target_record"] == target_record
+                    and task["action"] == "CREATE"
+                    and ro_task["vim_info"]["created_items"]
+                ):
+                    created_items = ro_task["vim_info"]["created_items"]
+                    break
 
 
-        return ports_list
+        return created_items
 
     def _prepare_persistent_volumes_for_healing(
         self,
 
     def _prepare_persistent_volumes_for_healing(
         self,
@@ -1871,7 +1887,7 @@ class Ns(object):
 
                     target_record = f"{db_record}.{item_index}.vim_info.{target_vim}"
                     created_items = self._prepare_created_items_for_healing(
 
                     target_record = f"{db_record}.{item_index}.vim_info.{target_vim}"
                     created_items = self._prepare_created_items_for_healing(
-                        target_vim, existing_instance
+                        nsr_id, target_record
                     )
 
                     volumes_to_hold = self._prepare_persistent_volumes_for_healing(
                     )
 
                     volumes_to_hold = self._prepare_persistent_volumes_for_healing(
@@ -1927,6 +1943,20 @@ class Ns(object):
                     # The CREATE task depens on the DELETE task
                     extra_dict["depends_on"] = [delete_task_id]
 
                     # The CREATE task depens on the DELETE task
                     extra_dict["depends_on"] = [delete_task_id]
 
+                    # Add volumes created from created_items if any
+                    # Ports should be deleted with delete task and automatically created with create task
+                    volumes = {}
+                    for k, v in created_items.items():
+                        try:
+                            k_item, _, k_id = k.partition(":")
+                            if k_item == "volume":
+                                volumes[k] = v
+                        except Exception as e:
+                            self.logger.error(
+                                "Error evaluating created item {}: {}".format(k, e)
+                            )
+                    extra_dict["previous_created_volumes"] = volumes
+
                     deployment_info = {
                         "action_id": action_id,
                         "nsr_id": nsr_id,
                     deployment_info = {
                         "action_id": action_id,
                         "nsr_id": nsr_id,
index fda7253..767382d 100644 (file)
@@ -391,6 +391,11 @@ class VimInteractionVdu(VimInteractionBase):
             vim_vm_id, created_items = target_vim.new_vminstance(**params_copy)
             interfaces = [iface["vim_id"] for iface in params_copy["net_list"]]
 
             vim_vm_id, created_items = target_vim.new_vminstance(**params_copy)
             interfaces = [iface["vim_id"] for iface in params_copy["net_list"]]
 
+            # add to created items previous_created_volumes (healing)
+            if task.get("previous_created_volumes"):
+                for k, v in task["previous_created_volumes"].items():
+                    created_items[k] = v
+
             ro_vim_item_update = {
                 "vim_id": vim_vm_id,
                 "vim_status": "BUILD",
             ro_vim_item_update = {
                 "vim_id": vim_vm_id,
                 "vim_status": "BUILD",
diff --git a/releasenotes/notes/Feature_10909_Heal_fix_volume_deletion-93881695b38ec312.yaml b/releasenotes/notes/Feature_10909_Heal_fix_volume_deletion-93881695b38ec312.yaml
new file mode 100644 (file)
index 0000000..b8ccdbf
--- /dev/null
@@ -0,0 +1,21 @@
+#######################################################################################
+# 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:
+  - |
+    Feature 10909: Heal operation for VDU. Fix virtual machine deletion
+    and volume deletion when terminating network service