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 4681aec952
commit 9efcf345e0
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"))

View File

@ -91,6 +91,7 @@ loopbacks:
mtu: 1500
mac: 02:de:ad:11:be:ef
addresses: [ 10.0.2.1/24, 2001:db8:2::1/64 ]
mpls: true
bridgedomains:
bd1:

View File

@ -33,6 +33,7 @@ loopback:
lcp: str(max=15,matches='[a-z]+[a-z0-9-]*',required=False)
mtu: int(min=128,max=9216,required=False)
addresses: list(ip_interface(),min=1,max=6,required=False)
mpls: bool(required=False)
---
bondethernet:
description: str(exclude='\'"',len=64,required=False)

View File

@ -6,6 +6,7 @@ loopbacks:
mtu: 2000
lcp: "loop56789012345"
addresses: [ 192.0.2.1/29, 2001:db8::1/64 ]
mpls: true
loop2:
description: "Loopback, invalid because it has an address but no LCP"
mtu: 2000