Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved _get_tag_ranges() to kytos/core #175

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

from kytos.core import KytosEvent, KytosNApp, log, rest
from kytos.core.common import EntityStatus
from kytos.core.exceptions import (KytosInvalidRanges, KytosLinkCreationError,
KytosSetTagRangeError,
KytosTagtypeNotSupported)
from kytos.core.exceptions import (KytosInvalidTagRanges,
KytosLinkCreationError, KytosTagError)
from kytos.core.helpers import listen_to, load_spec, now, validate_openapi
from kytos.core.interface import Interface
from kytos.core.link import Link
Expand Down Expand Up @@ -496,20 +495,17 @@ def set_tag_range(self, request: Request) -> JSONResponse:
tag_type = content.get("tag_type")
try:
ranges = get_tag_ranges(content["tag_ranges"])
except KytosInvalidRanges as err:
raise HTTPException(400, detail=err)
except KytosInvalidTagRanges as err:
raise HTTPException(400, detail=str(err))
interface_id = request.path_params["interface_id"]
interface = self.controller.get_interface_by_id(interface_id)
if not interface:
raise HTTPException(404, detail="Interface not found")
try:
interface.set_tag_ranges(ranges, tag_type)
self.handle_on_interface_tags(interface)
except KytosSetTagRangeError as err:
detail = f"The new tag_ranges cannot be applied {err}"
raise HTTPException(400, detail=detail)
except KytosTagtypeNotSupported as err:
detail = f"Error with tag_type. {err}"
except KytosTagError as err:
detail = f"Error when setting tag ranges: {err}"
viniarck marked this conversation as resolved.
Show resolved Hide resolved
raise HTTPException(400, detail=detail)
return JSONResponse("Operation Successful", status_code=200)

Expand All @@ -526,7 +522,7 @@ def delete_tag_range(self, request: Request) -> JSONResponse:
try:
interface.remove_tag_ranges(tag_type)
self.handle_on_interface_tags(interface)
except KytosTagtypeNotSupported as err:
except KytosTagError as err:
detail = f"Error with tag_type. {err}"
raise HTTPException(400, detail=detail)
return JSONResponse("Operation Successful", status_code=200)
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ async def test_set_tag_range_tag_error(self, event_loop):
mock_switch = get_switch_mock(dpid)
mock_interface = get_interface_mock('s1-eth1', 1, mock_switch)
mock_interface.set_tag_ranges = MagicMock()
mock_interface.set_tag_ranges.side_effect = KytosSetTagRangeError()
mock_interface.set_tag_ranges.side_effect = KytosSetTagRangeError("")
mock_interface.notify_interface_tags = MagicMock()
self.napp.controller.get_interface_by_id = MagicMock()
self.napp.controller.get_interface_by_id.return_value = mock_interface
Expand All @@ -1696,7 +1696,9 @@ async def test_set_tag_range_type_error(self, event_loop):
mock_switch = get_switch_mock(dpid)
mock_interface = get_interface_mock('s1-eth1', 1, mock_switch)
mock_interface.set_tag_ranges = MagicMock()
mock_interface.set_tag_ranges.side_effect = KytosTagtypeNotSupported()
mock_interface.set_tag_ranges.side_effect = KytosTagtypeNotSupported(
""
)
self.napp.handle_on_interface_tags = MagicMock()
self.napp.controller.get_interface_by_id = MagicMock()
self.napp.controller.get_interface_by_id.return_value = mock_interface
Expand Down Expand Up @@ -1749,7 +1751,7 @@ async def test_delete_tag_range_type_error(self, event_loop):
mock_interface = get_interface_mock('s1-eth1', 1, mock_switch)
mock_interface.remove_tag_ranges = MagicMock()
remove_tag = mock_interface.remove_tag_ranges
remove_tag.side_effect = KytosTagtypeNotSupported()
remove_tag.side_effect = KytosTagtypeNotSupported("")
self.napp.controller.get_interface_by_id = MagicMock()
self.napp.controller.get_interface_by_id.return_value = mock_interface
url = f"{self.base_endpoint}/interfaces/{interface_id}/tag_ranges"
Expand Down