Add validator to ensure that bridgedomain interfaces occur in at most one bridgedomain. Ironically, this caught a bug in the bridgedomain5 test, where Gi1/0/0 was added twice.
This commit is contained in:
@ -15,5 +15,5 @@ bridgedomains:
|
|||||||
bd13:
|
bd13:
|
||||||
description: "Bridge Domain 13, address but no LCP"
|
description: "Bridge Domain 13, address but no LCP"
|
||||||
mtu: 3000
|
mtu: 3000
|
||||||
interfaces: [ GigabitEthernet1/0/0, GigabitEthernet1/0/0 ]
|
interfaces: [ GigabitEthernet1/0/0, GigabitEthernet1/0/1 ]
|
||||||
addresses: [ 192.0.2.9/29, 2001:db8:1::1/64 ]
|
addresses: [ 192.0.2.9/29, 2001:db8:1::1/64 ]
|
||||||
|
32
unittest/error-bridgedomain6.yaml
Normal file
32
unittest/error-bridgedomain6.yaml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
test:
|
||||||
|
description: "An interface can only occur in one bridgedomain, not two or more"
|
||||||
|
errors:
|
||||||
|
expected:
|
||||||
|
- "bridgedomain .* member .* is not unique"
|
||||||
|
count: 2
|
||||||
|
---
|
||||||
|
interfaces:
|
||||||
|
GigabitEthernet1/0/0:
|
||||||
|
mtu: 3000
|
||||||
|
GigabitEthernet1/0/1:
|
||||||
|
mtu: 3000
|
||||||
|
|
||||||
|
GigabitEthernet2/0/0:
|
||||||
|
mtu: 3000
|
||||||
|
sub-interfaces:
|
||||||
|
1234:
|
||||||
|
description: "BD11 and BD12"
|
||||||
|
|
||||||
|
bridgedomains:
|
||||||
|
bd10:
|
||||||
|
description: "Bridge Domain 10 is well formed"
|
||||||
|
mtu: 3000
|
||||||
|
interfaces: [ GigabitEthernet1/0/0, GigabitEthernet1/0/1 ]
|
||||||
|
bd11:
|
||||||
|
description: "Bridge Domain 11 uses Gi2/0/0.1234, but so does Bridge Domain 12"
|
||||||
|
mtu: 1500
|
||||||
|
interfaces: [ GigabitEthernet2/0/0.1234 ]
|
||||||
|
bd12:
|
||||||
|
description: "Bridge Domain 12 uses Gi2/0/0.1234, but so does Bridge Domain 11"
|
||||||
|
mtu: 1500
|
||||||
|
interfaces: [ GigabitEthernet2/0/0.1234 ]
|
@ -67,6 +67,10 @@ def validate_bridgedomains(yaml):
|
|||||||
result = False
|
result = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if not interface.is_bridge_interface_unique(yaml, member):
|
||||||
|
msgs.append("bridgedomain %s member %s is not unique" % (ifname, member))
|
||||||
|
result = False
|
||||||
|
|
||||||
if interface.has_lcp(yaml, member):
|
if interface.has_lcp(yaml, member):
|
||||||
msgs.append("bridgedomain %s member %s has an LCP" % (ifname, member))
|
msgs.append("bridgedomain %s member %s has an LCP" % (ifname, member))
|
||||||
result = False
|
result = False
|
||||||
|
@ -100,8 +100,41 @@ def is_bond_member(yaml, ifname):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_bridge_interfaces(yaml):
|
||||||
|
""" Returns a list of all interfaces that are bridgedomain members """
|
||||||
|
|
||||||
|
ret = []
|
||||||
|
if not 'bridgedomains' in yaml:
|
||||||
|
return ret
|
||||||
|
|
||||||
|
for ifname, iface in yaml['bridgedomains'].items():
|
||||||
|
if 'interfaces' in iface:
|
||||||
|
ret.extend(iface['interfaces'])
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def is_bridge_interface_unique(yaml, ifname):
|
||||||
|
""" Returns True if this interface is referenced in bridgedomains zero or one times """
|
||||||
|
|
||||||
|
ifs = get_bridge_interfaces(yaml)
|
||||||
|
n = ifs.count(ifname)
|
||||||
|
|
||||||
|
if n == 0 or n == 1:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def is_bridge_interface(yaml, ifname):
|
||||||
|
""" Returns True if this interface is a member of a BridgeDomain """
|
||||||
|
|
||||||
|
if ifname in get_bridge_interfaces(yaml):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def has_lcp(yaml, ifname):
|
def has_lcp(yaml, ifname):
|
||||||
""" Returns True if this interface or sub-interface has an LCP"""
|
""" Returns True if this interface or sub-interface has an LCP """
|
||||||
if not 'interfaces' in yaml:
|
if not 'interfaces' in yaml:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user