Skip to content

Commit

Permalink
l3_interfaces - Fix gathering wrong facts for source interface in ipv…
Browse files Browse the repository at this point in the history
…4. (#1065)

* Fix L3 interfaces source interface parser

* Add changelog

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
roverflow and pre-commit-ci[bot] authored May 2, 2024
1 parent 604a62b commit 0c5ee86
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/l3_sinterface_parser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- ios_l3_interfaces - Fix gathering wrong facts for source interface in ipv4.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def __init__(self, lines=None, module=None):
"name": "ipv4.source_interface",
"getval": re.compile(
r"""\s+ip\sunnumbered
(\s(?P<name>\S+))
(\s(?P<src_name>\S+))
(\s(?P<poll>poll))?
(\s(?P<point_to_point>point-to-point))?
$""",
Expand All @@ -180,7 +180,7 @@ def __init__(self, lines=None, module=None):
"ipv4": [
{
"source_interface": {
"name": "{{ True if name is defined }}",
"name": "{{ src_name }}",
"poll": "{{ True if poll is defined }}",
"point_to_point": "{{ True if point_to_point is defined }}",
},
Expand Down
29 changes: 28 additions & 1 deletion tests/unit/modules/network/ios/test_ios_l3_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ def test_ios_l3_interfaces_merged(self):
"ipv6 enable",
"no autostate",
]

result = self.execute_module(changed=True)
self.assertEqual(sorted(result["commands"]), sorted(commands))

Expand Down Expand Up @@ -524,3 +523,31 @@ def test_ios_l3_interfaces_remove_primary_replaced(self):
]
result = self.execute_module(changed=True)
self.assertEqual(sorted(result["commands"]), sorted(commands))

def test_ios_l3_interfaces_gathered(self):
self.execute_show_command.return_value = dedent(
"""\
interface GigabitEthernet0/1
no autostate
interface Vlan901
ip unnumbered Loopback2
""",
)
set_module_args(
dict(
state="gathered",
),
)
result = self.execute_module(changed=False)
gathered = [
{
"name": "GigabitEthernet0/1",
"autostate": False,
},
{
"name": "Vlan901",
"ipv4": [{"source_interface": {"name": "Loopback2"}}],
"autostate": True,
},
]
self.assertEqual(result["gathered"], gathered)

0 comments on commit 0c5ee86

Please sign in to comment.