X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=osm_lcm%2Fnetslice.py;h=6f4e5479b9d62329f6838702e542dc2fedc039f8;hb=refs%2Fchanges%2F57%2F9557%2F3;hp=fe8a7b9ad31c03599dfa49661c1a6aa52d2681d7;hpb=744303e157182880777f169259ea7cd4431af1d7;p=osm%2FLCM.git diff --git a/osm_lcm/netslice.py b/osm_lcm/netslice.py index fe8a7b9..6f4e547 100644 --- a/osm_lcm/netslice.py +++ b/osm_lcm/netslice.py @@ -17,7 +17,7 @@ import asyncio import logging import logging.handlers import traceback -from osm_lcm import ROclient, ns +from osm_lcm import ROclient from osm_lcm.lcm_utils import LcmException, LcmBase, populate_dict, get_iterable, deep_get from osm_common.dbbase import DbException from time import time @@ -31,7 +31,7 @@ class NetsliceLcm(LcmBase): timeout_nsi_deploy = 2 * 3600 # default global timeout for deployment a nsi - def __init__(self, db, msg, fs, lcm_tasks, config, loop): + def __init__(self, db, msg, fs, lcm_tasks, config, loop, ns): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', @@ -41,7 +41,7 @@ class NetsliceLcm(LcmBase): self.logger = logging.getLogger('lcm.netslice') self.loop = loop self.lcm_tasks = lcm_tasks - self.ns = ns.NsLcm(db, msg, fs, lcm_tasks, config, loop) + self.ns = ns self.ro_config = config["ro_config"] self.timeout = config["timeout"] @@ -248,7 +248,7 @@ class NetsliceLcm(LcmBase): if nss_cp_item["nss-ref"] == nss["nss-id"]: db_nsds = self.db.get_one("nsds", {"_id": nss["nsdId"]}) # Go for nsd, and search the CP that match with nst:CP to get vld-id-ref - for cp_nsd in db_nsds["connection-point"]: + for cp_nsd in db_nsds.get("connection-point", ()): if cp_nsd["name"] == nss_cp_item["nsd-connection-point-ref"]: if nslcmop.get("operationParams"): if nslcmop["operationParams"].get("nsName") == nss["nsName"]: @@ -288,19 +288,19 @@ class NetsliceLcm(LcmBase): # Slice status Creating db_nsir_update["detailed-status"] = "creating" db_nsir_update["operational-status"] = "init" - self.update_db_2("nsis", nsir_id, db_nsir_update) + db_nsir_update["_admin.nsiState"] = "INSTANTIATED" - step = "Creating netslice VLDs before NS instantiation" + step = "Instantiating netslice VLDs before NS instantiation" # Creating netslice VLDs networking before NS instantiation - db_nsir_update["detailed-status"] = "Creating netslice-vld at RO" + db_nsir_update["detailed-status"] = step self.update_db_2("nsis", nsir_id, db_nsir_update) db_nsir_update["_admin.deployed.RO"] = db_nsir_admin["deployed"]["RO"] for vld_item in get_iterable(nsir_admin, "netslice-vld"): await netslice_scenario_create(self, vld_item, nsir_id, db_nsir, db_nsir_admin, db_nsir_update) self.update_db_2("nsis", nsir_id, db_nsir_update) - step = "Creating netslice subnets at RO" - db_nsir_update["detailed-status"] = "Creating netslice subnets at RO" + step = "Instantiating netslice subnets" + db_nsir_update["detailed-status"] = step self.update_db_2("nsis", nsir_id, db_nsir_update) db_nsir = self.db.get_one("nsis", {"_id": nsir_id}) @@ -316,9 +316,6 @@ class NetsliceLcm(LcmBase): # self.update_db_2("nsis", nsir_id, db_nsir_update) # Iterate over the network services operation ids to instantiate NSs - # TODO: (future improvement) look another way check the tasks instead of keep asking - # -> https://docs.python.org/3/library/asyncio-task.html#waiting-primitives - # steps: declare ns_tasks, add task when terminate is called, await asyncio.wait(vca_task_list, timeout=300) step = "Instantiating Netslice Subnets" db_nsir = self.db.get_one("nsis", {"_id": nsir_id}) nslcmop_ids = db_nsilcmop["operationParams"].get("nslcmops_ids") @@ -331,16 +328,15 @@ class NetsliceLcm(LcmBase): self.lcm_tasks.register("ns", nsr_id, nslcmop_id, "ns_instantiate", task) # Wait until Network Slice is ready - step = nsir_status_detailed = " Waiting nsi ready. nsi_id={}".format(nsir_id) + step = " Waiting nsi ready." nsrs_detailed_list_old = None self.logger.debug(logging_text + step) - # TODO: substitute while for await (all task to be done or not) + # For HA, it is checked from database, as the ns operation may be managed by other LCM worker while time() <= start_deploy + timeout_nsi_deploy: # Check ns instantiation status nsi_ready = True nsir = self.db.get_one("nsis", {"_id": nsir_id}) - nsir_admin = nsir["_admin"] nsrs_detailed_list = nsir["_admin"]["nsrs-detailed-list"] nsrs_detailed_list_new = [] for nslcmop_item in nslcmop_ids: @@ -350,8 +346,7 @@ class NetsliceLcm(LcmBase): for nss in nsrs_detailed_list: if nss["nsrId"] == nslcmop["nsInstanceId"]: nss.update({"nsrId": nslcmop["nsInstanceId"], "status": nslcmop["operationState"], - "detailed-status": - nsir_status_detailed + "; {}".format(nslcmop.get("detailed-status")), + "detailed-status": nslcmop.get("detailed-status"), "instantiated": True}) nsrs_detailed_list_new.append(nss) if status not in ["COMPLETED", "PARTIALLY_COMPLETED", "FAILED", "FAILED_TEMP"]: @@ -362,17 +357,22 @@ class NetsliceLcm(LcmBase): self.update_db_2("nsis", nsir_id, {"_admin.nsrs-detailed-list": nsrs_detailed_list_new}) if nsi_ready: - step = "Network Slice Instance is ready. nsi_id={}".format(nsir_id) - for items in nsrs_detailed_list: - if "FAILED" in items.values(): - raise LcmException("Error deploying NSI: {}".format(nsir_id)) + error_list = [] + step = "Network Slice Instance instantiated" + for nss in nsrs_detailed_list: + if nss["status"] in ("FAILED", "FAILED_TEMP"): + error_list.append("NS {} {}: {}".format(nss["nsrId"], nss["status"], + nss["detailed-status"])) + if error_list: + step = "instantiating" + raise LcmException("; ".join(error_list)) break # TODO: future improvement due to synchronism -> await asyncio.wait(vca_task_list, timeout=300) await asyncio.sleep(5, loop=self.loop) else: # timeout_nsi_deploy reached: - raise LcmException("Timeout waiting nsi to be ready. nsi_id={}".format(nsir_id)) + raise LcmException("Timeout waiting nsi to be ready.") db_nsir_update["operational-status"] = "running" db_nsir_update["detailed-status"] = "done" @@ -397,13 +397,13 @@ class NetsliceLcm(LcmBase): if db_nsir: db_nsir_update["detailed-status"] = "ERROR {}: {}".format(step, exc) db_nsir_update["operational-status"] = "failed" + db_nsir_update["config-status"] = "configured" if db_nsilcmop: db_nsilcmop_update["detailed-status"] = "FAILED {}: {}".format(step, exc) db_nsilcmop_update["operationState"] = nsilcmop_operation_state = "FAILED" db_nsilcmop_update["statusEnteredTime"] = time() try: if db_nsir: - db_nsir_update["_admin.nsiState"] = "INSTANTIATED" db_nsir_update["_admin.nsilcmop"] = None self.update_db_2("nsis", nsir_id, db_nsir_update) if db_nsilcmop: