From e988518e14b47cea9a7b5c4ab6a115feb390c5fc Mon Sep 17 00:00:00 2001 From: Luca Haneklau Date: Sun, 1 Aug 2021 20:11:13 +0200 Subject: [PATCH] fixed vyos_config smart diffing `...` incorrectly applying to children --- plugins/cliconf_utils/vyosconf.py | 10 +++++----- tests/unit/cliconf/test_utils_vyosconf.py | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/cliconf_utils/vyosconf.py b/plugins/cliconf_utils/vyosconf.py index a94e74bb..21c5872e 100644 --- a/plugins/cliconf_utils/vyosconf.py +++ b/plugins/cliconf_utils/vyosconf.py @@ -205,12 +205,12 @@ def diff_to(self, other, structure): (subset, subdel) = self.diff_to(other[key], structure[key]) for s in subset: toset.append(quoted_key + " " + s) - if KEEP_EXISTING_VALUES not in other[key]: - for d in subdel: - todel.append(quoted_key + " " + d) + for d in subdel: + todel.append(quoted_key + " " + d) else: - # keys only in this, pls del - todel.append(quoted_key) + # keys only in this, delete if KEEP_EXISTING_VALUES not set + if KEEP_EXISTING_VALUES not in other: + todel.append(quoted_key) continue # del for (key, value) in other.items(): if key == KEEP_EXISTING_VALUES: diff --git a/tests/unit/cliconf/test_utils_vyosconf.py b/tests/unit/cliconf/test_utils_vyosconf.py index bc533012..a568649a 100644 --- a/tests/unit/cliconf/test_utils_vyosconf.py +++ b/tests/unit/cliconf/test_utils_vyosconf.py @@ -173,6 +173,13 @@ def test_diff_commands_to(self): ["delete a b 'c a'", "set a b 'a c'"], ) + self.assertListEqual( + VyosConf( + ["set a b c d", "set a b c e", "set a b d"] + ).diff_commands_to(VyosConf(["set a b c d", "set a b ..."])), + ["delete a b c e"], + ) + if __name__ == "__main__": unittest.main()