Fix bug in get_l2xc_interfaces(), and add tests for it
This commit is contained in:
@ -63,3 +63,11 @@ interfaces:
|
||||
l2xc: GigabitEthernet3/0/1
|
||||
GigabitEthernet3/0/1:
|
||||
l2xc: GigabitEthernet3/0/0
|
||||
|
||||
GigabitEthernet3/0/2:
|
||||
sub-interfaces:
|
||||
100:
|
||||
description: "This interface connects one-way to Gi3/0/2.200. Strange, but valid."
|
||||
l2xc: GigabitEthernet3/0/2.200
|
||||
200:
|
||||
description: "This interface does not connect back to Gi3/0/2.100. Strange, but valid."
|
||||
|
@ -120,7 +120,8 @@ def get_l2xc_interfaces(yaml):
|
||||
if 'l2xc' in iface:
|
||||
ret.append(ifname)
|
||||
if 'sub-interfaces' in iface:
|
||||
for sub_ifname, sub_iface in iface['sub-interfaces'].items():
|
||||
for subid, sub_iface in iface['sub-interfaces'].items():
|
||||
sub_ifname = "%s.%d" % (ifname, subid)
|
||||
if 'l2xc' in sub_iface:
|
||||
ret.append(sub_ifname)
|
||||
|
||||
@ -141,7 +142,7 @@ def get_l2xc_target_interfaces(yaml):
|
||||
if 'l2xc' in iface:
|
||||
ret.append(iface['l2xc'])
|
||||
if 'sub-interfaces' in iface:
|
||||
for sub_ifname, sub_iface in iface['sub-interfaces'].items():
|
||||
for subid, sub_iface in iface['sub-interfaces'].items():
|
||||
if 'l2xc' in sub_iface:
|
||||
ret.append(sub_iface['l2xc'])
|
||||
|
||||
|
@ -22,7 +22,7 @@ def get_lcps(yaml):
|
||||
if 'lcp' in iface:
|
||||
ret.append(iface['lcp'])
|
||||
if 'sub-interfaces' in iface:
|
||||
for sub_ifname, sub_iface in iface['sub-interfaces'].items():
|
||||
for subid, sub_iface in iface['sub-interfaces'].items():
|
||||
if 'lcp' in sub_iface:
|
||||
ret.append(sub_iface['lcp'])
|
||||
|
||||
|
@ -9,12 +9,12 @@ class TestInterfaceMethods(unittest.TestCase):
|
||||
|
||||
def test_enumerators(self):
|
||||
ifs = interface.get_interfaces(self.cfg)
|
||||
self.assertEqual(len(ifs), 16)
|
||||
self.assertEqual(len(ifs), 19)
|
||||
self.assertIn("GigabitEthernet1/0/1", ifs)
|
||||
self.assertIn("GigabitEthernet1/0/1.200", ifs)
|
||||
|
||||
ifs = interface.get_sub_interfaces(self.cfg)
|
||||
self.assertEqual(len(ifs), 11)
|
||||
self.assertEqual(len(ifs), 13)
|
||||
self.assertNotIn("GigabitEthernet1/0/1", ifs)
|
||||
self.assertIn("GigabitEthernet1/0/1.200", ifs)
|
||||
self.assertIn("GigabitEthernet1/0/1.201", ifs)
|
||||
@ -28,6 +28,24 @@ class TestInterfaceMethods(unittest.TestCase):
|
||||
self.assertIn("GigabitEthernet1/0/1.201", ifs)
|
||||
self.assertIn("GigabitEthernet1/0/1.203", ifs)
|
||||
|
||||
ifs = interface.get_l2xc_interfaces(self.cfg)
|
||||
self.assertEqual(len(ifs), 3)
|
||||
self.assertIn("GigabitEthernet3/0/0", ifs)
|
||||
self.assertIn("GigabitEthernet3/0/1", ifs)
|
||||
self.assertIn("GigabitEthernet3/0/2.100", ifs)
|
||||
self.assertNotIn("GigabitEthernet3/0/2.200", ifs)
|
||||
|
||||
target_ifs = interface.get_l2xc_target_interfaces(self.cfg)
|
||||
self.assertEqual(len(target_ifs), 3)
|
||||
self.assertIn("GigabitEthernet3/0/0", target_ifs)
|
||||
self.assertIn("GigabitEthernet3/0/1", target_ifs)
|
||||
self.assertNotIn("GigabitEthernet3/0/2.100", target_ifs)
|
||||
self.assertIn("GigabitEthernet3/0/2.200", target_ifs)
|
||||
|
||||
## Since l2xc cannot connect to itself, and the target must exist,
|
||||
## it follows that the same number of l2xc target interfaces must exist.
|
||||
self.assertEqual(len(target_ifs), len(ifs))
|
||||
|
||||
def test_mtu(self):
|
||||
self.assertEqual(interface.get_mtu(self.cfg, "GigabitEthernet1/0/1"), 9216)
|
||||
self.assertEqual(interface.get_mtu(self.cfg, "GigabitEthernet1/0/1.200"), 9000)
|
||||
|
Reference in New Issue
Block a user