-
Notifications
You must be signed in to change notification settings - Fork 7
feat: understack trunk #668
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
python/neutron-understack/neutron_understack/tests/test_trunk.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from unittest.mock import MagicMock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from neutron_understack.nautobot import Nautobot | ||
from neutron_understack.neutron_understack_mech import UnderstackDriver | ||
from neutron_understack.trunk import SubportSegmentationIDError | ||
from neutron_understack.trunk import UnderStackTrunkDriver | ||
|
||
|
||
@pytest.fixture | ||
def subport() -> MagicMock: | ||
return MagicMock(port_id="portUUID", segmentation_id=555) | ||
|
||
|
||
@pytest.fixture | ||
def trunk(subport) -> MagicMock: | ||
return MagicMock(sub_ports=[subport]) | ||
|
||
|
||
@pytest.fixture | ||
def payload_metadata(subport) -> dict: | ||
return {"subports": [subport]} | ||
|
||
|
||
@pytest.fixture | ||
def payload(payload_metadata, trunk) -> MagicMock: | ||
return MagicMock(metadata=payload_metadata, states=[trunk]) | ||
|
||
|
||
@pytest.fixture | ||
def nautobot_client() -> Nautobot: | ||
return MagicMock(spec_set=Nautobot) | ||
|
||
|
||
driver = UnderstackDriver() | ||
driver.nb = Nautobot("", "") | ||
trunk_driver = UnderStackTrunkDriver.create(driver) | ||
|
||
|
||
@patch("neutron_understack.utils.fetch_subport_network_id", return_value="112233") | ||
def test_subports_added_when_ucvni_tenan_vlan_id_is_not_set_yet( | ||
nautobot_client, payload | ||
): | ||
trunk_driver.nb = nautobot_client | ||
attrs = {"fetch_ucvni_tenant_vlan_id.return_value": None} | ||
nautobot_client.configure_mock(**attrs) | ||
trunk_driver.subports_added("", "", "", payload) | ||
|
||
nautobot_client.add_tenant_vlan_tag_to_ucvni.assert_called_once_with( | ||
network_uuid="112233", vlan_tag=555 | ||
) | ||
|
||
|
||
@patch("neutron_understack.utils.fetch_subport_network_id", return_value="223344") | ||
def test_subports_added_when_segmentation_id_is_different_to_tenant_vlan_id( | ||
nautobot_client, payload | ||
): | ||
trunk_driver.nb = nautobot_client | ||
attrs = {"fetch_ucvni_tenant_vlan_id.return_value": 123} | ||
nautobot_client.configure_mock(**attrs) | ||
with pytest.raises(SubportSegmentationIDError): | ||
trunk_driver.subports_added("", "", "", payload) | ||
|
||
|
||
@patch("neutron_understack.utils.fetch_subport_network_id", return_value="112233") | ||
def test_trunk_created_when_ucvni_tenan_vlan_id_is_not_set_yet( | ||
nautobot_client, payload | ||
): | ||
trunk_driver.nb = nautobot_client | ||
attrs = {"fetch_ucvni_tenant_vlan_id.return_value": None} | ||
nautobot_client.configure_mock(**attrs) | ||
trunk_driver.trunk_created("", "", "", payload) | ||
|
||
nautobot_client.add_tenant_vlan_tag_to_ucvni.assert_called_once_with( | ||
network_uuid="112233", vlan_tag=555 | ||
) | ||
|
||
|
||
@patch("neutron_understack.utils.fetch_subport_network_id", return_value="223344") | ||
def test_trunk_created_when_segmentation_id_is_different_to_tenant_vlan_id( | ||
nautobot_client, payload | ||
): | ||
trunk_driver.nb = nautobot_client | ||
attrs = {"fetch_ucvni_tenant_vlan_id.return_value": 123} | ||
nautobot_client.configure_mock(**attrs) | ||
with pytest.raises(SubportSegmentationIDError): | ||
trunk_driver.trunk_created("", "", "", payload) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from neutron.objects import ports as port_obj | ||
from neutron_lib import context as n_context | ||
|
||
|
||
def fetch_subport_network_id(subport_id): | ||
context = n_context.get_admin_context() | ||
neutron_port = port_obj.Port.get_object(context, id=subport_id) | ||
return neutron_port.network_id |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.