From 2104304f6a0197bc20b296532ef60eb73ee00b89 Mon Sep 17 00:00:00 2001 From: Sabari Jaganathan <93724860+sajagana@users.noreply.github.com> Date: Wed, 19 Apr 2023 17:12:00 +0530 Subject: [PATCH 1/2] Added bgpLocalAsnP child object to aci_l3out_bgp_peer module --- plugins/modules/aci_l3out_bgp_peer.py | 26 +++++++++++++++++++ .../targets/aci_l3out_bgp_peer/tasks/main.yml | 18 ++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/plugins/modules/aci_l3out_bgp_peer.py b/plugins/modules/aci_l3out_bgp_peer.py index 83bb9ce14..b030e37f1 100644 --- a/plugins/modules/aci_l3out_bgp_peer.py +++ b/plugins/modules/aci_l3out_bgp_peer.py @@ -130,6 +130,19 @@ - Name of the Route Control Profile direction. type: str required: true + local_as_number_config: + description: + - The local Autonomous System Number (ASN) configuration of the L3Out BGP Peer. + - The APIC defaults to C(none) when unset during creation. + type: str + choices: [ dual-as, no-prepend, none, replace-as ] + aliases: [ local_as_num_config ] + local_as_number: + description: + - The local Autonomous System Number (ASN) of the L3Out BGP Peer. + - The APIC defaults to 0 when unset during creation. + type: int + aliases: [ local_as_num ] state: description: - Use C(present) or C(absent) for adding or removing. @@ -439,6 +452,8 @@ def main(): elements="dict", options=route_control_profile_spec(), ), + local_as_number_config=dict(type="str", choices=["dual-as", "no-prepend", "none", "replace-as"], aliases=["local_as_num_config"]), + local_as_number=dict(type="int", aliases=["local_as_num"]), ) module = AnsibleModule( @@ -470,6 +485,8 @@ def main(): admin_state = module.params.get("admin_state") allow_self_as_count = module.params.get("allow_self_as_count") route_control_profiles = module.params.get("route_control_profiles") + local_as_number_config = module.params.get("local_as_number_config") + local_as_number = module.params.get("local_as_number") aci = ACIModule(module) if node_id: @@ -492,6 +509,15 @@ def main(): ) ) + if local_as_number_config or local_as_number: + child_configs.append( + dict( + bgpLocalAsnP=dict( + attributes=dict(asnPropagate=local_as_number_config, localAsn=local_as_number), + ), + ) + ) + if route_control_profiles: child_classes.append("bgpRsPeerToProfile") for profile in route_control_profiles: diff --git a/tests/integration/targets/aci_l3out_bgp_peer/tasks/main.yml b/tests/integration/targets/aci_l3out_bgp_peer/tasks/main.yml index 4e1784a6a..bc8e94ffb 100644 --- a/tests/integration/targets/aci_l3out_bgp_peer/tasks/main.yml +++ b/tests/integration/targets/aci_l3out_bgp_peer/tasks/main.yml @@ -201,6 +201,7 @@ address_type_controls: - af-ucast ttl: 2 + local_as_number_config: "replace-as" state: present register: add_eth_bgp_peer when: version.current.0.topSystem.attributes.version is version('4', '>=') @@ -239,6 +240,8 @@ - add_eth_bgp_peer.current.0.bgpPeerP.attributes.peerCtrl == "bfd" - add_eth_bgp_peer.current.0.bgpPeerP.attributes.ttl == "2" - add_eth_bgp_peer.current.0.bgpPeerP.attributes.annotation == 'orchestrator:ansible' + - add_eth_bgp_peer.current.0.bgpPeerP.children.0.bgpLocalAsnP.attributes.asnPropagate == "replace-as" + - add_eth_bgp_peer.current.0.bgpPeerP.children.0.bgpLocalAsnP.attributes.localAsn == "0" when: version.current.0.topSystem.attributes.version is version('4', '>=') - name: verify BGP peer has been created with correct attributes (version < 4) @@ -255,7 +258,7 @@ - name: verify remote AS object has been created correctly assert: that: - - add_eth_bgp_peer.current.0.bgpPeerP.children.1.bgpAsP.attributes.asn == "65456" + - add_eth_bgp_peer.current.0.bgpPeerP.children.2.bgpAsP.attributes.asn == "65456" when: version.current.0.topSystem.attributes.version is version('4', '>=') - name: verify remote AS object has been created correctly @@ -340,7 +343,7 @@ - name: verify remote AS object is still correct (version >= 4) assert: that: - - add_eth_bgp_peer_again.current.0.bgpPeerP.children.1.bgpAsP.attributes.asn == "65456" + - add_eth_bgp_peer_again.current.0.bgpPeerP.children.2.bgpAsP.attributes.asn == "65456" when: version.current.0.topSystem.attributes.version is version('4', '>=') - name: verify remote AS object his still correct (version < 4) @@ -376,6 +379,7 @@ allow_self_as_count: 3 ttl: 4 admin_state: disabled + local_as_number: 101 state: present register: update_eth_bgp_peer when: version.current.0.topSystem.attributes.version is version('4', '>=') @@ -419,6 +423,8 @@ - update_eth_bgp_peer.current.0.bgpPeerP.attributes.ttl == "4" - update_eth_bgp_peer.current.0.bgpPeerP.attributes.allowedSelfAsCnt == "3" - update_eth_bgp_peer.current.0.bgpPeerP.attributes.privateASctrl == "remove-exclusive" + - update_eth_bgp_peer.current.0.bgpPeerP.children.0.bgpLocalAsnP.attributes.asnPropagate == "replace-as" + - update_eth_bgp_peer.current.0.bgpPeerP.children.0.bgpLocalAsnP.attributes.localAsn == "101" when: version.current.0.topSystem.attributes.version is version('4', '>=') - name: verify BGP peer has been updated with correct attributes (version < 4) @@ -437,7 +443,7 @@ - name: verify remote AS object has been updated correctly (version >= 4) assert: that: - - update_eth_bgp_peer.current.0.bgpPeerP.children.1.bgpAsP.attributes.asn == "65457" + - update_eth_bgp_peer.current.0.bgpPeerP.children.2.bgpAsP.attributes.asn == "65457" when: version.current.0.topSystem.attributes.version is version('4', '>=') - name: verify remote AS object has been updated correctly (version < 4) @@ -508,7 +514,7 @@ - name: verify BGP remote AS (version >= 4) assert: that: - - query_eth_bgp_peer.current.0.bgpPeerP.children.1.bgpAsP.attributes.asn == "65457" + - query_eth_bgp_peer.current.0.bgpPeerP.children.2.bgpAsP.attributes.asn == "65457" when: version.current.0.topSystem.attributes.version is version('4', '>=') - name: verify BGP remote AS (version < 4) @@ -641,6 +647,8 @@ profile: "anstest_export" direction: "export" l3out: "anstest_l3out" + local_as_number_config: "dual-as" + local_as_number: 100 state: present check_mode: true register: cm_ln_rtctrl_present @@ -668,6 +676,8 @@ - nm_ln_rtctrl_present.previous | length == 0 - nm_ln_rtctrl_present.current.0.bgpPeerP.attributes.addr == "192.168.50.3" - nm_ln_rtctrl_present.current.0.bgpPeerP.children | length >= 2 + - nm_ln_rtctrl_present.current.0.bgpPeerP.children.2.bgpLocalAsnP.attributes.asnPropagate == "dual-as" + - nm_ln_rtctrl_present.current.0.bgpPeerP.children.2.bgpLocalAsnP.attributes.localAsn == "100" - name: Add BGP Peer to the Node Profile level (version >= 4) - normal mode - idempotency works aci_l3out_bgp_peer: From 27b7f0fdf3c9595b65eb392753ee7a1f505be396 Mon Sep 17 00:00:00 2001 From: Sabari Jaganathan <93724860+sajagana@users.noreply.github.com> Date: Mon, 24 Apr 2023 21:00:10 +0530 Subject: [PATCH 2/2] Added update validation check to local_as_number_config attribute --- tests/integration/targets/aci_l3out_bgp_peer/tasks/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/aci_l3out_bgp_peer/tasks/main.yml b/tests/integration/targets/aci_l3out_bgp_peer/tasks/main.yml index bc8e94ffb..8ed2daee3 100644 --- a/tests/integration/targets/aci_l3out_bgp_peer/tasks/main.yml +++ b/tests/integration/targets/aci_l3out_bgp_peer/tasks/main.yml @@ -380,6 +380,7 @@ ttl: 4 admin_state: disabled local_as_number: 101 + local_as_number_config: "dual-as" state: present register: update_eth_bgp_peer when: version.current.0.topSystem.attributes.version is version('4', '>=') @@ -423,7 +424,7 @@ - update_eth_bgp_peer.current.0.bgpPeerP.attributes.ttl == "4" - update_eth_bgp_peer.current.0.bgpPeerP.attributes.allowedSelfAsCnt == "3" - update_eth_bgp_peer.current.0.bgpPeerP.attributes.privateASctrl == "remove-exclusive" - - update_eth_bgp_peer.current.0.bgpPeerP.children.0.bgpLocalAsnP.attributes.asnPropagate == "replace-as" + - update_eth_bgp_peer.current.0.bgpPeerP.children.0.bgpLocalAsnP.attributes.asnPropagate == "dual-as" - update_eth_bgp_peer.current.0.bgpPeerP.children.0.bgpLocalAsnP.attributes.localAsn == "101" when: version.current.0.topSystem.attributes.version is version('4', '>=')