Skip to content

Commit

Permalink
Include vlans with an IRB int in device vlans even if not on L2 port
Browse files Browse the repository at this point in the history
Include vlans that have an IRB int configured on a switch with the
list of device vlans.  Previously that list only included those that
were configured on L2 access or trunk ports, which meant that
vlans were not pre-provisioned on L3 switches.

Bug: T366348
Change-Id: I4e83cab64cd92cf162a50d84dd954fe7a325a81c
  • Loading branch information
topranks committed Jun 18, 2024
1 parent 9f6ced4 commit 7af405b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions homer/netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ def _get_vlans(self) -> Dict[int, Any]:
for tagged_vlan in interface.tagged_vlans:
if tagged_vlan.vid not in vlans:
vlans[tagged_vlan.vid] = tagged_vlan
if interface.name.startswith('irb'):
vid = int(interface.name.split('.')[1])
if vid not in vlans:
vlan = self._api.ipam.vlans.get(vid=vid)
try:
vlans[vlan.vid] = vlan
except AttributeError as e:
raise HomerError(f'IRB interface {interface} does not match any Vlan in Netbox') from e

return vlans


Expand Down
2 changes: 2 additions & 0 deletions homer/tests/unit/test_netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ def test_get_vlans(self):
interface1.tagged_vlans = [NetboxObject(), NetboxObject()]
interface1.tagged_vlans[0].vid = 667
interface1.tagged_vlans[1].vid = 667
interface1.name = 'int1'
interface2 = NetboxObject() # This is a fake interface object
interface2.untagged_vlan = NetboxObject() # That interface have fake tagged and untagged vlans
interface2.untagged_vlan.vid = 666
interface2.tagged_vlans = None
interface2.name = 'int2'
self.netbox_api.dcim.interfaces.filter.return_value = [interface1, interface2]
# We want the function with the fake inbound data to match the one untagged and tagged vlans
assert self.netbox_data['vlans'] == {666: interface1.untagged_vlan, 667: interface1.tagged_vlans[0]}
Expand Down

0 comments on commit 7af405b

Please sign in to comment.