Enabling Flake8 and import sorting
[osm/RO.git] / NG-RO / osm_ng_ro / ns_thread.py
index 2efdbc0..01c894d 100644 (file)
@@ -24,25 +24,23 @@ A single ro_task refers to a VIM element (flavor, image, network, ...).
 A ro_task can contain several 'tasks', each one with a target, where to store the results
 """
 
-import logging
-import queue
-import threading
-import time
-import yaml
 from copy import deepcopy
 from http import HTTPStatus
+import logging
 from os import mkdir
-from pkg_resources import iter_entry_points
+import queue
 from shutil import rmtree
+import threading
+import time
 from unittest.mock import Mock
 
-# from osm_common import dbmongo, dbmemory, fslocal, fsmongo, msglocal, msgkafka, version as common_version
+from importlib_metadata import entry_points
 from osm_common.dbbase import DbException
-from osm_ro_plugin.vim_dummy import VimDummyConnector
-from osm_ro_plugin.sdn_dummy import SdnDummyConnector
-from osm_ro_plugin import vimconn, sdnconn
 from osm_ng_ro.vim_admin import LockRenew
-
+from osm_ro_plugin import sdnconn, vimconn
+from osm_ro_plugin.sdn_dummy import SdnDummyConnector
+from osm_ro_plugin.vim_dummy import VimDummyConnector
+import yaml
 
 __author__ = "Alfonso Tierno"
 __date__ = "$28-Sep-2017 12:07:15$"
@@ -596,7 +594,7 @@ class VimInteractionImage(VimInteractionBase):
                     )
                 elif len(vim_images) > 1:
                     raise NsWorkerException(
-                        "More than one network found with this criteria: '{}'".format(
+                        "More than one image found with this criteria: '{}'".format(
                             task["find_params"]
                         )
                     )
@@ -1229,8 +1227,8 @@ class NsWorker(threading.Thread):
             return self.plugins[name]
 
         try:
-            for v in iter_entry_points("osm_ro{}.plugins".format(type), name):
-                self.plugins[name] = v.load()
+            for ep in entry_points(group="osm_ro{}.plugins".format(type), name=name):
+                self.plugins[name] = ep.load()
         except Exception as e:
             raise NsWorkerException("Cannot load plugin osm_{}: {}".format(name, e))
 
@@ -1758,6 +1756,11 @@ class NsWorker(threading.Thread):
                                     next_check_at = min(
                                         next_check_at, dependency_ro_task["to_check_at"]
                                     )
+                                    # must allow dependent task to be processed first
+                                    # to do this set time after last_task_processed
+                                    next_check_at = max(
+                                        self.time_last_task_processed, next_check_at
+                                    )
                                     break
                                 elif dependency_task["status"] == "FAILED":
                                     error_text = "Cannot {} {} because depends on failed {} {} id={}): {}".format(