From 22d6c1c97bda0f614d6a29add36c67e50730a4e9 Mon Sep 17 00:00:00 2001 From: rohitthakur2590 Date: Wed, 8 Feb 2023 16:58:30 +0530 Subject: [PATCH 1/5] Fix BGP peer-group and ebgp-multihop config/facts-gathering Signed-off-by: rohitthakur2590 --- changelogs/fragments/fix_eos_bgp_global.yaml | 4 ++++ .../module_utils/network/eos/rm_templates/bgp_global.py | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/fix_eos_bgp_global.yaml diff --git a/changelogs/fragments/fix_eos_bgp_global.yaml b/changelogs/fragments/fix_eos_bgp_global.yaml new file mode 100644 index 000000000..c311bf566 --- /dev/null +++ b/changelogs/fragments/fix_eos_bgp_global.yaml @@ -0,0 +1,4 @@ +--- +bugfixes: + - fix facts gathering for ebgp-multihop attribute. + - fix bgp neighbor peer-group command formation. diff --git a/plugins/module_utils/network/eos/rm_templates/bgp_global.py b/plugins/module_utils/network/eos/rm_templates/bgp_global.py index a1fcee400..da549721c 100644 --- a/plugins/module_utils/network/eos/rm_templates/bgp_global.py +++ b/plugins/module_utils/network/eos/rm_templates/bgp_global.py @@ -14,7 +14,6 @@ facilitates both facts gathering and native command generation for the given network resource. """ - import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( @@ -271,7 +270,7 @@ def _tmplt_bgp_neighbor(config_data): if config_data["neighbor"]["additional_paths"] == "send": command += "any" elif config_data["neighbor"].get("peer_group"): - command += " peer group" + command += " peer-group " + config_data["neighbor"].get("peer_group") if ( config_data["neighbor"]["peer_group"] != config_data["neighbor"]["peer_group"] @@ -304,7 +303,7 @@ def _tmplt_bgp_neighbor(config_data): elif config_data["neighbor"].get("dont_capability_negotiate"): command += " dont-capability-negotiate" elif config_data["neighbor"].get("ebgp_multihop"): - command += " ebgp-multiphop" + command += " ebgp-multihop" if config_data["neighbor"]["ebgp_multihop"].get("ttl"): command += " {ttl}".format( **config_data["neighbor"]["ebgp_multihop"] @@ -1741,7 +1740,7 @@ def __init__(self, lines=None, module=None): \s*neighbor \s+(?P\S+) \s+ebgp-multihop - \s*(?P\d+)* + \s+(?P\d+)* $""", re.VERBOSE, ), @@ -2349,7 +2348,7 @@ def __init__(self, lines=None, module=None): r""" \s*neighbor \s+(?P\S+) - \s+peer\sgroup + \s+peer-group \s*(?P\S+) *$""", re.VERBOSE, From dcd2df0a0695abd0f3b67c095e2f0e17dc47cdff Mon Sep 17 00:00:00 2001 From: rohitthakur2590 Date: Mon, 10 Apr 2023 14:26:06 +0530 Subject: [PATCH 2/5] Update tests Signed-off-by: rohitthakur2590 --- .../eos/facts/bgp_global/bgp_global.py | 2 ++ .../network/eos/test_eos_bgp_global.py | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugins/module_utils/network/eos/facts/bgp_global/bgp_global.py b/plugins/module_utils/network/eos/facts/bgp_global/bgp_global.py index 9cb785a3c..e430eaee8 100644 --- a/plugins/module_utils/network/eos/facts/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/eos/facts/bgp_global/bgp_global.py @@ -57,6 +57,8 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self.get_config(connection) # remove address_family configs from bgp_global + import q + q(data) bgp_global_config = [] start = False self._af = False diff --git a/tests/unit/modules/network/eos/test_eos_bgp_global.py b/tests/unit/modules/network/eos/test_eos_bgp_global.py index bb3cd7090..639979d10 100644 --- a/tests/unit/modules/network/eos/test_eos_bgp_global.py +++ b/tests/unit/modules/network/eos/test_eos_bgp_global.py @@ -243,6 +243,29 @@ def test_eos_bgp_global_merged(self): ] self.execute_module(changed=True, commands=commands) + def test_eos_bgp_global_merged_multihop(self): + set_module_args( + dict( + config=dict( + as_number="65000", + router_id="192.168.1.1", + neighbor=[ + dict(neighbor_address="10.2.2.1", peer_group="evpn", ebgp_multihop=dict(set=True, ttl=2)), + ], + ), + state="merged", + ), + ) + commands = [ + "router bgp 65000", + "neighbor evpn ebgp-multihop 2", + "neighbor evpn peer-group evpn", + "neighbor 10.2.2.1 peer-group evpn", + "router-id 192.168.1.1" + + ] + self.execute_module(changed=True, commands=commands) + def test_eos_bgp_global_replaced_idempotent(self): set_module_args( dict( From b9db9416ed1335fd3449e6d8668acedcea0f1f9a Mon Sep 17 00:00:00 2001 From: rohitthakur2590 Date: Mon, 10 Apr 2023 14:31:24 +0530 Subject: [PATCH 3/5] Update test Signed-off-by: rohitthakur2590 --- plugins/module_utils/network/eos/facts/bgp_global/bgp_global.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/module_utils/network/eos/facts/bgp_global/bgp_global.py b/plugins/module_utils/network/eos/facts/bgp_global/bgp_global.py index e430eaee8..9cb785a3c 100644 --- a/plugins/module_utils/network/eos/facts/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/eos/facts/bgp_global/bgp_global.py @@ -57,8 +57,6 @@ def populate_facts(self, connection, ansible_facts, data=None): data = self.get_config(connection) # remove address_family configs from bgp_global - import q - q(data) bgp_global_config = [] start = False self._af = False From 3e7642d2e0ab3513a9f1249a974ee6bf1eff1fd9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Apr 2023 10:24:28 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/modules/network/eos/test_eos_bgp_global.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/unit/modules/network/eos/test_eos_bgp_global.py b/tests/unit/modules/network/eos/test_eos_bgp_global.py index 639979d10..56cdcd51e 100644 --- a/tests/unit/modules/network/eos/test_eos_bgp_global.py +++ b/tests/unit/modules/network/eos/test_eos_bgp_global.py @@ -250,7 +250,11 @@ def test_eos_bgp_global_merged_multihop(self): as_number="65000", router_id="192.168.1.1", neighbor=[ - dict(neighbor_address="10.2.2.1", peer_group="evpn", ebgp_multihop=dict(set=True, ttl=2)), + dict( + neighbor_address="10.2.2.1", + peer_group="evpn", + ebgp_multihop=dict(set=True, ttl=2), + ), ], ), state="merged", @@ -261,8 +265,7 @@ def test_eos_bgp_global_merged_multihop(self): "neighbor evpn ebgp-multihop 2", "neighbor evpn peer-group evpn", "neighbor 10.2.2.1 peer-group evpn", - "router-id 192.168.1.1" - + "router-id 192.168.1.1", ] self.execute_module(changed=True, commands=commands) From fd7777b20861108bdbf4c80fde12fcbd6e1ccda3 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle Date: Tue, 7 Jan 2025 10:20:36 +0530 Subject: [PATCH 5/5] update --- changelogs/fragments/fix_eos_bgp_global.yaml | 1 - .../network/eos/rm_templates/bgp_global.py | 2 +- .../unit/modules/network/eos/test_eos_bgp_global.py | 13 ++++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/changelogs/fragments/fix_eos_bgp_global.yaml b/changelogs/fragments/fix_eos_bgp_global.yaml index c311bf566..98bd65b86 100644 --- a/changelogs/fragments/fix_eos_bgp_global.yaml +++ b/changelogs/fragments/fix_eos_bgp_global.yaml @@ -1,4 +1,3 @@ --- bugfixes: - fix facts gathering for ebgp-multihop attribute. - - fix bgp neighbor peer-group command formation. diff --git a/plugins/module_utils/network/eos/rm_templates/bgp_global.py b/plugins/module_utils/network/eos/rm_templates/bgp_global.py index 352896eec..386fe198a 100644 --- a/plugins/module_utils/network/eos/rm_templates/bgp_global.py +++ b/plugins/module_utils/network/eos/rm_templates/bgp_global.py @@ -2261,7 +2261,7 @@ def __init__(self, lines=None, module=None): r""" \s*neighbor \s+(?P\S+) - \s+peer-group + \s+peer\sgroup \s*(?P\S+) *$""", re.VERBOSE, diff --git a/tests/unit/modules/network/eos/test_eos_bgp_global.py b/tests/unit/modules/network/eos/test_eos_bgp_global.py index baafb658c..35488ff69 100644 --- a/tests/unit/modules/network/eos/test_eos_bgp_global.py +++ b/tests/unit/modules/network/eos/test_eos_bgp_global.py @@ -206,7 +206,7 @@ def test_eos_bgp_global_merged(self): "neighbor peer1 peer group", "neighbor peer1 bfd c-bit", "neighbor peer1 maximum-routes 12000", - "neighbor peer1 ebgp-multiphop", + "neighbor peer1 ebgp-multihop", "neighbor peer1 send-community link-bandwidth divide ratio", "neighbor peer1 timers 5 10", "neighbor peer1 ttl maximum-hops 33", @@ -242,7 +242,7 @@ def test_eos_bgp_global_merged_multihop(self): set_module_args( dict( config=dict( - as_number="65000", + as_number="65535", router_id="192.168.1.1", neighbor=[ dict( @@ -256,10 +256,9 @@ def test_eos_bgp_global_merged_multihop(self): ), ) commands = [ - "router bgp 65000", - "neighbor evpn ebgp-multihop 2", - "neighbor evpn peer-group evpn", - "neighbor 10.2.2.1 peer-group evpn", + "router bgp 65535", + "neighbor 10.2.2.1 ebgp-multihop 2", + "neighbor 10.2.2.1 peer group", "router-id 192.168.1.1", ] self.execute_module(changed=True, commands=commands) @@ -826,7 +825,7 @@ def test_eos_bgp_global_rendered(self): "neighbor peer2 peer group", "neighbor peer2 local-as 55 no-prepend replace-as fallback", "neighbor peer2 next-hop-v6-addr 5001::/64 in", - "neighbor peer2 ebgp-multiphop 10", + "neighbor peer2 ebgp-multihop 10", "neighbor peer2 enforce-first-as", "neighbor peer2 fall-over bfd", "neighbor peer2 graceful-restart-helper",