Allow MPLS on loopbacks too -- needed for BVIs and such. Add tests.

This commit is contained in:
Pim van Pelt
2023-06-11 18:18:05 +02:00
parent 52b8cb5477
commit 9a42cc91c3
5 changed files with 19 additions and 0 deletions

View File

@ -96,3 +96,14 @@ def validate_loopbacks(yaml):
result = False
return result, msgs
def is_mpls(yaml, ifname):
"""Returns True if the loopback exists and has mpls enabled. Returns false otherwise."""
ifname, iface = get_by_name(yaml, ifname)
try:
if iface["mpls"] == True:
return True
except:
pass
return False

View File

@ -50,3 +50,8 @@ class TestLoopbackMethods(unittest.TestCase):
self.assertIn("loop1", ifs)
self.assertIn("loop2", ifs)
self.assertNotIn("loop-noexist", ifs)
def test_is_mpls(self):
self.assertTrue(loopback.is_mpls(self.cfg, "loop1"))
self.assertFalse(loopback.is_mpls(self.cfg, "loop2"))
self.assertFalse(loopback.is_mpls(self.cfg, "loop-noexist"))