Bug 2215 fixed
[osm/MON.git] / osm_mon / collector / vnf_collectors / juju.py
index 36aabab..fbc6bc2 100644 (file)
@@ -39,7 +39,6 @@ class VCACollector(BaseCollector):
     def __init__(self, config: Config):
         super().__init__(config)
         self.common_db = CommonDbClient(config)
-        self.loop = asyncio.get_event_loop()
         # host = config.get("vca", "host")
         # port = config.get("vca", "port") if "port" in config.conf["vca"] else 17070
 
@@ -60,7 +59,6 @@ class VCACollector(BaseCollector):
             db=self.common_db.common_db,
             fs=object(),
             log=log,
-            loop=self.loop,
             on_update_db=None,
         )
 
@@ -88,7 +86,11 @@ class VCACollector(BaseCollector):
         day12ops = ops_config.get("day1-2", [])
         for day12op in day12ops:
             if day12op and "metrics" in day12op:
-                vdur = next(filter(lambda vdur: vdur["vdu-id-ref"] == day12op["id"], vnfr["vdur"]))
+                vdur = next(
+                    filter(
+                        lambda vdur: vdur["vdu-id-ref"] == day12op["id"], vnfr["vdur"]
+                    )
+                )
 
                 # This avoids errors when vdur records have not been completely filled
                 if vdur and "name" in vdur:
@@ -103,14 +105,16 @@ class VCACollector(BaseCollector):
                         log.warning(repr(e))
                         continue
                     # This avoids errors before application and model is not ready till they are occured
-                    if vca_deployment_info.get("model") and vca_deployment_info.get("application"):
-                        measures = self.loop.run_until_complete(
+                    if vca_deployment_info.get("model") and vca_deployment_info.get(
+                        "application"
+                    ):
+                        measures = asyncio.run(
                             self.n2vc.get_metrics(
                                 vca_deployment_info["model"],
                                 vca_deployment_info["application"],
                                 vca_id=vnfr.get("vca-id"),
-                                )
                             )
+                        )
                         log.debug("Measures: %s", measures)
                         for measure_list in measures.values():
                             for measure in measure_list: