Skip to content

Commit

Permalink
Got back compatibility
Browse files Browse the repository at this point in the history
- Updated readme
- Updated changelog
- Tag type integer compatibility returned.
- No longer calling `notify_interface_tags()` from Interface
  • Loading branch information
Alopalao committed Sep 20, 2023
1 parent fc4f99a commit 4b71e78
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 26 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ Added
Changed
=======
- UNIs now will use and free tags from ``Interface.available_tags``.
- Bumped API endpoint version to ``v3``.

Deprecated
==========
- Deleted emition of ``kytos/.*.link_available_tags`` event. ``kytos/core.interface_tags`` event through Interface takes its place.

General Information
===================
- ``scripts/vlan_type_string.py`` can be used to update the collection ``evcs`` by changing ``tag_type`` from integer to string

[2023.1.0] - 2023-06-27
***********************

Expand Down
7 changes: 5 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,10 +966,13 @@ def _uni_from_dict(self, uni_dict):
+ f"Could not instantiate interface {interface_id}"
)
raise ValueError(result) from ValueError

tag_convert = {1: "vlan"}
tag_dict = uni_dict.get("tag", None)
if tag_dict:
tag = TAG.from_dict(tag_dict)
tag_type = tag_dict.get("tag_type")
tag_type = tag_convert.get(tag_type, tag_type)
tag_value = tag_dict.get("value")
tag = TAG(tag_type, tag_value)
else:
tag = None
uni = UNI(interface, tag)
Expand Down
13 changes: 8 additions & 5 deletions models/evc.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,12 @@ def _use_uni_vlan(self, uni: UNI):
tag = uni.user_tag.value
tag_type = uni.user_tag.tag_type
if isinstance(tag, int):
if not uni.interface.use_tags([tag, tag], tag_type):
result = uni.interface.use_tags(
self._controller, [tag, tag], tag_type
)
if not result:
intf = uni.interface.id
raise ValueError(f"Tag {tag} is not available in {intf}")
uni.interface.notify_interface_tags(self._controller)

def make_uni_vlan_available(self, uni: UNI):
"""Make available tag from UNI"""
Expand All @@ -438,11 +440,12 @@ def make_uni_vlan_available(self, uni: UNI):
tag = uni.user_tag.value
tag_type = uni.user_tag.tag_type
if isinstance(tag, int):
if not uni.interface.make_tags_available([tag, tag], tag_type):
result = uni.interface.make_tags_available(
self._controller, [tag, tag], tag_type
)
if not result:
intf = uni.interface.id
log.warning(f"Tag {tag} was already available in {intf}")
else:
uni.interface.notify_interface_tags(self._controller)

def remove_uni_tags(self):
"""Remove both UNI usage of a tag"""
Expand Down
8 changes: 7 additions & 1 deletion models/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ def make_vlans_available(self, controller):
"""Make the VLANs used in a path available when undeployed."""
for link in self:
tag = link.get_metadata("s_vlan")
link.make_tags_available(
result_a, result_b = link.make_tags_available(
controller, tag.value, link.id, tag.tag_type
)
if result_a is False:
log.error(f"Tag {tag} was already available in"
f"{link.endpoint_a.id}")
if result_b is False:
log.error(f"Tag {tag} was already available in"
f"{link.endpoint_b.id}")
link.remove_metadata("s_vlan")

def is_valid(self, switch_a, switch_z, is_scheduled=False):
Expand Down
6 changes: 4 additions & 2 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,10 @@ components:
type: object
properties:
tag_type:
type: string
enum: ['vlan']
oneOf:
- type: string
- type: integer
enum: ['vlan', 1]
value:
oneOf:
- type: integer
Expand Down
2 changes: 0 additions & 2 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ EVC_IDS='d33539656d8b40,095e1d6f43c745' priority python3 scripts/002_unset_spf_a

#### Pre-requisites

- There's no additional Python libraries dependencies required, other than installing the existing `topology`'s, or if you're running in development locally then installing `requirements/dev.in`
- Make sure you don't have `kytosd` running with otherwise topology will start writing to MongoDB, and the application could overwrite the data you're trying to insert with this script.
- Make sure MongoDB replica set is up and running.
- Export the following MongnoDB variables accordingly in case your running outside of a container

Expand Down
6 changes: 5 additions & 1 deletion scripts/vlan_type_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
),
)
evcs = collection.bulk_write(up_paths)
print(f"{evcs.modified_count} documents where PATH are modified")

# Update Uni_a
for key, value in tag_type.items():
Expand All @@ -41,6 +42,8 @@
{"uni_a.tag.tag_type": value}
}
)
print(f"{uni_a.modified_count} documents where UNI_A tag_type {key}"
f" are modified to {value}")

# Update Uni_z
for key, value in tag_type.items():
Expand All @@ -50,4 +53,5 @@
{"uni_z.tag.tag_type": value}
}
)
print(f"Finnished updating EVCs")
print(f"{uni_z.modified_count} documents where UNI_Z tag_type {key}"
f" are modified to {value}")
1 change: 1 addition & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def get_link_mocked(**kwargs):
switch_b,
)
link = Mock(spec=Link, endpoint_a=endpoint_a, endpoint_b=endpoint_b)
link.make_tags_available.return_value = True, True
link.endpoint_a.link = link
link.endpoint_b.link = link
link.as_dict.return_value = kwargs.get(
Expand Down
16 changes: 4 additions & 12 deletions tests/unit/models/test_evc_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,24 +552,20 @@ def test_use_uni_vlan(self):
evc = EVC(**attributes)
uni = get_uni_mocked(is_valid=True)
uni.interface.use_tags = MagicMock()
uni.interface.notify_interface_tags = MagicMock()
evc._use_uni_vlan(uni)
args = uni.interface.use_tags.call_args[0]
assert args[0] == [uni.user_tag.value, uni.user_tag.value]
assert args[1] == uni.user_tag.tag_type
assert args[1] == [uni.user_tag.value, uni.user_tag.value]
assert args[2] == uni.user_tag.tag_type
assert uni.interface.use_tags.call_count == 1
assert uni.interface.notify_interface_tags.call_count == 1

uni.interface.use_tags.return_value = False
with pytest.raises(ValueError):
evc._use_uni_vlan(uni)
assert uni.interface.use_tags.call_count == 2
assert uni.interface.notify_interface_tags.call_count == 1

uni.user_tag = None
evc._use_uni_vlan(uni)
assert uni.interface.use_tags.call_count == 2
assert uni.interface.notify_interface_tags.call_count == 1

def test_make_uni_vlan_available(self):
"""Test make_uni_vlan_available"""
Expand All @@ -583,24 +579,20 @@ def test_make_uni_vlan_available(self):
evc = EVC(**attributes)
uni = get_uni_mocked(is_valid=True)
uni.interface.make_tags_available = MagicMock()
uni.interface.notify_interface_tags = MagicMock()

evc.make_uni_vlan_available(uni)
args = uni.interface.make_tags_available.call_args[0]
assert args[0] == [uni.user_tag.value, uni.user_tag.value]
assert args[1] == uni.user_tag.tag_type
assert args[1] == [uni.user_tag.value, uni.user_tag.value]
assert args[2] == uni.user_tag.tag_type
assert uni.interface.make_tags_available.call_count == 1
assert uni.interface.notify_interface_tags.call_count == 1

uni.interface.make_tags_available.return_value = False
evc.make_uni_vlan_available(uni)
assert uni.interface.make_tags_available.call_count == 2
assert uni.interface.notify_interface_tags.call_count == 1

uni.user_tag = None
evc.make_uni_vlan_available(uni)
assert uni.interface.make_tags_available.call_count == 2
assert uni.interface.notify_interface_tags.call_count == 1

def test_remove_uni_tags(self):
"""Test remove_uni_tags"""
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2333,10 +2333,16 @@ async def test_use_uni_tags(self, event_loop):
assert evc_mock._use_uni_vlan.call_args[0][0] == evc_mock.uni_z

# One UNI tag is not available
evc_mock._use_uni_vlan.side_effect = [ValueError(), None]
with pytest.raises(ValueError):
self.napp._use_uni_tags(evc_mock)
assert evc_mock._use_uni_vlan.call_count == 3
assert evc_mock.make_uni_vlan_available.call_count == 0

evc_mock._use_uni_vlan.side_effect = [None, ValueError()]
with pytest.raises(ValueError):
self.napp._use_uni_tags(evc_mock)
assert evc_mock._use_uni_vlan.call_count == 4
assert evc_mock._use_uni_vlan.call_count == 5
assert evc_mock.make_uni_vlan_available.call_count == 1

async def test_handle_topology_update(self):
Expand Down

0 comments on commit 4b71e78

Please sign in to comment.