From cf5360bd8be579d59fb284f97c920d6795b93bde Mon Sep 17 00:00:00 2001 From: Antonio Francisco Date: Mon, 4 Oct 2021 18:30:55 -0300 Subject: [PATCH] Change how EVCs are loaded on startup Instead of always trying to deploy EVCs on startup, verify first if the old path is installed in the switches and working. Fix #33. --- main.py | 12 +++++++++--- models.py | 1 + requirements/run.in | 1 + settings.py | 3 +++ tests/unit/models/test_link_protection.py | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 1acb15eb..dd85d2fb 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ NApp to provision circuits from user request. """ +import time from threading import Lock from flask import jsonify, request @@ -54,14 +55,20 @@ def setup(self): self._lock = Lock() self.execute_as_loop(settings.DEPLOY_EVCS_INTERVAL) + self.load_time = time.time() self.load_all_evcs() def execute(self): """Execute once when the napp is running.""" for circuit in tuple(self.circuits.values()): if circuit.is_enabled() and not circuit.is_active(): - with circuit.lock: - circuit.deploy() + if circuit.check_traces(): + circuit.activate() + circuit.sync() + else: + running_for = time.time() - self.load_time + if running_for > settings.WAIT_FOR_OLD_PATH: + circuit.deploy() def shutdown(self): """Execute when your napp is unloaded. @@ -592,7 +599,6 @@ def _load_evc(self, circuit_dict): if evc.archived: return None evc.deactivate() - evc.current_path = Path([]) evc.sync() self.circuits.setdefault(evc.id, evc) self.sched.add(evc) diff --git a/models.py b/models.py index d2295252..411d1e9f 100644 --- a/models.py +++ b/models.py @@ -12,6 +12,7 @@ from kytos.core.helpers import get_time, now from kytos.core.interface import UNI from kytos.core.link import Link + from napps.kytos.mef_eline import settings from napps.kytos.mef_eline.exceptions import FlowModException from napps.kytos.mef_eline.storehouse import StoreHouse diff --git a/requirements/run.in b/requirements/run.in index e173d70a..ccb9a293 100644 --- a/requirements/run.in +++ b/requirements/run.in @@ -1,2 +1,3 @@ apscheduler requests +glom diff --git a/settings.py b/settings.py index ca2d19ad..962766aa 100644 --- a/settings.py +++ b/settings.py @@ -15,5 +15,8 @@ # EVC consistency interval DEPLOY_EVCS_INTERVAL = 60 +# Time to wait for old path to become available +WAIT_FOR_OLD_PATH = 5 * DEPLOY_EVCS_INTERVAL + # Prefix this NApp has when using cookies COOKIE_PREFIX = 0xaa diff --git a/tests/unit/models/test_link_protection.py b/tests/unit/models/test_link_protection.py index 078ce87c..c3120f8a 100644 --- a/tests/unit/models/test_link_protection.py +++ b/tests/unit/models/test_link_protection.py @@ -196,6 +196,7 @@ def test_handle_link_down_case_1(self, path_status_mocked, evc = EVC(**attributes) evc.current_path = evc.primary_path + evc.activate() current_handle_link_down = evc.handle_link_down() self.assertEqual(deploy_mocked.call_count, 0) deploy_to_mocked.assert_called_once()