diff --git a/db/models.py b/db/models.py index c68e8aec..5577474c 100644 --- a/db/models.py +++ b/db/models.py @@ -139,6 +139,7 @@ class EVCBaseDoc(DocumentBaseModel): metadata: Dict = {} active: bool enabled: bool + take_last: bool @staticmethod def projection() -> Dict: diff --git a/models/evc.py b/models/evc.py index d13b5a07..b4f537e9 100644 --- a/models/evc.py +++ b/models/evc.py @@ -157,6 +157,7 @@ def __init__(self, controller, **kwargs): self.backup_links_cache = set() self.affected_by_link_at = get_time("0001-01-01T00:00:00") self.old_path = Path([]) + self.take_last = kwargs.get("take_last", False) self.lock = Lock() @@ -431,6 +432,7 @@ def as_dict(self, keys: set = None): evc_dict["secondary_constraints"] = self.secondary_constraints evc_dict["flow_removed_at"] = self.flow_removed_at evc_dict["updated_at"] = self.updated_at + evc_dict["take_last"] = self.take_last if keys: selected = {} @@ -847,7 +849,7 @@ def deploy_to_path(self, path=None): tag_errors = [] if self.should_deploy(use_path): try: - use_path.choose_vlans(self._controller) + use_path.choose_vlans(self._controller, self.take_last) except KytosNoTagAvailableError as e: tag_errors.append(str(e)) use_path = None @@ -856,7 +858,7 @@ def deploy_to_path(self, path=None): if use_path is None: continue try: - use_path.choose_vlans(self._controller) + use_path.choose_vlans(self._controller, self.take_last) break except KytosNoTagAvailableError as e: tag_errors.append(str(e)) @@ -886,6 +888,7 @@ def deploy_to_path(self, path=None): return False self.activate() self.current_path = use_path + self.take_last = not self.take_last self.sync() log.info(f"{self} was deployed.") return True @@ -932,7 +935,7 @@ def setup_failover_path(self): if not use_path: continue try: - use_path.choose_vlans(self._controller) + use_path.choose_vlans(self._controller, not self.take_last) break except KytosNoTagAvailableError as e: tag_errors.append(str(e)) diff --git a/models/path.py b/models/path.py index d3e308c2..6cea2548 100644 --- a/models/path.py +++ b/models/path.py @@ -36,10 +36,12 @@ def link_affected_by_interface(self, interface=None): return link return None - def choose_vlans(self, controller): + def choose_vlans(self, controller, take_last): """Choose the VLANs to be used for the circuit.""" for link in self: - tag_value = link.get_next_available_tag(controller, link.id) + tag_value = link.get_next_available_tag( + controller, link.id, take_last=take_last + ) tag = TAG('vlan', tag_value) link.add_metadata("s_vlan", tag) diff --git a/openapi.yml b/openapi.yml index d10d1b4f..862a2ba8 100644 --- a/openapi.yml +++ b/openapi.yml @@ -690,6 +690,8 @@ components: request_time: type: string format: date-time + take_last: + type: boolean UpdateCircuit: # Can be referenced via '#/components/schemas/UpdateCircuit' type: object @@ -762,6 +764,8 @@ components: type: object enabled: type: boolean + take_last: + type: boolean Tag: # Can be referenced via '#/components/schemas/Tag' type: object diff --git a/requirements/dev.in b/requirements/dev.in index 0683acaa..b5014810 100644 --- a/requirements/dev.in +++ b/requirements/dev.in @@ -5,5 +5,5 @@ # pip-compile --output-file requirements/dev.txt requirements/dev.in # -e git+https://github.com/kytos-ng/python-openflow.git#egg=python-openflow --e git+https://github.com/kytos-ng/kytos.git#egg=kytos[dev] +-e git+https://github.com/kytos-ng/kytos.git@feature/last_tag#egg=kytos[dev] -e . diff --git a/tests/unit/test_controllers.py b/tests/unit/test_controllers.py index a467da56..2f1e4678 100644 --- a/tests/unit/test_controllers.py +++ b/tests/unit/test_controllers.py @@ -32,7 +32,8 @@ def setup_method(self) -> None: "priority": 100, "active": False, "enabled": True, - "circuit_scheduler": [] + "circuit_scheduler": [], + "take_last": False, } def test_bootstrap_indexes(self): diff --git a/tests/unit/test_db_models.py b/tests/unit/test_db_models.py index 9a2ea2ae..cb65d040 100644 --- a/tests/unit/test_db_models.py +++ b/tests/unit/test_db_models.py @@ -33,7 +33,8 @@ def setup_method(self): "active": False, "enabled": False, "circuit_scheduler": [], - "queue_id": None + "queue_id": None, + "take_last": False, } self.evc_update = { "uni_a": { @@ -55,7 +56,7 @@ def setup_method(self): "sb_priority": 81, "enabled": False, "circuit_scheduler": [], - "queue_id": None + "queue_id": None, } def test_evcbasedoc(self): @@ -71,6 +72,7 @@ def test_evcbasedoc(self): assert not evc.active assert not evc.enabled assert not evc.circuit_scheduler + assert not evc.take_last def test_evcupdatedoc(self): """Test EVCUpdateDoc model"""