feat: switch panel and PDF also use the VLANs assigned to cables

Ports without a label show the VLANs of their cable. A label with exactly
one number counts as that VLAN ID, so "Server 30", "VLAN 30", "30" and a
cable with VLAN 30 share one colour and legend entry. A numeric label that
differs from the cable VLANs is flagged with an orange corner and a
warning; tooltips and the PDF port list show label and cable VLANs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-10-30 10:17:54 +01:00
1 parent e9c00f2b11
commit 6906bf6ed6
9 files changed
+200 -39

No files matched your search

@@ -157,3 +157,40 @@ class ManagementTest(SimpleTestCase):
def test_other_ports_without_number_are_shortened(self):
self.assertEqual(port("console").short, "conso")
class CableVlanTest(SimpleTestCase):
def test_cable_vlans_are_used_without_label(self):
p = port("Gi1/0/1", cable_vlans=[(20, "VoIP"), (10, "Office")])
self.assertEqual(p.vlan, "10, 20")
self.assertEqual(p.cable_vlan_text, "10 Office, 20 VoIP")
self.assertFalse(p.vlan_mismatch)
def test_label_wins_and_cable_vlan_shares_its_colour(self):
labelled = port("Gi1/0/1", label="VLAN 10", cable_vlans=[(10, "Office")])
cable_only = port("Gi1/0/2", cable_vlans=[(10, "Office")])
switch_ports.assign_vlan_colors([labelled, cable_only])
self.assertEqual(labelled.vlan, "10")
self.assertEqual(labelled.color, cable_only.color)
self.assertFalse(labelled.vlan_mismatch)
def test_mismatch_only_for_numeric_labels(self):
self.assertTrue(port("1", label="20", cable_vlans=[(30, "")]).vlan_mismatch)
self.assertTrue(port("2", label="Server 30", cable_vlans=[(30, ""), (40, "")]).vlan_mismatch)
self.assertFalse(port("3", label="Trunk", cable_vlans=[(30, "")]).vlan_mismatch)
self.assertFalse(port("4", label="10,20", cable_vlans=[(20, ""), (10, "")]).vlan_mismatch)
class VlanIdentityTest(SimpleTestCase):
def test_label_number_and_cable_vlan_are_one_vlan(self):
ports = [
port("1", label="Server 30", connected=True),
port("2", label="VLAN 30"),
port("3", cable_vlans=[(30, "Server")], connected=True),
port("4", label="Trunk"),
port("5", label="10,20"),
]
switch_ports.assign_vlan_colors(ports)
self.assertEqual(len({p.color for p in ports[:3]}), 1)
legend = [(text, total, connected) for text, _, total, connected in switch_ports.vlan_legend(ports)]
self.assertEqual(legend, [("10,20", 1, 0), ("Server 30", 3, 2), ("Trunk", 1, 0)])