From: tierno Date: Mon, 28 Jan 2019 16:18:56 +0000 (+0000) Subject: On ns/netslice terminate, sends to kafka for NBI to delete X-Git-Tag: v5.0.3~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=c2564fecb25a5238d20edd628c9cdf94569e7625;p=osm%2FLCM.git On ns/netslice terminate, sends to kafka for NBI to delete Change-Id: Ibaaf15a824505bd2b93d5ece8e8d46ef60932f00 Signed-off-by: tierno --- diff --git a/osm_lcm/lcm.py b/osm_lcm/lcm.py index d967c03..44f2b2e 100644 --- a/osm_lcm/lcm.py +++ b/osm_lcm/lcm.py @@ -40,12 +40,12 @@ from n2vc import version as n2vc_version __author__ = "Alfonso Tierno" -min_RO_version = [0, 6, 0] +min_RO_version = [0, 6, 3] min_n2vc_version = "0.0.2" min_common_version = "0.1.11" # uncomment if LCM is installed as library and installed, and get them from __init__.py -lcm_version = '0.1.31' -lcm_version_date = '2019-01-16' +lcm_version = '0.1.32' +lcm_version_date = '2019-01-28' class Lcm: @@ -64,6 +64,8 @@ class Lcm: self.msg = None self.fs = None self.pings_not_received = 1 + self.consecutive_errors = 0 + self.first_start = False # contains created tasks/futures to be able to cancel self.lcm_tasks = TaskRegistry() @@ -145,15 +147,17 @@ class Lcm: raise LcmException("Invalid configuration param '{}' at '[storage]':'driver'".format( config["storage"]["driver"])) - if config["message"]["driver"] == "local": + config_message = config["message"].copy() + config_message["loop"] = self.loop + if config_message["driver"] == "local": self.msg = msglocal.MsgLocal() - self.msg.connect(config["message"]) - elif config["message"]["driver"] == "kafka": + self.msg.connect(config_message) + elif config_message["driver"] == "kafka": self.msg = msgkafka.MsgKafka() - self.msg.connect(config["message"]) + self.msg.connect(config_message) else: raise LcmException("Invalid configuration param '{}' at '[message]':'driver'".format( - config["storage"]["driver"])) + config["message"]["driver"])) except (DbException, FsException, MsgException) as e: self.logger.critical(str(e), exc_info=True) raise LcmException(str(e)) @@ -273,6 +277,7 @@ class Lcm: self.lcm_tasks.register("ns", nsr_id, nslcmop_id, "ns_scale", task) return elif command == "show": + nsr_id = params try: db_nsr = self.db.get_one("nsrs", {"_id": nsr_id}) print("nsr:\n _id={}\n operational-status: {}\n config-status: {}" @@ -307,6 +312,7 @@ class Lcm: self.lcm_tasks.register("nsi", nsir_id, nsilcmop_id, "nsi_terminate", task) return elif command == "show": + nsir_id = params try: db_nsir = self.db.get_one("nsirs", {"_id": nsir_id}) print("nsir:\n _id={}\n operational-status: {}\n config-status: {}" diff --git a/osm_lcm/netslice.py b/osm_lcm/netslice.py index e0a08e3..340c858 100644 --- a/osm_lcm/netslice.py +++ b/osm_lcm/netslice.py @@ -406,6 +406,7 @@ class NetsliceLcm(LcmBase): RO = ROclient.ROClient(self.loop, **self.ro_config) failed_detail = [] # annotates all failed error messages nsilcmop_operation_state = None + autoremove = False # autoremove after terminated try: step = "Getting nsir={} from db".format(nsir_id) db_nsir = self.db.get_one("nsis", {"_id": nsir_id}) @@ -543,9 +544,26 @@ class NetsliceLcm(LcmBase): failed_detail.append("RO_ns_id={} delete error: {}".format(RO_nsir_id, e)) self.logger.error(logging_text + failed_detail[-1]) + if failed_detail: + self.logger.error(logging_text + " ;".join(failed_detail)) + db_nsir_update["operational-status"] = "failed" + db_nsir_update["detailed-status"] = "Deletion errors " + "; ".join(failed_detail) + db_nsilcmop_update["detailed-status"] = "; ".join(failed_detail) + db_nsilcmop_update["operationState"] = nsilcmop_operation_state = "FAILED" + db_nsilcmop_update["statusEnteredTime"] = time() + else: + db_nsir_update["operational-status"] = "terminated" + db_nsir_update["detailed-status"] = "done" + db_nsir_update["config-status"] = "configured" + db_nsir_update["_admin.nsiState"] = "NOT_INSTANTIATED" + db_nsilcmop_update["detailed-status"] = "Done" + db_nsilcmop_update["operationState"] = nsilcmop_operation_state = "COMPLETED" + db_nsilcmop_update["statusEnteredTime"] = time() + if db_nsilcmop["operationParams"].get("autoremove"): + autoremove = True + db_nsir_update["operational-status"] = "terminated" - db_nsir_update["config-status"] = "configured" - db_nsir_update["detailed-status"] = "done" + db_nsir_update["config-status"] = "configured" db_nsilcmop_update["operationState"] = nsilcmop_operation_state = "COMPLETED" db_nsilcmop_update["statusEnteredTime"] = time() db_nsilcmop_update["detailed-status"] = "done" @@ -573,7 +591,6 @@ class NetsliceLcm(LcmBase): try: if db_nsir: db_nsir_update["_admin.nsilcmop"] = None - db_nsir_update["_admin.nsiState"] = "TERMINATED" self.update_db_2("nsis", nsir_id, db_nsir_update) if db_nsilcmop: self.update_db_2("nsilcmops", nsilcmop_id, db_nsilcmop_update) @@ -583,7 +600,9 @@ class NetsliceLcm(LcmBase): if nsilcmop_operation_state: try: await self.msg.aiowrite("nsi", "terminated", {"nsir_id": nsir_id, "nsilcmop_id": nsilcmop_id, - "operationState": nsilcmop_operation_state}) + "operationState": nsilcmop_operation_state, + "autoremove": autoremove}, + loop=self.loop) except Exception as e: self.logger.error(logging_text + "kafka_write notification Exception {}".format(e)) self.logger.debug(logging_text + "Exit") diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index 951ad76..e6caced 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -1116,6 +1116,7 @@ class NsLcm(LcmBase): db_nsr_update = {"_admin.nslcmop": nslcmop_id} db_nslcmop_update = {} nslcmop_operation_state = None + autoremove = False # autoremove after terminated try: step = "Getting nslcmop={} from db".format(nslcmop_id) db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id}) @@ -1288,18 +1289,6 @@ class NsLcm(LcmBase): db_nslcmop_update["detailed-status"] = "; ".join(failed_detail) db_nslcmop_update["operationState"] = nslcmop_operation_state = "FAILED" db_nslcmop_update["statusEnteredTime"] = time() - elif db_nslcmop["operationParams"].get("autoremove"): - self.db.del_one("nsrs", {"_id": nsr_id}) - db_nsr = None - db_nsr_update.clear() - self.db.del_list("nslcmops", {"nsInstanceId": nsr_id}) - db_nslcmop = None - nslcmop_operation_state = "COMPLETED" - db_nslcmop_update.clear() - self.db.del_list("vnfrs", {"nsr-id-ref": nsr_id}) - self.db.set_list("pdus", {"_admin.usage.nsr_id": nsr_id}, - {"_admin.usageState": "NOT_IN_USE", "_admin.usage": None}) - self.logger.debug(logging_text + "Delete from database") else: db_nsr_update["operational-status"] = "terminated" db_nsr_update["detailed-status"] = "Done" @@ -1307,6 +1296,8 @@ class NsLcm(LcmBase): db_nslcmop_update["detailed-status"] = "Done" db_nslcmop_update["operationState"] = nslcmop_operation_state = "COMPLETED" db_nslcmop_update["statusEnteredTime"] = time() + if db_nslcmop["operationParams"].get("autoremove"): + autoremove = True except (ROclient.ROClientException, DbException) as e: self.logger.error(logging_text + "Exit Exception {}".format(e)) @@ -1333,7 +1324,8 @@ class NsLcm(LcmBase): if nslcmop_operation_state: try: await self.msg.aiowrite("ns", "terminated", {"nsr_id": nsr_id, "nslcmop_id": nslcmop_id, - "operationState": nslcmop_operation_state}, + "operationState": nslcmop_operation_state, + "autoremove": autoremove}, loop=self.loop) except Exception as e: self.logger.error(logging_text + "kafka_write notification Exception {}".format(e))