From 8825984d49da847d940f47773733dd50add70d1e Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 13 Mar 2022 19:27:27 +0000 Subject: [PATCH] Force loopbacks with an address to have an LCP --- unittest/correct-loopback.yaml | 5 ----- unittest/error-loopback1.yaml | 12 ++++++++++++ validator/loopback.py | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 unittest/error-loopback1.yaml diff --git a/unittest/correct-loopback.yaml b/unittest/correct-loopback.yaml index be780cc..c78e968 100644 --- a/unittest/correct-loopback.yaml +++ b/unittest/correct-loopback.yaml @@ -10,11 +10,6 @@ loopbacks: mtu: 9216 addresses: [ 192.0.2.1/29 ] - loop10: - description: "Loopback instance loop10, with address, but no LCP" - mtu: 9216 - addresses: [ 192.0.2.1/29 ] - loop20: description: "Loopback instance loop20, with LCP, but no address" mtu: 9216 diff --git a/unittest/error-loopback1.yaml b/unittest/error-loopback1.yaml new file mode 100644 index 0000000..e427da1 --- /dev/null +++ b/unittest/error-loopback1.yaml @@ -0,0 +1,12 @@ +test: + description: "Cannot give an IP address to a loopback without LCP" + errors: + expected: + - "loopback .* has an address but no LCP" + count: 1 +--- +loopbacks: + loop10: + description: "Loopback instance loop10, with address, but no LCP" + mtu: 9216 + addresses: [ 192.0.2.1/29 ] diff --git a/validator/loopback.py b/validator/loopback.py index 381e46b..0acbee3 100644 --- a/validator/loopback.py +++ b/validator/loopback.py @@ -26,4 +26,8 @@ def validate_loopbacks(yaml): logger.debug("Validating loopbacks...") for ifname, iface in yaml['loopbacks'].items(): logger.debug("loopback %s" % iface) + if 'addresses' in iface and not 'lcp' in iface: + msgs.append("loopback %s has an address but no LCP" % ifname) + result = False + return result, msgs