X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Fns.py;h=28979b2e75dcc8e9e0a7042f057507faacb6c143;hb=refs%2Fchanges%2F94%2F13294%2F2;hp=83869bc0bef72e9c7b98dca79a7d7881a931dc5e;hpb=1ae3c56140dbb3426addacceffe85be0bdee3c45;p=osm%2FLCM.git diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index 83869bc..28979b2 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -124,7 +124,7 @@ from copy import copy, deepcopy from time import time from uuid import uuid4 -from random import randint +from random import SystemRandom __author__ = "Alfonso Tierno " @@ -135,7 +135,7 @@ class NsLcm(LcmBase): SUBOPERATION_STATUS_SKIP = -3 task_name_deploy_vca = "Deploying VCA" - def __init__(self, msg, lcm_tasks, config: LcmCfg, loop): + def __init__(self, msg, lcm_tasks, config: LcmCfg): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', @@ -145,7 +145,6 @@ class NsLcm(LcmBase): self.db = Database().instance.db self.fs = Filesystem().instance.fs - self.loop = loop self.lcm_tasks = lcm_tasks self.timeout = config.timeout self.ro_config = config.RO @@ -154,7 +153,6 @@ class NsLcm(LcmBase): # create N2VC connector self.n2vc = N2VCJujuConnector( log=self.logger, - loop=self.loop, on_update_db=self._on_update_n2vc_db, fs=self.fs, db=self.db, @@ -162,7 +160,6 @@ class NsLcm(LcmBase): self.conn_helm_ee = LCMHelmConn( log=self.logger, - loop=self.loop, vca_config=self.vca_config, on_update_db=self._on_update_n2vc_db, ) @@ -189,7 +186,6 @@ class NsLcm(LcmBase): kubectl_command=self.vca_config.kubectlpath, juju_command=self.vca_config.jujupath, log=self.logger, - loop=self.loop, on_update_db=self._on_update_k8s_db, fs=self.fs, db=self.db, @@ -212,7 +208,7 @@ class NsLcm(LcmBase): } # create RO client - self.RO = NgRoClient(self.loop, **self.ro_config.to_dict()) + self.RO = NgRoClient(**self.ro_config.to_dict()) self.op_status_map = { "instantiation": self.RO.status, @@ -1318,7 +1314,7 @@ class NsLcm(LcmBase): db_nsr_update["detailed-status"] = " ".join(stage) self.update_db_2("nsrs", nsr_id, db_nsr_update) self._write_op_status(nslcmop_id, stage) - await asyncio.sleep(15, loop=self.loop) + await asyncio.sleep(15) else: # timeout_ns_deploy raise NgRoException("Timeout waiting ns to deploy") @@ -1504,7 +1500,7 @@ class NsLcm(LcmBase): "target KDU={} is in error state".format(kdu_name) ) - await asyncio.sleep(10, loop=self.loop) + await asyncio.sleep(10) nb_tries += 1 raise LcmException("Timeout waiting KDU={} instantiated".format(kdu_name)) @@ -1535,7 +1531,7 @@ class NsLcm(LcmBase): "Not found _admin.deployed.RO.nsr_id for nsr_id: {}".format(nsr_id) ) - await asyncio.sleep(10, loop=self.loop) + await asyncio.sleep(10) # get ip address if not target_vdu_id: @@ -2296,9 +2292,7 @@ class NsLcm(LcmBase): self.logger.debug( logging_text + "Invoke and wait for placement optimization" ) - await self.msg.aiowrite( - "pla", "get_placement", {"nslcmopId": nslcmop_id}, loop=self.loop - ) + await self.msg.aiowrite("pla", "get_placement", {"nslcmopId": nslcmop_id}) db_poll_interval = 5 wait = db_poll_interval * 10 pla_result = None @@ -2428,6 +2422,7 @@ class NsLcm(LcmBase): for vdur in monitored_vdurs: vdu_id = vdur["vdu-id-ref"] metric_name = vnf_monitoring_param.get("performance-metric") + metric_name = f"osm_{metric_name}" vnf_member_index = vnfr["member-vnf-index-ref"] scalein_threshold = scaling_criteria.get( "scale-in-threshold" @@ -3052,7 +3047,6 @@ class NsLcm(LcmBase): "nslcmop_id": nslcmop_id, "operationState": nslcmop_operation_state, }, - loop=self.loop, ) except Exception as e: self.logger.error( @@ -4739,7 +4733,6 @@ class NsLcm(LcmBase): "operationState": nslcmop_operation_state, "autoremove": autoremove, }, - loop=self.loop, ) except Exception as e: self.logger.error( @@ -4997,7 +4990,7 @@ class NsLcm(LcmBase): ) ) # wait and retry - await asyncio.sleep(retries_interval, loop=self.loop) + await asyncio.sleep(retries_interval) else: if isinstance(e, asyncio.TimeoutError): e = N2VCException( @@ -5409,7 +5402,6 @@ class NsLcm(LcmBase): "nslcmop_id": nslcmop_id, "operationState": nslcmop_operation_state, }, - loop=self.loop, ) except Exception as e: self.logger.error( @@ -6240,7 +6232,7 @@ class NsLcm(LcmBase): and member_vnf_index ): msg.update({"vnf_member_index": member_vnf_index}) - await self.msg.aiowrite("ns", change_type, msg, loop=self.loop) + await self.msg.aiowrite("ns", change_type, msg) except Exception as e: self.logger.error( logging_text + "kafka_write notification Exception {}".format(e) @@ -7273,7 +7265,7 @@ class NsLcm(LcmBase): "nslcmop_id": nslcmop_id, "operationState": nslcmop_operation_state, } - await self.msg.aiowrite("ns", "scaled", msg, loop=self.loop) + await self.msg.aiowrite("ns", "scaled", msg) except Exception as e: self.logger.error( logging_text + "kafka_write notification Exception {}".format(e) @@ -7531,7 +7523,7 @@ class NsLcm(LcmBase): kdur_name = kdur.get("name") break - await asyncio.sleep(10, loop=self.loop) + await asyncio.sleep(10) else: if vdu_id and vdu_index is not None: raise LcmException( @@ -7565,7 +7557,7 @@ class NsLcm(LcmBase): not isinstance(job.get("job_name"), str) or vnfr_id not in job["job_name"] ): - job["job_name"] = vnfr_id + "_" + str(randint(1, 10000)) + job["job_name"] = vnfr_id + "_" + str(SystemRandom().randint(1, 10000)) job["nsr_id"] = nsr_id job["vnfr_id"] = vnfr_id return job_list @@ -7774,7 +7766,7 @@ class NsLcm(LcmBase): "nslcmop_id": nslcmop_id, "operationState": nslcmop_operation_state, } - await self.msg.aiowrite("ns", "migrated", msg, loop=self.loop) + await self.msg.aiowrite("ns", "migrated", msg) except Exception as e: self.logger.error( logging_text + "kafka_write notification Exception {}".format(e) @@ -7898,9 +7890,9 @@ class NsLcm(LcmBase): for target_vdu in target_vdu_list: deploy_params_vdu = target_vdu # Set run-day1 vnf level value if not vdu level value exists - if not deploy_params_vdu.get("run-day1") and target_vnf[ - "additionalParams" - ].get("run-day1"): + if not deploy_params_vdu.get("run-day1") and target_vnf.get( + "additionalParams", {} + ).get("run-day1"): deploy_params_vdu["run-day1"] = target_vnf[ "additionalParams" ].get("run-day1") @@ -8060,7 +8052,7 @@ class NsLcm(LcmBase): "nslcmop_id": nslcmop_id, "operationState": nslcmop_operation_state, } - await self.msg.aiowrite("ns", "healed", msg, loop=self.loop) + await self.msg.aiowrite("ns", "healed", msg) except Exception as e: self.logger.error( logging_text + "kafka_write notification Exception {}".format(e) @@ -8741,7 +8733,7 @@ class NsLcm(LcmBase): self.logger.debug("Wait Heal RO > {}".format(operational_status_ro)) if operational_status_ro != "healing": break - await asyncio.sleep(15, loop=self.loop) + await asyncio.sleep(15) else: # timeout_ns_deploy raise NgRoException("Timeout waiting ns to deploy") @@ -8839,7 +8831,7 @@ class NsLcm(LcmBase): "nslcmop_id": nslcmop_id, "operationState": nslcmop_operation_state, } - await self.msg.aiowrite("ns", "verticalscaled", msg, loop=self.loop) + await self.msg.aiowrite("ns", "verticalscaled", msg) except Exception as e: self.logger.error( logging_text + "kafka_write notification Exception {}".format(e)