From 47e86b567ff08adb8c77ce35a8e4feb4c7d59a3d Mon Sep 17 00:00:00 2001 From: tierno Date: Wed, 10 Oct 2018 14:05:55 +0200 Subject: [PATCH] feature 6314: Control LCM operations over ns instance Change-Id: I8ed95199f1f2352e8f9aebf7c7ff11c7b609ec8a Signed-off-by: tierno --- osm_lcm/lcm.py | 2 +- osm_lcm/ns.py | 60 +++++++++++++++++++++++++++++++++++++++------- osm_lcm/vim_sdn.py | 8 +++++-- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/osm_lcm/lcm.py b/osm_lcm/lcm.py index be31bf36..1e6bba1c 100644 --- a/osm_lcm/lcm.py +++ b/osm_lcm/lcm.py @@ -27,7 +27,7 @@ min_RO_version = [0, 5, 72] min_n2vc_version = "0.0.2" min_common_version = "0.1.7" # uncomment if LCM is installed as library and installed, and get them from __init__.py -lcm_version = '0.1.17' +lcm_version = '0.1.18' lcm_version_date = '2018-10-11' diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index db022fd3..4b4adbf1 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -444,7 +444,7 @@ class NsLcm(LcmBase): # get all needed from database db_nsr = None db_nslcmop = None - db_nsr_update = {} + db_nsr_update = {"_admin.nslcmop": nslcmop_id} db_nslcmop_update = {} nslcmop_operation_state = None db_vnfrs = {} @@ -460,6 +460,18 @@ class NsLcm(LcmBase): ns_params = db_nsr.get("instantiate_params") nsd = db_nsr["nsd"] nsr_name = db_nsr["name"] # TODO short-name?? + + # look if previous tasks in process + task_name, task_dependency = self.lcm_tasks.lookfor_related("ns", nsr_id, nslcmop_id) + if task_dependency: + step = db_nslcmop_update["detailed-status"] = \ + "Waiting for related tasks to be completed: {}".format(task_name) + self.logger.debug(logging_text + step) + self.update_db_2("nslcmops", nslcmop_id, db_nslcmop_update) + _, pending = await asyncio.wait(task_dependency, timeout=3600) + if pending: + raise LcmException("Timeout waiting related tasks to be completed") + needed_vnfd = {} vnfr_filter = {"nsr-id-ref": nsr_id, "member-vnf-index-ref": None} for c_vnf in nsd["constituent-vnfd"]: @@ -858,7 +870,8 @@ class NsLcm(LcmBase): db_nslcmop_update["detailed-status"] = "FAILED {}: {}".format(step, exc) db_nslcmop_update["operationState"] = nslcmop_operation_state = "FAILED" db_nslcmop_update["statusEnteredTime"] = time() - if db_nsr_update: + if db_nsr: + db_nsr_update["_admin.nslcmop"] = None self.update_db_2("nsrs", nsr_id, db_nsr_update) if db_nslcmop_update: self.update_db_2("nslcmops", nslcmop_id, db_nslcmop_update) @@ -881,7 +894,7 @@ class NsLcm(LcmBase): failed_detail = [] # annotates all failed error messages vca_task_list = [] vca_task_dict = {} - db_nsr_update = {} + db_nsr_update = {"_admin.nslcmop": nslcmop_id} db_nslcmop_update = {} nslcmop_operation_state = None try: @@ -1088,7 +1101,8 @@ class NsLcm(LcmBase): db_nslcmop_update["statusEnteredTime"] = time() if db_nslcmop_update: self.update_db_2("nslcmops", nslcmop_id, db_nslcmop_update) - if db_nsr_update: + if db_nsr: + db_nsr_update["_admin.nslcmop"] = None self.update_db_2("nsrs", nsr_id, db_nsr_update) if nslcmop_operation_state: try: @@ -1162,6 +1176,7 @@ class NsLcm(LcmBase): # get all needed from database db_nsr = None db_nslcmop = None + db_nsr_update = {"_admin.nslcmop": nslcmop_id} db_nslcmop_update = {} nslcmop_operation_state = None exc = None @@ -1174,6 +1189,17 @@ class NsLcm(LcmBase): vnf_index = db_nslcmop["operationParams"]["member_vnf_index"] vdu_id = db_nslcmop["operationParams"].get("vdu_id") + # look if previous tasks in process + task_name, task_dependency = self.lcm_tasks.lookfor_related("ns", nsr_id, nslcmop_id) + if task_dependency: + step = db_nslcmop_update["detailed-status"] = \ + "Waiting for related tasks to be completed: {}".format(task_name) + self.logger.debug(logging_text + step) + self.update_db_2("nslcmops", nslcmop_id, db_nslcmop_update) + _, pending = await asyncio.wait(task_dependency, timeout=3600) + if pending: + raise LcmException("Timeout waiting related tasks to be completed") + # TODO check if ns is in a proper status primitive = db_nslcmop["operationParams"]["primitive"] primitive_params = db_nslcmop["operationParams"]["primitive_params"] @@ -1201,6 +1227,9 @@ class NsLcm(LcmBase): db_nslcmop_update["statusEnteredTime"] = time() if db_nslcmop_update: self.update_db_2("nslcmops", nslcmop_id, db_nslcmop_update) + if db_nsr: + db_nsr_update["_admin.nslcmop"] = None + self.update_db_2("nsrs", nsr_id, db_nsr_update) self.logger.debug(logging_text + "Exit") if nslcmop_operation_state: try: @@ -1219,7 +1248,7 @@ class NsLcm(LcmBase): db_nslcmop = None db_nslcmop_update = {} nslcmop_operation_state = None - db_nsr_update = {} + db_nsr_update = {"_admin.nslcmop": nslcmop_id} exc = None # in case of error, indicates what part of scale was failed to put nsr at error status scale_process = None @@ -1232,6 +1261,18 @@ class NsLcm(LcmBase): db_nsr = self.db.get_one("nsrs", {"_id": nsr_id}) old_operational_status = db_nsr["operational-status"] old_config_status = db_nsr["config-status"] + + # look if previous tasks in process + task_name, task_dependency = self.lcm_tasks.lookfor_related("ns", nsr_id, nslcmop_id) + if task_dependency: + step = db_nslcmop_update["detailed-status"] = \ + "Waiting for related tasks to be completed: {}".format(task_name) + self.logger.debug(logging_text + step) + self.update_db_2("nslcmops", nslcmop_id, db_nslcmop_update) + _, pending = await asyncio.wait(task_dependency, timeout=3600) + if pending: + raise LcmException("Timeout waiting related tasks to be completed") + step = "Parsing scaling parameters" db_nsr_update["operational-status"] = "scaling" self.update_db_2("nsrs", nsr_id, db_nsr_update) @@ -1364,7 +1405,6 @@ class NsLcm(LcmBase): RO_desc = await RO.create_action("ns", RO_nsr_id, {"vdu-scaling": RO_scaling_info}) db_nsr_update["_admin.scaling-group.{}.nb-scale-op".format(admin_scale_index)] = nb_scale_op db_nsr_update["_admin.scaling-group.{}.time".format(admin_scale_index)] = time() - # TODO mark db_nsr_update as scaling # wait until ready RO_nslcmop_id = RO_desc["instance_action_id"] db_nslcmop_update["_admin.deploy.RO"] = RO_nslcmop_id @@ -1465,8 +1505,8 @@ class NsLcm(LcmBase): else: raise LcmException("Invalid vnfd descriptor at scaling-group-descriptor[name='{}']:" "scaling-config-action[vnf-config-primitive-name-ref='{}'] does not " - "match any vnf-cnfiguration:config-primitive".format(scaling_group, - config_primitive)) + "match any vnf-configuration:config-primitive".format(scaling_group, + config_primitive)) scale_process = "VCA" db_nsr_update["config-status"] = "configuring post-scaling" @@ -1505,6 +1545,7 @@ class NsLcm(LcmBase): db_nsr_update["operational-status"] = old_operational_status db_nsr_update["config-status"] = old_config_status db_nsr_update["detailed-status"] = "" + db_nsr_update["_admin.nslcmop"] = None if scale_process: if "VCA" in scale_process: db_nsr_update["config-status"] = "failed" @@ -1514,7 +1555,8 @@ class NsLcm(LcmBase): exc) if db_nslcmop_update: self.update_db_2("nslcmops", nslcmop_id, db_nslcmop_update) - if db_nsr_update: + if db_nsr: + db_nsr_update["_admin.nslcmop"] = None self.update_db_2("nsrs", nsr_id, db_nsr_update) if nslcmop_operation_state: try: diff --git a/osm_lcm/vim_sdn.py b/osm_lcm/vim_sdn.py index e41d2175..cf836bf6 100644 --- a/osm_lcm/vim_sdn.py +++ b/osm_lcm/vim_sdn.py @@ -124,7 +124,9 @@ class VimLcm(LcmBase): step = "Waiting for related tasks to be completed: {}".format(task_name) self.logger.debug(logging_text + step) # TODO write this to database - await asyncio.wait(task_dependency, timeout=3600) + _, pending = await asyncio.wait(task_dependency, timeout=3600) + if pending: + raise LcmException("Timeout waiting related tasks to be completed") if db_vim.get("_admin") and db_vim["_admin"].get("deployed") and db_vim["_admin"]["deployed"].get("RO"): if vim_content.get("config") and vim_content["config"].get("sdn-controller"): @@ -137,7 +139,9 @@ class VimLcm(LcmBase): step = "Waiting for related tasks to be completed: {}".format(task_name) self.logger.debug(logging_text + step) # TODO write this to database - await asyncio.wait(task_dependency, timeout=3600) + _, pending = await asyncio.wait(task_dependency, timeout=3600) + if pending: + raise LcmException("Timeout waiting related tasks to be completed") if db_sdn.get("_admin") and db_sdn["_admin"].get("deployed") and db_sdn["_admin"]["deployed"].get( "RO"): -- 2.25.1