Skip to content

Commit

Permalink
Merge pull request #114 from joewesch/113_ios-idempotent-fix
Browse files Browse the repository at this point in the history
Fixes ios default interface idempotent options
  • Loading branch information
aedwardstx committed Sep 9, 2023
2 parents 8d8ab08 + 9626ed8 commit b1e23a2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
8 changes: 2 additions & 6 deletions hier_config/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
7 changes: 4 additions & 3 deletions tests/fixtures/options_ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down
27 changes: 27 additions & 0 deletions tests/test_various.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b1e23a2

Please sign in to comment.