Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions cosmo/netbox_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ def isCurrentDeviceInterface(self) -> bool:
return self.getParent(DeviceType).isCompositeRoot()

def getUntaggedVLAN(self):
"""
Retrieves untagged VLAN on interface, if any (None else). Compatible with Netbox native VLANType
and outer_tag CF. Will raise an error if native VLANType and outer_tag CF are used at the same time.
"""
cf = self.getCustomFields()
if "untagged_vlan" in self.keys() and self["untagged_vlan"]:
if cf.get("outer_tag"):
Expand All @@ -536,6 +540,7 @@ def getUntaggedVLAN(self):
return VLANType(
{"vid": int(cf["outer_tag"]), "interfaces_as_untagged": [self]}
)
return None

def getTaggedVLANS(self) -> list:
return self.get("tagged_vlans", [])
Expand Down
12 changes: 2 additions & 10 deletions cosmo/routervisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,11 @@ def processSubInterface(self, o: InterfaceType):
# easy checks first, narrow down afterward
if not o.getUntaggedVLAN() and not o.getUnitNumber() == 0:
# costlier checks it is then
device = o.getParent(DeviceType)
parent_interface = o.getPhysicalInterfaceByFilter()
if parent_interface:
all_parent_sub_interfaces = list(
filter(
lambda i: i.getName().startswith(parent_interface.getName())
and i.isSubInterface(),
device.getInterfaces(),
)
)
parent_interface_type = parent_interface.getAssociatedType()
# cases where no VLAN is authorized: we have only one sub interface, or it's a loopback or virtual
if len(all_parent_sub_interfaces) > 1 and parent_interface_type not in [
# cases where no VLAN is authorized: parent is a loopback or virtual
if parent_interface_type not in [
"loopback",
"virtual",
]:
Expand Down
22 changes: 22 additions & 0 deletions cosmo/tests/test_case_2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,28 @@ device_list:
name: TEST-VLAN
vid: 139
vrf: null
- custom_fields:
bpdufilter: false
inner_tag: null
outer_tag: null
storm_control__broadcast: null
storm_control__multicast: null
storm_control__unknown_unicast: null
description: 'Missing subinterface VLAN'
__typename: InterfaceType
enabled: true
id: '183110'
ip_addresses: [ ]
lag: null
mac_address: null
mode: ACCESS
mtu: null
name: et-0/0/0.200
tagged_vlans: [ ]
tags: [ ]
type: VIRTUAL
untagged_vlan: null
vrf: null
name: TEST0001
platform:
__typename: PlatformType
Expand Down
6 changes: 5 additions & 1 deletion cosmo/tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ def test_router_physical_interface():
def test_router_logical_interface(capsys):
[sd] = get_router_sd_from_path("./test_case_2.yaml")

assert len(sd["interfaces"]["et-0/0/0"]["units"]) == 4
assert len(sd["interfaces"]["et-0/0/0"]["units"]) == 5

assert 139 in sd["interfaces"]["et-0/0/0"]["units"]
assert 150 in sd["interfaces"]["et-0/0/0"]["units"]
assert 200 in sd["interfaces"]["et-0/0/0"]["units"]
assert 1 in sd["interfaces"]["et-0/0/0"]["units"]
assert 2 in sd["interfaces"]["et-0/0/0"]["units"]

Expand All @@ -328,6 +329,9 @@ def test_router_logical_interface(capsys):
assert re.search(
r"0.2] sub-interface number should be same as VLAN \(456\)", output.out
)
assert re.search(
r"0.200] sub interfaces should have an access VLAN configured!", output.out
)


@with_feature(features, "interface-auto-descriptions")
Expand Down
Loading