Skip to content

Commit

Permalink
Change how EVCs are loaded on startup
Browse files Browse the repository at this point in the history
Instead of always trying to deploy EVCs on startup,
verify first if the old path is installed in the switches
and working. Fix kytos#33.
  • Loading branch information
ajoaoff committed Oct 4, 2021
1 parent d194f98 commit cf5360b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
NApp to provision circuits from user request.
"""
import time
from threading import Lock

from flask import jsonify, request
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements/run.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
apscheduler
requests
glom
3 changes: 3 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/unit/models/test_link_protection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit cf5360b

Please sign in to comment.