Also assert that targets of an L2XC do not have an address or LCP

This commit is contained in:
Pim van Pelt
2022-03-15 21:07:47 +00:00
parent 5876465327
commit 2bbcff2ca0
4 changed files with 46 additions and 9 deletions

View File

@ -2,9 +2,11 @@ test:
description: "L2 cross connect targets cannot have an IP address or LCP" description: "L2 cross connect targets cannot have an IP address or LCP"
errors: errors:
expected: expected:
- "interface .* l2xc so it cannot be an LCP" - "interface .* has l2xc so it cannot be an LCP"
- "interface .* l2xc so it cannot have an address" - "interface .* has l2xc so it cannot have an address"
count: 3 - "interface .* l2xc target .* cannot be an LCP"
- "interface .* l2xc target .* cannot have an address"
count: 6
--- ---
interfaces: interfaces:
GigabitEthernet1/0/0: GigabitEthernet1/0/0:

View File

@ -2,7 +2,7 @@ test:
description: "L2 cross connect from a phy cannot also have sub-interfaces" description: "L2 cross connect from a phy cannot also have sub-interfaces"
errors: errors:
expected: expected:
- "interface .* l2xc so it cannot have sub-interfaces" - "interface .* has l2xc so it cannot have sub-interfaces"
count: 1 count: 1
--- ---
interfaces: interfaces:

23
unittest/error-l2xc6.yaml Normal file
View File

@ -0,0 +1,23 @@
test:
description: "L2 cross connect target cannot have an IP address or LCP"
errors:
expected:
- "sub-interface .* l2xc target .* cannot have an address"
- "sub-interface .* l2xc target .* cannot be an LCP"
count: 2
---
interfaces:
GigabitEthernet1/0/0:
sub-interfaces:
100:
l2xc: GigabitEthernet1/0/1.100
200:
l2xc: GigabitEthernet1/0/1.200
GigabitEthernet1/0/1:
lcp: "xe1-0-1"
sub-interfaces:
100:
addresses: [ 192.0.2.1/30 ]
200:
lcp: 'foo'

View File

@ -383,13 +383,13 @@ def validate_interfaces(yaml):
result = False result = False
if 'l2xc' in iface: if 'l2xc' in iface:
if has_sub(yaml, ifname): if has_sub(yaml, ifname):
msgs.append("interface %s is l2xc so it cannot have sub-interfaces" % (ifname)) msgs.append("interface %s has l2xc so it cannot have sub-interfaces" % (ifname))
result = False result = False
if iface_lcp: if iface_lcp:
msgs.append("interface %s is l2xc so it cannot be an LCP" % (ifname)) msgs.append("interface %s has l2xc so it cannot be an LCP" % (ifname))
result = False result = False
if iface_address: if iface_address:
msgs.append("interface %s is l2xc so it cannot have an address" % (ifname)) msgs.append("interface %s has l2xc so it cannot have an address" % (ifname))
result = False result = False
if not get_by_name(yaml, iface['l2xc']): if not get_by_name(yaml, iface['l2xc']):
msgs.append("interface %s l2xc target %s does not exist" % (ifname, iface['l2xc'])) msgs.append("interface %s l2xc target %s does not exist" % (ifname, iface['l2xc']))
@ -400,6 +400,12 @@ def validate_interfaces(yaml):
if is_bridge_interface(yaml, iface['l2xc']): if is_bridge_interface(yaml, iface['l2xc']):
msgs.append("interface %s l2xc target %s is in a bridgedomain" % (ifname, iface['l2xc'])) msgs.append("interface %s l2xc target %s is in a bridgedomain" % (ifname, iface['l2xc']))
result = False result = False
if has_lcp(yaml, iface['l2xc']):
msgs.append("interface %s l2xc target %s cannot be an LCP" % (ifname, iface['l2xc']))
result = False
if has_address(yaml, iface['l2xc']):
msgs.append("interface %s l2xc target %s cannot have an address" % (ifname, iface['l2xc']))
result = False
if has_sub(yaml, ifname): if has_sub(yaml, ifname):
for sub_id, sub_iface in yaml['interfaces'][ifname]['sub-interfaces'].items(): for sub_id, sub_iface in yaml['interfaces'][ifname]['sub-interfaces'].items():
@ -442,10 +448,10 @@ def validate_interfaces(yaml):
result = False result = False
if 'l2xc' in sub_iface: if 'l2xc' in sub_iface:
if has_lcp(yaml, sub_ifname): if has_lcp(yaml, sub_ifname):
msgs.append("sub-interface %s is l2xc so it cannot be an LCP" % (sub_ifname)) msgs.append("sub-interface %s has l2xc so it cannot be an LCP" % (sub_ifname))
result = False result = False
if has_address(yaml, sub_ifname): if has_address(yaml, sub_ifname):
msgs.append("sub-interface %s is l2xc so it cannot have an address" % (sub_ifname)) msgs.append("sub-interface %s has l2xc so it cannot have an address" % (sub_ifname))
result = False result = False
if not get_by_name(yaml, sub_iface['l2xc']): if not get_by_name(yaml, sub_iface['l2xc']):
msgs.append("sub-interface %s l2xc target %s does not exist" % (ifname, sub_iface['l2xc'])) msgs.append("sub-interface %s l2xc target %s does not exist" % (ifname, sub_iface['l2xc']))
@ -456,6 +462,12 @@ def validate_interfaces(yaml):
if is_bridge_interface(yaml, sub_iface['l2xc']): if is_bridge_interface(yaml, sub_iface['l2xc']):
msgs.append("sub-interface %s l2xc target %s is in a bridgedomain" % (ifname, sub_iface['l2xc'])) msgs.append("sub-interface %s l2xc target %s is in a bridgedomain" % (ifname, sub_iface['l2xc']))
result = False result = False
if has_lcp(yaml, sub_iface['l2xc']):
msgs.append("sub-interface %s l2xc target %s cannot be an LCP" % (sub_ifname, sub_iface['l2xc']))
result = False
if has_address(yaml, sub_iface['l2xc']):
msgs.append("sub-interface %s l2xc target %s cannot have an address" % (sub_ifname, sub_iface['l2xc']))
result = False
return result, msgs return result, msgs