Skip to content

Commit

Permalink
Merge branch 'ui/not_ownership' of https://github.com/kytos-ng/mef_eline
Browse files Browse the repository at this point in the history
 into ui/not_ownership
  • Loading branch information
Alopalao committed Feb 16, 2024
2 parents ab7a891 + fae39dc commit 76d5ae4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 172 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Changed
- An inactive and enabled EVC will be redeploy if an attribute from ``attributes_requiring_redeploy`` is updated.
- If a KytosEvent can't be put on ``buffers.app`` during ``setup()``, it'll make the NApp to fail to start
- Disjointedness algorithm now takes into account switches, excepting the UNIs switches. Unwanted switches have the same value as the unwanted links.
- Archived EVCs are not longer kept in memory. They can only be found in the database.

Deprecated
==========
Expand Down
54 changes: 19 additions & 35 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ def setup(self):
self.load_all_evcs()
self._topology_updated_at = None

def get_evcs_by_svc_level(self) -> list:
def get_evcs_by_svc_level(self, enable_filter: bool = True) -> list:
"""Get circuits sorted by desc service level and asc creation_time.
In the future, as more ops are offloaded it should be get from the DB.
"""
if enable_filter:
return sorted(
[circuit for circuit in self.circuits.values()
if circuit.is_enabled()],
key=lambda x: (-x.service_level, x.creation_time),
)
return sorted(self.circuits.values(),
key=lambda x: (-x.service_level, x.creation_time))

Expand Down Expand Up @@ -116,7 +122,7 @@ def execute_consistency(self):
"""Execute consistency routine."""
circuits_to_check = []
stored_circuits = self.mongo_controller.get_circuits()['circuits']
for circuit in self.get_evcs_by_svc_level():
for circuit in self.get_evcs_by_svc_level(enable_filter=False):
stored_circuits.pop(circuit.id, None)
if self.should_be_checked(circuit):
circuits_to_check.append(circuit)
Expand Down Expand Up @@ -364,11 +370,6 @@ def update(self, request: Request) -> JSONResponse:
log.debug("update result %s %s", result, 404)
raise HTTPException(404, detail=result) from KeyError

if evc.archived:
result = "Can't update archived EVC"
log.debug("update result %s %s", result, 409)
raise HTTPException(409, detail=result)

try:
updated_data = self._evc_dict_with_instances(data)
self._check_no_tag_duplication(
Expand Down Expand Up @@ -423,17 +424,12 @@ def delete_circuit(self, request: Request) -> JSONResponse:
circuit_id = request.path_params["circuit_id"]
log.debug("delete_circuit /v2/evc/%s", circuit_id)
try:
evc = self.circuits[circuit_id]
evc = self.circuits.pop(circuit_id)
except KeyError:
result = f"circuit_id {circuit_id} not found"
log.debug("delete_circuit result %s %s", result, 404)
raise HTTPException(404, detail=result) from KeyError

if evc.archived:
result = f"Circuit {circuit_id} already removed"
log.debug("delete_circuit result %s %s", result, 404)
raise HTTPException(404, detail=result)

log.info("Removing %s", evc)
with evc.lock:
evc.remove_current_flows()
Expand Down Expand Up @@ -604,11 +600,6 @@ def create_schedule(self, request: Request) -> JSONResponse:
result = f"circuit_id {circuit_id} not found"
log.debug("create_schedule result %s %s", result, 404)
raise HTTPException(404, detail=result)
# Can not modify circuits deleted and archived
if evc.archived:
result = f"Circuit {circuit_id} is archived. Update is forbidden."
log.debug("create_schedule result %s %s", result, 409)
raise HTTPException(409, detail=result)

# new schedule from dict
new_schedule = CircuitSchedule.from_dict(schedule_data)
Expand Down Expand Up @@ -659,10 +650,6 @@ def update_schedule(self, request: Request) -> JSONResponse:
result = f"schedule_id {schedule_id} not found"
log.debug("update_schedule result %s %s", result, 404)
raise HTTPException(404, detail=result)
if evc.archived:
result = f"Circuit {evc.id} is archived. Update is forbidden."
log.debug("update_schedule result %s %s", result, 409)
raise HTTPException(409, detail=result)

new_schedule = CircuitSchedule.from_dict(data)
new_schedule.id = found_schedule.id
Expand Down Expand Up @@ -702,11 +689,6 @@ def delete_schedule(self, request: Request) -> JSONResponse:
log.debug("delete_schedule result %s %s", result, 404)
raise HTTPException(404, detail=result)

if evc.archived:
result = f"Circuit {evc.id} is archived. Update is forbidden."
log.debug("delete_schedule result %s %s", result, 409)
raise HTTPException(409, detail=result)

# Remove the old schedule
evc.circuit_scheduler.remove(found_schedule)

Expand Down Expand Up @@ -808,20 +790,22 @@ def handle_interface_link_up(self, interface):
Handler for interface link_up events
"""
for evc in self.get_evcs_by_svc_level():
log.info("Event handle_interface_link_up %s", interface)
evc.handle_interface_link_up(
interface
)
with evc.lock:
log.info("Event handle_interface_link_up %s", interface)
evc.handle_interface_link_up(
interface
)

def handle_interface_link_down(self, interface):
"""
Handler for interface link_down events
"""
for evc in self.get_evcs_by_svc_level():
log.info("Event handle_interface_link_down %s", interface)
evc.handle_interface_link_down(
interface
)
with evc.lock:
log.info("Event handle_interface_link_down %s", interface)
evc.handle_interface_link_down(
interface
)

@listen_to("kytos/topology.link_down")
def on_link_down(self, event):
Expand Down
4 changes: 0 additions & 4 deletions models/evc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,8 +1686,6 @@ def handle_interface_link_up(self, interface: Interface):
"""
Handler for interface link_up events
"""
if self.archived: # TODO: Remove when addressing issue #369
return
if self.is_active():
return
interfaces = (self.uni_a.interface, self.uni_z.interface)
Expand Down Expand Up @@ -1718,8 +1716,6 @@ def handle_interface_link_down(self, interface):
"""
Handler for interface link_down events
"""
if self.archived:
return
if not self.is_active():
return
interfaces = (self.uni_a.interface, self.uni_z.interface)
Expand Down
Loading

0 comments on commit 76d5ae4

Please sign in to comment.