From 0d8a28caddeffa591018343fc0015c9e74005a7f Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 13 Mar 2022 19:32:30 +0000 Subject: [PATCH] Enforce that when a bridgedomain has an address (ie a BVI), that it must also have an LCP --- unittest/correct-bridgedomain.yaml | 10 ---------- unittest/error-bridgedomain5.yaml | 19 +++++++++++++++++++ validator/bridgedomain.py | 4 ++++ 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 unittest/error-bridgedomain5.yaml diff --git a/unittest/correct-bridgedomain.yaml b/unittest/correct-bridgedomain.yaml index b79632e..c9eda94 100644 --- a/unittest/correct-bridgedomain.yaml +++ b/unittest/correct-bridgedomain.yaml @@ -34,11 +34,6 @@ interfaces: GigabitEthernet4/0/1: mtu: 9000 - GigabitEthernet4/0/2: - mtu: 9000 - GigabitEthernet4/0/3: - mtu: 9000 - BondEthernet0: mtu: 3000 sub-interfaces: @@ -61,8 +56,3 @@ bridgedomains: mtu: 9000 interfaces: [ GigabitEthernet4/0/0, GigabitEthernet4/0/1 ] lcp: "bvi11" - bd13: - description: "Bridge Domain 13, address but no LCP" - mtu: 9000 - interfaces: [ GigabitEthernet4/0/2, GigabitEthernet4/0/3 ] - addresses: [ 192.0.2.9/29, 2001:db8:1::1/64 ] diff --git a/unittest/error-bridgedomain5.yaml b/unittest/error-bridgedomain5.yaml new file mode 100644 index 0000000..55cc1ae --- /dev/null +++ b/unittest/error-bridgedomain5.yaml @@ -0,0 +1,19 @@ +test: + description: "A bridgedomain with a BVI address must have an LCP" + errors: + expected: + - "bridgedomain .* has an address but no LCP" + count: 1 +--- +interfaces: + GigabitEthernet1/0/0: + mtu: 3000 + GigabitEthernet1/0/1: + mtu: 3000 + +bridgedomains: + bd13: + description: "Bridge Domain 13, address but no LCP" + mtu: 3000 + interfaces: [ GigabitEthernet1/0/0, GigabitEthernet1/0/0 ] + addresses: [ 192.0.2.9/29, 2001:db8:1::1/64 ] diff --git a/validator/bridgedomain.py b/validator/bridgedomain.py index 418cb2a..c2f5b1e 100644 --- a/validator/bridgedomain.py +++ b/validator/bridgedomain.py @@ -32,6 +32,10 @@ def validate_bridgedomains(yaml): if 'mtu' in iface: bd_mtu = iface['mtu'] + if 'addresses' in iface and not 'lcp' in iface: + msgs.append("bridgedomain %s has an address but no LCP" % ifname) + result = False + if 'interfaces' in iface: for member in iface['interfaces']: member_iface = interface.get_by_name(yaml, member)