From 9626ed8634e34b9a64e18d2587a84223863fa575 Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Fri, 18 Aug 2023 17:18:13 -0500 Subject: [PATCH] Fixes ios default interface idempotent options --- hier_config/options.py | 8 ++------ tests/fixtures/options_ios.yml | 7 ++++--- tests/test_various.py | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/hier_config/options.py b/hier_config/options.py index f6239d7..13e7201 100644 --- a/hier_config/options.py +++ b/hier_config/options.py @@ -68,12 +68,8 @@ ], "idempotent_commands": [ {"lineage": [{"startswith": "vlan"}, {"startswith": "name"}]}, - { - "lineage": [ - {"startswith": "interface"}, - {"startswith": ["description", "ip address"]}, - ] - }, + {"lineage": [{"startswith": "interface"}, {"startswith": "description"}]}, + {"lineage": [{"startswith": "interface"}, {"startswith": "ip address"}]}, ], } iosxe_options: dict = { diff --git a/tests/fixtures/options_ios.yml b/tests/fixtures/options_ios.yml index b9bee69..92b80e6 100644 --- a/tests/fixtures/options_ios.yml +++ b/tests/fixtures/options_ios.yml @@ -102,9 +102,10 @@ idempotent_commands: - startswith: name - lineage: - startswith: interface - - startswith: - - description - - ip address + - startswith: description +- lineage: + - startswith: interface + - startswith: ip address # Default when expression: list of expressions negation_default_when: [] diff --git a/tests/test_various.py b/tests/test_various.py index f505a77..f56ac4d 100644 --- a/tests/test_various.py +++ b/tests/test_various.py @@ -24,3 +24,30 @@ def test_issue104() -> None: } rem_lines = {line.cisco_style_text() for line in rem.all_children()} assert expected_rem_lines == rem_lines + + +def test_issue_113() -> None: + running_config_raw = ( + "interface Ethernet1/1\n" + " description test\n" + " ip address 192.0.2.1 255.255.255.0\n" + " switchport\n" + ) + generated_config_raw = ( + "interface Ethernet1/1\n" + " ip address 192.0.2.1 255.255.255.0\n" + " switchport\n" + ) + + host = Host(hostname="test", os="ios") + running_config = HConfig(host=host) + running_config.load_from_string(running_config_raw) + generated_config = HConfig(host=host) + generated_config.load_from_string(generated_config_raw) + rem = running_config.config_to_get_to(generated_config) + expected_rem_lines = { + "interface Ethernet1/1", + " no description test", + } + rem_lines = {line.cisco_style_text() for line in rem.all_children()} + assert expected_rem_lines == rem_lines