From 2bbcff2ca088f6fc4201226181b6900f8c8470fb Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Tue, 15 Mar 2022 21:07:47 +0000 Subject: [PATCH] Also assert that targets of an L2XC do not have an address or LCP --- unittest/error-l2xc4.yaml | 8 +++++--- unittest/error-l2xc5.yaml | 2 +- unittest/error-l2xc6.yaml | 23 +++++++++++++++++++++++ validator/interface.py | 22 +++++++++++++++++----- 4 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 unittest/error-l2xc6.yaml diff --git a/unittest/error-l2xc4.yaml b/unittest/error-l2xc4.yaml index cfbd0cb..99969b5 100644 --- a/unittest/error-l2xc4.yaml +++ b/unittest/error-l2xc4.yaml @@ -2,9 +2,11 @@ test: description: "L2 cross connect targets cannot have an IP address or LCP" errors: expected: - - "interface .* l2xc so it cannot be an LCP" - - "interface .* l2xc so it cannot have an address" - count: 3 + - "interface .* has l2xc so it cannot be an LCP" + - "interface .* has l2xc so it cannot have an address" + - "interface .* l2xc target .* cannot be an LCP" + - "interface .* l2xc target .* cannot have an address" + count: 6 --- interfaces: GigabitEthernet1/0/0: diff --git a/unittest/error-l2xc5.yaml b/unittest/error-l2xc5.yaml index 6e0bb2a..42ea7db 100644 --- a/unittest/error-l2xc5.yaml +++ b/unittest/error-l2xc5.yaml @@ -2,7 +2,7 @@ test: description: "L2 cross connect from a phy cannot also have sub-interfaces" errors: expected: - - "interface .* l2xc so it cannot have sub-interfaces" + - "interface .* has l2xc so it cannot have sub-interfaces" count: 1 --- interfaces: diff --git a/unittest/error-l2xc6.yaml b/unittest/error-l2xc6.yaml new file mode 100644 index 0000000..f839abd --- /dev/null +++ b/unittest/error-l2xc6.yaml @@ -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' diff --git a/validator/interface.py b/validator/interface.py index edbc6a5..eaacbc2 100644 --- a/validator/interface.py +++ b/validator/interface.py @@ -383,13 +383,13 @@ def validate_interfaces(yaml): result = False if 'l2xc' in iface: 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 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 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 if not get_by_name(yaml, 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']): msgs.append("interface %s l2xc target %s is in a bridgedomain" % (ifname, iface['l2xc'])) 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): for sub_id, sub_iface in yaml['interfaces'][ifname]['sub-interfaces'].items(): @@ -442,10 +448,10 @@ def validate_interfaces(yaml): result = False if 'l2xc' in sub_iface: 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 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 if not get_by_name(yaml, 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']): msgs.append("sub-interface %s l2xc target %s is in a bridgedomain" % (ifname, sub_iface['l2xc'])) 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