From b5902abfc18ceb939d897dd010feda90ebd3ce85 Mon Sep 17 00:00:00 2001 From: rohitthakur2590 Date: Fri, 13 Oct 2023 12:36:21 +0530 Subject: [PATCH 1/2] Fix secondary ip address parsing Signed-off-by: rohitthakur2590 --- changelogs/fragments/fix_virtual_ip_facts_issue.yaml | 3 +++ .../network/eos/facts/l3_interfaces/l3_interfaces.py | 4 ++-- tests/unit/modules/network/eos/test_eos_l3_interfaces.py | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/fix_virtual_ip_facts_issue.yaml diff --git a/changelogs/fragments/fix_virtual_ip_facts_issue.yaml b/changelogs/fragments/fix_virtual_ip_facts_issue.yaml new file mode 100644 index 000000000..b968b3387 --- /dev/null +++ b/changelogs/fragments/fix_virtual_ip_facts_issue.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fix secondary ip address parsing. diff --git a/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py index 4cf1f07f9..9de2d7b79 100644 --- a/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py @@ -100,10 +100,10 @@ def render_config(self, spec, conf): for match in matches: address, dummy, remainder = match.partition(" ") if address == "virtual": - ipv4 = {"virtual": True, "address": remainder} + ipv4 = {"virtual": True, "address": remainder.split(' ')[0]} else: ipv4 = {"address": address} - if remainder == "secondary": + if "secondary" in remainder: ipv4["secondary"] = True config["ipv4"].append(ipv4) diff --git a/tests/unit/modules/network/eos/test_eos_l3_interfaces.py b/tests/unit/modules/network/eos/test_eos_l3_interfaces.py index 364c12d8e..0702f8da1 100644 --- a/tests/unit/modules/network/eos/test_eos_l3_interfaces.py +++ b/tests/unit/modules/network/eos/test_eos_l3_interfaces.py @@ -294,6 +294,8 @@ def test_eos_l3_interfaces_parsed(self): "ip address 198.51.100.14/24", "interface Ethernet2", "ip address 203.0.113.27/24", + "interface Vlan100", + "ip address virtual 192.13.45.13/24 secondary", ] parsed_str = "\n".join(commands) set_module_args(dict(running_config=parsed_str, state="parsed")) @@ -301,6 +303,7 @@ def test_eos_l3_interfaces_parsed(self): parsed_list = [ {"name": "Ethernet1", "ipv4": [{"address": "198.51.100.14/24"}]}, {"name": "Ethernet2", "ipv4": [{"address": "203.0.113.27/24"}]}, + {"name": "Vlan100", "ipv4": [{"address": "192.13.45.13/24", "secondary": True, "virtual": True}]}, ] self.assertEqual(parsed_list, result["parsed"]) From ddc9961f20ff1e9aa7e1234e0639fc7eb336a02f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Oct 2023 07:07:34 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../network/eos/facts/l3_interfaces/l3_interfaces.py | 2 +- tests/unit/modules/network/eos/test_eos_l3_interfaces.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py index 9de2d7b79..8648ed1aa 100644 --- a/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py @@ -100,7 +100,7 @@ def render_config(self, spec, conf): for match in matches: address, dummy, remainder = match.partition(" ") if address == "virtual": - ipv4 = {"virtual": True, "address": remainder.split(' ')[0]} + ipv4 = {"virtual": True, "address": remainder.split(" ")[0]} else: ipv4 = {"address": address} if "secondary" in remainder: diff --git a/tests/unit/modules/network/eos/test_eos_l3_interfaces.py b/tests/unit/modules/network/eos/test_eos_l3_interfaces.py index 0702f8da1..a7970455e 100644 --- a/tests/unit/modules/network/eos/test_eos_l3_interfaces.py +++ b/tests/unit/modules/network/eos/test_eos_l3_interfaces.py @@ -303,7 +303,10 @@ def test_eos_l3_interfaces_parsed(self): parsed_list = [ {"name": "Ethernet1", "ipv4": [{"address": "198.51.100.14/24"}]}, {"name": "Ethernet2", "ipv4": [{"address": "203.0.113.27/24"}]}, - {"name": "Vlan100", "ipv4": [{"address": "192.13.45.13/24", "secondary": True, "virtual": True}]}, + { + "name": "Vlan100", + "ipv4": [{"address": "192.13.45.13/24", "secondary": True, "virtual": True}], + }, ] self.assertEqual(parsed_list, result["parsed"])