X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=NG-RO%2Fosm_ng_ro%2Fns_thread.py;h=b713d4dcd6dee30992f56f0fe21d66d4450ca38b;hb=4d5c814c1490b641818f362fe538252e10bf6d8c;hp=f15831aab94fd04e083bb8e3409d75c5d545d6c0;hpb=80135b928ab442c38898750b4751480205b4affc;p=osm%2FRO.git diff --git a/NG-RO/osm_ng_ro/ns_thread.py b/NG-RO/osm_ng_ro/ns_thread.py index f15831aa..b713d4dc 100644 --- a/NG-RO/osm_ng_ro/ns_thread.py +++ b/NG-RO/osm_ng_ro/ns_thread.py @@ -24,24 +24,23 @@ A single ro_task refers to a VIM element (flavor, image, network, ...). A ro_task can contain several 'tasks', each one with a target, where to store the results """ -import logging -import queue -import threading -import time -import yaml from copy import deepcopy from http import HTTPStatus +import logging from os import mkdir -from pkg_resources import iter_entry_points +import queue from shutil import rmtree +import threading +import time from unittest.mock import Mock -# from osm_common import dbmongo, dbmemory, fslocal, fsmongo, msglocal, msgkafka, version as common_version +from importlib_metadata import entry_points from osm_common.dbbase import DbException -from osm_ro_plugin.vim_dummy import VimDummyConnector -from osm_ro_plugin.sdn_dummy import SdnDummyConnector -from osm_ro_plugin import vimconn, sdnconn from osm_ng_ro.vim_admin import LockRenew +from osm_ro_plugin import sdnconn, vimconn +from osm_ro_plugin.sdn_dummy import SdnDummyConnector +from osm_ro_plugin.vim_dummy import VimDummyConnector +import yaml __author__ = "Alfonso Tierno" @@ -125,6 +124,8 @@ class VimInteractionNet(VimInteractionBase): created = False created_items = {} target_vim = self.my_vims[ro_task["target_id"]] + mgmtnet = False + mgmtnet_defined_in_vim = False try: # FIND @@ -132,13 +133,15 @@ class VimInteractionNet(VimInteractionBase): # if management, get configuration of VIM if task["find_params"].get("filter_dict"): vim_filter = task["find_params"]["filter_dict"] - # mamagement network + # management network elif task["find_params"].get("mgmt"): + mgmtnet = True if deep_get( self.db_vims[ro_task["target_id"]], "config", "management_network_id", ): + mgmtnet_defined_in_vim = True vim_filter = { "id": self.db_vims[ro_task["target_id"]]["config"][ "management_network_id" @@ -149,6 +152,7 @@ class VimInteractionNet(VimInteractionBase): "config", "management_network_name", ): + mgmtnet_defined_in_vim = True vim_filter = { "name": self.db_vims[ro_task["target_id"]]["config"][ "management_network_name" @@ -163,11 +167,29 @@ class VimInteractionNet(VimInteractionBase): vim_nets = target_vim.get_network_list(vim_filter) if not vim_nets and not task.get("params"): - raise NsWorkerExceptionNotFound( - "Network not found with this criteria: '{}'".format( - task.get("find_params") + # If there is mgmt-network in the descriptor, + # there is no mapping of that network to a VIM network in the descriptor, + # also there is no mapping in the "--config" parameter or at VIM creation; + # that mgmt-network will be created. + if mgmtnet and not mgmtnet_defined_in_vim: + net_name = ( + vim_filter.get("name") + if vim_filter.get("name") + else vim_filter.get("id")[:16] + ) + vim_net_id, created_items = target_vim.new_network( + net_name, None + ) + self.logger.debug( + "Created mgmt network vim_net_id: {}".format(vim_net_id) + ) + created = True + else: + raise NsWorkerExceptionNotFound( + "Network not found with this criteria: '{}'".format( + task.get("find_params") + ) ) - ) elif len(vim_nets) > 1: raise NsWorkerException( "More than one network found with this criteria: '{}'".format( @@ -596,7 +618,7 @@ class VimInteractionImage(VimInteractionBase): ) elif len(vim_images) > 1: raise NsWorkerException( - "More than one network found with this criteria: '{}'".format( + "More than one image found with this criteria: '{}'".format( task["find_params"] ) ) @@ -921,7 +943,7 @@ class VimInteractionSdnNet(VimInteractionBase): else None, "service_endpoint_encapsulation_info": { "vlan": port.get("vlan"), - "mac": port.get("mac_address"), + "mac": port.get("mac-address"), "device_id": pmap.get("device_id") or port["compute_node"], "device_interface_id": pmap.get("device_interface_id") or port["pci"], @@ -1229,8 +1251,8 @@ class NsWorker(threading.Thread): return self.plugins[name] try: - for v in iter_entry_points("osm_ro{}.plugins".format(type), name): - self.plugins[name] = v.load() + for ep in entry_points(group="osm_ro{}.plugins".format(type), name=name): + self.plugins[name] = ep.load() except Exception as e: raise NsWorkerException("Cannot load plugin osm_{}: {}".format(name, e)) @@ -1758,6 +1780,11 @@ class NsWorker(threading.Thread): next_check_at = min( next_check_at, dependency_ro_task["to_check_at"] ) + # must allow dependent task to be processed first + # to do this set time after last_task_processed + next_check_at = max( + self.time_last_task_processed, next_check_at + ) break elif dependency_task["status"] == "FAILED": error_text = "Cannot {} {} because depends on failed {} {} id={}): {}".format( @@ -1848,6 +1875,11 @@ class NsWorker(threading.Thread): task["item"] ].refresh(ro_task) _update_refresh(new_status) + else: + # The refresh is updated to avoid set the value of "refresh_at" to + # default value (next_check_at = now + (24 * 60 * 60)) when status is BUILD, + # because it can happen that in this case the task is never processed + _update_refresh(task["status"]) except Exception as e: new_status = "FAILED"