Skip to content

Commit

Permalink
Merge pull request #422 from kytos-ng/feat/not_ownership_modern
Browse files Browse the repository at this point in the history
Add in support for not_ownership
  • Loading branch information
Ktmi authored Jan 30, 2024
2 parents 8408f20 + 06ce541 commit 94ec16d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Added
- EVCs now listen to ``switch.interface.(link_up|link_down|created|deleted)`` events for activation/deactivation
- Circuits with a vlan range are supported now. The ranges follows ``list[list[int]]`` format and both UNIs vlan should have the same ranges.
- Usage of special vlans ``"untagged"`` and ``"any"`` now send an event to each Interface.
- Added support for ``not_ownership`` to dynamic path constraints.

Changed
=======
Expand Down
1 change: 1 addition & 0 deletions db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class LinkConstraints(BaseModel):
utilization: Optional[float]
delay: Optional[float]
priority: Optional[int]
not_ownership: Optional[List[str]]


class PathConstraints(BaseModel):
Expand Down
6 changes: 6 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ components:
type: string
description: The exact user who should have ownership or be authorized to use the link.
example: "Bill"
not_ownership:
type: array
items:
type: string
description: The list of users whose links should not be used.
example: ["Ted"]
Circuit: # Can be referenced via '#/components/schemas/Circuit'
type: object
properties:
Expand Down
61 changes: 60 additions & 1 deletion tests/unit/test_db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import pytest
from pydantic import ValidationError

from db.models import EVCBaseDoc, DocumentBaseModel, TAGDoc, EVCUpdateDoc
from db.models import (DocumentBaseModel, EVCBaseDoc, EVCUpdateDoc,
LinkConstraints, TAGDoc)


class TestDBModels():
Expand Down Expand Up @@ -118,3 +119,61 @@ def test_tagdoc_fail(self):
tag_fail = {"tag_type": 'vlan', "value": "test_fail"}
with pytest.raises(ValueError):
TAGDoc(**tag_fail)

@pytest.mark.parametrize(
'attribute,acceptable_value',
[
('bandwidth', 1.0),
('bandwidth', 1),
('ownership', 'Test A'),
('reliability', 0.9),
('reliability', 1),
('utilization', 30.0),
('utilization', 30),
('delay', 10.0),
('delay', 10),
('priority', 1),
('not_ownership', []),
('not_ownership', ['Test B']),
('not_ownership', ['Test B', 'Test C']),
]
)
def test_link_metrics(
self,
attribute,
acceptable_value,
):
"""
Test attributes of link constraints across
various acceptable values
"""
constraints = {
attribute: acceptable_value
}
LinkConstraints(**constraints)

@pytest.mark.parametrize(
'attribute,unacceptable_value',
[
('bandwidth', 'E'),
('reliability', 'D'),
('utilization', 'C'),
('delay', 'B'),
('priority', 'A'),
('not_ownership', 'Yo'),
]
)
def test_link_unacceptable_metrics(
self,
attribute,
unacceptable_value,
):
"""
Test attributes of link constraints across
various unacceptable values
"""
constraints = {
attribute: unacceptable_value
}
with pytest.raises(ValidationError):
LinkConstraints(**constraints)

0 comments on commit 94ec16d

Please sign in to comment.