From: tierno Date: Tue, 28 Aug 2018 10:13:45 +0000 (+0000) Subject: fix issues deleting ns. Wait until it is deleted from VIM X-Git-Tag: v5.0.0~30 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=fa66d156a8b8c4b8252b55f13cd1825774f21b15;hp=86aa62f73881f01687cc9f3f5112552c1788fa54;p=osm%2FLCM.git fix issues deleting ns. Wait until it is deleted from VIM Change-Id: I31f5f667aed8e829c8a4599c8f0d60421e8aab72 Signed-off-by: tierno --- diff --git a/.gitignore-common b/.gitignore-common index f0f10bd..099610f 100644 --- a/.gitignore-common +++ b/.gitignore-common @@ -32,4 +32,5 @@ osm_nbi/test/temp build dist *.egg-info +.eggs diff --git a/osm_lcm/ROclient.py b/osm_lcm/ROclient.py index fe12f8b..b3bc5d5 100644 --- a/osm_lcm/ROclient.py +++ b/osm_lcm/ROclient.py @@ -693,7 +693,14 @@ class ROClient: all_tenants = None with aiohttp.ClientSession(loop=self.loop) as session: - return await self._del_item(session, self.client_to_RO[item], item_id_name, all_tenants=all_tenants) + result = await self._del_item(session, self.client_to_RO[item], item_id_name, all_tenants=all_tenants) + # in case of ns delete, get the action_id embeded in text + if item == "ns" and result.get("result"): + _, _, action_id = result["result"].partition("action_id=") + action_id, _, _ = action_id.partition(" ") + if action_id: + result["action_id"] = action_id + return result except aiohttp.errors.ClientOSError as e: raise ROClientException(e, http_code=504) except asyncio.TimeoutError: diff --git a/osm_lcm/lcm.py b/osm_lcm/lcm.py index 310c434..1c1bb11 100644 --- a/osm_lcm/lcm.py +++ b/osm_lcm/lcm.py @@ -32,8 +32,8 @@ from time import time __author__ = "Alfonso Tierno" min_RO_version = [0, 5, 72] # uncomment if LCM is installed as library and installed, and get them from __init__.py -lcm_version = '0.1.12' -lcm_version_date = '2018-08-23' +lcm_version = '0.1.13' +lcm_version_date = '2018-08-28' class LcmException(Exception): @@ -127,9 +127,10 @@ class TaskRegistry: for task_name, task in self.task_registry[topic][_id][op_id].items(): if target_task_name and target_task_name != task_name: continue - result = task.cancel() - if result: - self.logger.debug("{} _id={} order_id={} task={} cancelled".format(topic, _id, op_id, task_name)) + # result = + task.cancel() + # if result: + # self.logger.debug("{} _id={} order_id={} task={} cancelled".format(topic, _id, op_id, task_name)) class Lcm: @@ -1438,28 +1439,61 @@ class Lcm: # remove from RO RO_fail = False RO = ROclient.ROClient(self.loop, **self.ro_config) + # Delete ns - if nsr_lcm and nsr_lcm.get("RO") and nsr_lcm["RO"].get("nsr_id"): - RO_nsr_id = nsr_lcm["RO"]["nsr_id"] - try: + RO_nsr_id = RO_delete_action = None + if nsr_lcm and nsr_lcm.get("RO"): + RO_nsr_id = nsr_lcm["RO"].get("nsr_id") + RO_delete_action = nsr_lcm["RO"].get("nsr_delete_action_id") + try: + if RO_nsr_id: step = db_nsr_update["detailed-status"] = db_nslcmop_update["detailed-status"] = "Deleting ns at RO" self.logger.debug(logging_text + step) - await RO.delete("ns", RO_nsr_id) + desc = await RO.delete("ns", RO_nsr_id) + RO_delete_action = desc["action_id"] + db_nsr_update["_admin.deployed.RO.nsr_delete_action_id"] = RO_delete_action db_nsr_update["_admin.deployed.RO.nsr_id"] = None db_nsr_update["_admin.deployed.RO.nsr_status"] = "DELETED" - except ROclient.ROClientException as e: - if e.http_code == 404: # not found - db_nsr_update["_admin.deployed.RO.nsr_id"] = None - db_nsr_update["_admin.deployed.RO.nsr_status"] = "DELETED" - self.logger.debug(logging_text + "RO_ns_id={} already deleted".format(RO_nsr_id)) - elif e.http_code == 409: # conflict - failed_detail.append("RO_ns_id={} delete conflict: {}".format(RO_nsr_id, e)) - self.logger.debug(logging_text + failed_detail[-1]) - RO_fail = True - else: - failed_detail.append("RO_ns_id={} delete error: {}".format(RO_nsr_id, e)) - self.logger.error(logging_text + failed_detail[-1]) - RO_fail = True + if RO_delete_action: + # wait until NS is deleted from VIM + step = detailed_status = "Waiting ns deleted from VIM. RO_id={}".format(RO_nsr_id) + detailed_status_old = None + self.logger.debug(logging_text + step) + + delete_timeout = 20 * 60 # 20 minutes + while delete_timeout > 0: + desc = await RO.show("ns", item_id_name=RO_nsr_id, extra_item="action", + extra_item_id=RO_delete_action) + ns_status, ns_status_info = RO.check_action_status(desc) + if ns_status == "ERROR": + raise ROclient.ROClientException(ns_status_info) + elif ns_status == "BUILD": + detailed_status = step + "; {}".format(ns_status_info) + elif ns_status == "ACTIVE": + break + else: + assert False, "ROclient.check_action_status returns unknown {}".format(ns_status) + await asyncio.sleep(5, loop=self.loop) + delete_timeout -= 5 + if detailed_status != detailed_status_old: + detailed_status_old = db_nslcmop_update["detailed-status"] = detailed_status + self.update_db_2("nslcmops", nslcmop_id, db_nslcmop_update) + else: # delete_timeout <= 0: + raise ROclient.ROClientException("Timeout waiting ns deleted from VIM") + + except ROclient.ROClientException as e: + if e.http_code == 404: # not found + db_nsr_update["_admin.deployed.RO.nsr_id"] = None + db_nsr_update["_admin.deployed.RO.nsr_status"] = "DELETED" + self.logger.debug(logging_text + "RO_ns_id={} already deleted".format(RO_nsr_id)) + elif e.http_code == 409: # conflict + failed_detail.append("RO_ns_id={} delete conflict: {}".format(RO_nsr_id, e)) + self.logger.debug(logging_text + failed_detail[-1]) + RO_fail = True + else: + failed_detail.append("RO_ns_id={} delete error: {}".format(RO_nsr_id, e)) + self.logger.error(logging_text + failed_detail[-1]) + RO_fail = True # Delete nsd if not RO_fail and nsr_lcm and nsr_lcm.get("RO") and nsr_lcm["RO"].get("nsd_id"): diff --git a/setup.py b/setup.py index 47ca680..ffef539 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,11 @@ setup( "git+https://osm.etsi.org/gerrit/osm/common.git@master#egg=osm-common-0.1.4" ], install_requires=[ - 'pymongo', 'PyYAML', 'aiohttp' + 'pymongo', + 'PyYAML', + 'aiohttp==0.20.2', + # TODO this is version installed by 'apt python3-aiohttp' on Ubuntu Sserver 14.04 + # version installed by pip 3.3.2 is not compatible. Code should be migrated to this version and use pip3 # 'osm-common', ], setup_requires=['setuptools-version-command'],