X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=NG-RO%2Fosm_ng_ro%2Fns.py;h=d2dc46b565daf01e50c732f3b5223e068a9b602b;hb=d2a67cd30f775b4d1b63660a04124a5f8b49dade;hp=bc8e6287eea80664a93846c6ae32bf98f612c457;hpb=8658c2cd33bcea66c9b99aabb0825071c5c42df0;p=osm%2FRO.git diff --git a/NG-RO/osm_ng_ro/ns.py b/NG-RO/osm_ng_ro/ns.py index bc8e6287..d2dc46b5 100644 --- a/NG-RO/osm_ng_ro/ns.py +++ b/NG-RO/osm_ng_ro/ns.py @@ -958,6 +958,37 @@ class Ns(object): extra_dict = {"depends_on": [image_text, flavor_text]} net_list = [] + # If the position info is provided for all the interfaces, it will be sorted + # according to position number ascendingly. + if all(i.get("position") for i in target_vdu["interfaces"]): + sorted_interfaces = sorted( + target_vdu["interfaces"], + key=lambda x: (x.get("position") is None, x.get("position")), + ) + target_vdu["interfaces"] = sorted_interfaces + + # If the position info is provided for some interfaces but not all of them, the interfaces + # which has specific position numbers will be placed and others' positions will not be taken care. + else: + if any(i.get("position") for i in target_vdu["interfaces"]): + n = len(target_vdu["interfaces"]) + sorted_interfaces = [-1] * n + k, m = 0, 0 + while k < n: + if target_vdu["interfaces"][k].get("position"): + idx = target_vdu["interfaces"][k]["position"] + sorted_interfaces[idx - 1] = target_vdu["interfaces"][k] + k += 1 + while m < n: + if not target_vdu["interfaces"][m].get("position"): + idy = sorted_interfaces.index(-1) + sorted_interfaces[idy] = target_vdu["interfaces"][m] + m += 1 + + target_vdu["interfaces"] = sorted_interfaces + + # If the position info is not provided for the interfaces, interfaces will be attached + # according to the order in the VNFD. for iface_index, interface in enumerate(target_vdu["interfaces"]): if interface.get("ns-vld-id"): net_text = ns_preffix + ":vld." + interface["ns-vld-id"] @@ -1230,7 +1261,9 @@ class Ns(object): "floating_ip", ) } - existing_ifaces = existing_vdu["vim_info"][target_id].get("interfaces", []) + existing_ifaces = existing_vdu["vim_info"][target_id].get( + "interfaces_backup", [] + ) net_id = next( ( i["vim_net_id"] @@ -1693,12 +1726,17 @@ class Ns(object): 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, + "vim_info.vim_status.ne": "DELETED", }, update_dict={"to_check_at": now, "modified_at": now}, push={"tasks": db_task}, @@ -1711,6 +1749,7 @@ class Ns(object): 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}, @@ -1760,6 +1799,9 @@ class Ns(object): 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 @@ -1774,16 +1816,23 @@ class Ns(object): 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, @@ -1871,7 +1920,7 @@ class Ns(object): 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( @@ -1927,6 +1976,20 @@ class Ns(object): # 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,