diff --git a/validator/lcp.py b/validator/lcp.py index 350762c..2006eeb 100644 --- a/validator/lcp.py +++ b/validator/lcp.py @@ -13,11 +13,12 @@ # import logging -def get_lcps(yaml): - """ Returns a list of all LCPs configured in the system, or an empty list if there are none. """ +def get_lcps(yaml, interfaces=True, loopbacks=True, bridgedomains=True): + """ Returns a list of LCPs configured in the system. Optionally (de)select the different + types of LCP. Return an empty list if there are none of the given type(s). """ ret = [] - if 'interfaces' in yaml: + if interfaces and 'interfaces' in yaml: for ifname, iface in yaml['interfaces'].items(): if 'lcp' in iface: ret.append(iface['lcp']) @@ -26,11 +27,11 @@ def get_lcps(yaml): if 'lcp' in sub_iface: ret.append(sub_iface['lcp']) - if 'loopbacks' in yaml: + if loopbacks and 'loopbacks' in yaml: for ifname, iface in yaml['loopbacks'].items(): if 'lcp' in iface: ret.append(iface['lcp']) - if 'bridgedomains' in yaml: + if bridgedomains and 'bridgedomains' in yaml: for ifname, iface in yaml['bridgedomains'].items(): if 'lcp' in iface: ret.append(iface['lcp']) diff --git a/validator/test_lcp.py b/validator/test_lcp.py index aeeb4fb..2611ebb 100644 --- a/validator/test_lcp.py +++ b/validator/test_lcp.py @@ -13,6 +13,9 @@ class TestLCPMethods(unittest.TestCase): self.assertIn("e1", lcps) self.assertIn("foo", lcps) self.assertIn("e2", lcps) + loopback_lcps = lcp.get_lcps(self.cfg, interfaces=False, bridgedomains=False) + self.assertIn("thrice", loopback_lcps) + self.assertNotIn("e1", loopback_lcps) def test_lcp(self): self.assertTrue(lcp.is_unique(self.cfg, "e1"))