From 0313666f69bcadaa57f579f38dd23f448be5844d Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 13 Mar 2022 13:17:14 +0000 Subject: [PATCH] Force LCP names to be unique --- example.yaml | 4 ++++ validator/interface.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/example.yaml b/example.yaml index 036491c..200dbf9 100644 --- a/example.yaml +++ b/example.yaml @@ -15,6 +15,10 @@ interfaces: 101: description: "Infra: L2 for FrysIX AS112" + GigabitEthernet1/0/1: + description: "Broken - has same LCP as above" + lcp: e0-1 + GigabitEthernet2/0/0: description: "Infra: LAG to xsw0" diff --git a/validator/interface.py b/validator/interface.py index 0c4a803..f5c2c76 100644 --- a/validator/interface.py +++ b/validator/interface.py @@ -84,6 +84,24 @@ def is_bond_member(yaml, ifname): return True return False +def unique_lcp(yaml, ifname): + """ Returns true if this interface has a unique LCP name """ + if not 'interfaces' in yaml: + return True + iface = get_by_name(yaml, ifname) + lcp = get_lcp(yaml, ifname) + if not lcp: + return True + + ncount = 0 + for sibling_ifname, sibling_iface in yaml['interfaces'].items(): + sibling_lcp = get_lcp(yaml, sibling_ifname) + if sibling_lcp == lcp and sibling_ifname != ifname: + ## print("%s overlaps with %s: %s" % (ifname, sibling_ifname, lcp)) + ncount = ncount + 1 + if ncount == 0: + return True + return False def has_lcp(yaml, ifname): """ Returns True if this interface or sub-interface has an LCP""" @@ -263,6 +281,10 @@ def validate_interfaces(args, yaml): if iface_address and not iface_lcp: msgs.append("interface %s has adddress(es) but no LCP" % ifname) result = False + if iface_lcp and not unique_lcp(yaml, ifname): + lcp = get_lcp(yaml, ifname) + msgs.append("interface %s does not have a unique LCP name %s" % (ifname, lcp)) + result = False if has_sub(yaml, ifname): for sub_id, sub_iface in yaml['interfaces'][ifname]['sub-interfaces'].items():