From c8e85ce1d1a266deb629359adca3efc8bf5f6f87 Mon Sep 17 00:00:00 2001 From: Rohit Thakur Date: Fri, 12 Apr 2024 23:23:13 +0530 Subject: [PATCH 01/10] Add support for cli_restore functionality provided with in netcommon module (#1053) * tbr Signed-off-by: rohitthakur2590 * Add support for cli_restore functionality provided with in netcommon module Signed-off-by: rohitthakur2590 * Update netcommon base Signed-off-by: rohitthakur2590 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: rohitthakur2590 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- changelogs/fragments/add_restore_support.yaml | 6 ++++++ plugins/cliconf/ios.py | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 changelogs/fragments/add_restore_support.yaml diff --git a/changelogs/fragments/add_restore_support.yaml b/changelogs/fragments/add_restore_support.yaml new file mode 100644 index 000000000..ff161ac71 --- /dev/null +++ b/changelogs/fragments/add_restore_support.yaml @@ -0,0 +1,6 @@ +major_changes: + - Update the netcommon base version 6.1.0 to support cli_restore plugin. +minor_changes: + - Add support for cli_restore functionality. + - cli_restore module is part of netcommon. + - Please refer the PR to know more about core changes (https://github.com/ansible-collections/ansible.netcommon/pull/618). diff --git a/plugins/cliconf/ios.py b/plugins/cliconf/ios.py index be62c3724..324b7f000 100644 --- a/plugins/cliconf/ios.py +++ b/plugins/cliconf/ios.py @@ -180,6 +180,13 @@ def get_config(self, source="running", flags=None, format=None): return self.send_command(cmd) + @enable_mode + def restore(self, filename=None, path=""): + if not filename: + raise ValueError("'file_name' value is required for restore") + cmd = f"configure replace {path}{filename} force" + return self.send_command(cmd) + def get_diff( self, candidate=None, From 604a62bd473d09f53c37e394584128786b212828 Mon Sep 17 00:00:00 2001 From: Rohit Thakur Date: Fri, 12 Apr 2024 23:35:56 +0530 Subject: [PATCH 02/10] Prepare release 8.0.0 (#1054) * Prepare release 8.0.0 Signed-off-by: rohitthakur2590 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: rohitthakur2590 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CHANGELOG.rst | 89 +++++++------- changelogs/changelog.yaml | 114 ++++++++---------- changelogs/fragments/add_restore_support.yaml | 6 - changelogs/fragments/sanityfix.yml | 4 - galaxy.yml | 4 +- 5 files changed, 97 insertions(+), 120 deletions(-) delete mode 100644 changelogs/fragments/add_restore_support.yaml delete mode 100644 changelogs/fragments/sanityfix.yml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 586e87d69..9fdf040df 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,21 @@ Cisco Ios Collection Release Notes .. contents:: Topics +v8.0.0 +====== + +Major Changes +------------- + +- Update the netcommon base version 6.1.0 to support cli_restore plugin. + +Minor Changes +------------- + +- Add support for cli_restore functionality. +- Please refer the PR to know more about core changes (https://github.com/ansible-collections/ansible.netcommon/pull/618). +- cli_restore module is part of netcommon. + v7.0.0 ====== @@ -671,7 +686,7 @@ Documentation Changes New Modules ----------- -- ios_hostname - hostname resource module +- ios_hostname - Resource module to configure hostname. v2.6.0 ====== @@ -702,7 +717,7 @@ Documentation Changes New Modules ----------- -- ios_snmp_server - snmp_server resource module +- ios_snmp_server - Resource module to configure snmp server. v2.5.0 ====== @@ -735,7 +750,7 @@ Documentation Changes New Modules ----------- -- ios_ntp_global - ntp_global resource module +- ios_ntp_global - Resource module to configure NTP. v2.4.0 ====== @@ -822,8 +837,8 @@ Bugfixes New Modules ----------- -- ios_logging_global - Logging resource module. -- ios_prefix_lists - Prefix Lists resource module. +- ios_logging_global - Resource module to configure logging. +- ios_prefix_lists - Resource module to configure prefix lists. v2.1.0 ====== @@ -847,7 +862,7 @@ Bugfixes New Modules ----------- -- ios_route_maps - Route Maps resource module. +- ios_route_maps - Resource module to configure route maps. v2.0.1 ====== @@ -892,7 +907,7 @@ Bugfixes New Modules ----------- -- ios_bgp_address_family - BGP Address Family resource module. +- ios_bgp_address_family - Resource module to configure BGP Address family. v1.3.0 ====== @@ -915,7 +930,7 @@ Bugfixes New Modules ----------- -- ios_bgp_global - BGP Global resource module +- ios_bgp_global - Resource module to configure BGP. v1.2.1 ====== @@ -946,7 +961,7 @@ Bugfixes New Modules ----------- -- ios_ospf_interfaces - OSPF Interfaces resource module +- ios_ospf_interfaces - Resource module to configure OSPF interfaces. v1.1.0 ====== @@ -967,7 +982,7 @@ Bugfixes New Modules ----------- -- ios_ospfv3 - OSPFv3 resource module +- ios_ospfv3 - Resource module to configure OSPFv3. v1.0.3 ====== @@ -1019,34 +1034,26 @@ Cliconf New Modules ----------- -- ios_acl_interfaces - ACL interfaces resource module -- ios_acls - ACLs resource module -- ios_banner - Manage multiline banners on Cisco IOS devices -- ios_bgp - Configure global BGP protocol settings on Cisco IOS. -- ios_command - Run commands on remote devices running Cisco IOS -- ios_config - Manage Cisco IOS configuration sections -- ios_facts - Collect facts from remote devices running Cisco IOS -- ios_interface - (deprecated, removed after 2022-06-01) Manage Interface on Cisco IOS network devices -- ios_interfaces - Interfaces resource module -- ios_l2_interface - (deprecated, removed after 2022-06-01) Manage Layer-2 interface on Cisco IOS devices. -- ios_l2_interfaces - L2 interfaces resource module -- ios_l3_interface - (deprecated, removed after 2022-06-01) Manage Layer-3 interfaces on Cisco IOS network devices. -- ios_l3_interfaces - L3 interfaces resource module -- ios_lacp - LACP resource module -- ios_lacp_interfaces - LACP interfaces resource module -- ios_lag_interfaces - LAG interfaces resource module -- ios_linkagg - Manage link aggregation groups on Cisco IOS network devices -- ios_lldp - Manage LLDP configuration on Cisco IOS network devices. -- ios_lldp_global - LLDP resource module -- ios_lldp_interfaces - LLDP interfaces resource module -- ios_logging - Manage logging on network devices -- ios_ntp - Manages core NTP configuration. -- ios_ospfv2 - OSPFv2 resource module -- ios_ping - Tests reachability using ping from Cisco IOS network devices -- ios_static_route - (deprecated, removed after 2022-06-01) Manage static IP routes on Cisco IOS network devices -- ios_static_routes - Static routes resource module -- ios_system - Manage the system attributes on Cisco IOS devices -- ios_user - Manage the aggregate of local users on Cisco IOS device -- ios_vlan - (deprecated, removed after 2022-06-01) Manage VLANs on IOS network devices -- ios_vlans - VLANs resource module -- ios_vrf - Manage the collection of VRF definitions on Cisco IOS devices +- ios_acl_interfaces - Resource module to configure ACL interfaces. +- ios_acls - Resource module to configure ACLs. +- ios_banner - Module to configure multiline banners. +- ios_command - Module to run commands on remote devices. +- ios_config - Module to manage configuration sections. +- ios_facts - Module to collect facts from remote devices. +- ios_interfaces - Resource module to configure interfaces. +- ios_l2_interfaces - Resource module to configure L2 interfaces. +- ios_l3_interfaces - Resource module to configure L3 interfaces. +- ios_lacp - Resource module to configure LACP. +- ios_lacp_interfaces - Resource module to configure LACP interfaces. +- ios_lag_interfaces - Resource module to configure LAG interfaces. +- ios_linkagg - Module to configure link aggregation groups. +- ios_lldp - (deprecated, removed after 2024-06-01) Manage LLDP configuration on Cisco IOS network devices. +- ios_lldp_global - Resource module to configure LLDP. +- ios_lldp_interfaces - Resource module to configure LLDP interfaces. +- ios_ospfv2 - Resource module to configure OSPFv2. +- ios_ping - Tests reachability using ping from IOS switch. +- ios_static_routes - Resource module to configure static routes. +- ios_system - Module to manage the system attributes. +- ios_user - Module to manage the aggregates of local users. +- ios_vlans - Resource module to configure VLANs. +- ios_vrf - Module to configure VRF definitions. diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 4df6f0452..e57571cd7 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -2,107 +2,75 @@ ancestor: null releases: 1.0.0: modules: - - description: ACL interfaces resource module + - description: Resource module to configure ACL interfaces. name: ios_acl_interfaces namespace: "" - - description: ACLs resource module + - description: Resource module to configure ACLs. name: ios_acls namespace: "" - - description: Manage multiline banners on Cisco IOS devices + - description: Module to configure multiline banners. name: ios_banner namespace: "" - - description: Configure global BGP protocol settings on Cisco IOS. - name: ios_bgp - namespace: "" - - description: Run commands on remote devices running Cisco IOS + - description: Module to run commands on remote devices. name: ios_command namespace: "" - - description: Manage Cisco IOS configuration sections + - description: Module to manage configuration sections. name: ios_config namespace: "" - - description: Collect facts from remote devices running Cisco IOS + - description: Module to collect facts from remote devices. name: ios_facts namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manage Interface on Cisco - IOS network devices - name: ios_interface - namespace: "" - - description: Interfaces resource module + - description: Resource module to configure interfaces. name: ios_interfaces namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manage Layer-2 interface - on Cisco IOS devices. - name: ios_l2_interface - namespace: "" - - description: L2 interfaces resource module + - description: Resource module to configure L2 interfaces. name: ios_l2_interfaces namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manage Layer-3 interfaces - on Cisco IOS network devices. - name: ios_l3_interface - namespace: "" - - description: L3 interfaces resource module + - description: Resource module to configure L3 interfaces. name: ios_l3_interfaces namespace: "" - - description: LACP resource module + - description: Resource module to configure LACP. name: ios_lacp namespace: "" - - description: LACP interfaces resource module + - description: Resource module to configure LACP interfaces. name: ios_lacp_interfaces namespace: "" - - description: LAG interfaces resource module + - description: Resource module to configure LAG interfaces. name: ios_lag_interfaces namespace: "" - - description: Manage link aggregation groups on Cisco IOS network devices + - description: Module to configure link aggregation groups. name: ios_linkagg namespace: "" - - description: Manage LLDP configuration on Cisco IOS network devices. + - description: + (deprecated, removed after 2024-06-01) Manage LLDP configuration + on Cisco IOS network devices. name: ios_lldp namespace: "" - - description: LLDP resource module + - description: Resource module to configure LLDP. name: ios_lldp_global namespace: "" - - description: LLDP interfaces resource module + - description: Resource module to configure LLDP interfaces. name: ios_lldp_interfaces namespace: "" - - description: Manage logging on network devices - name: ios_logging - namespace: "" - - description: Manages core NTP configuration. - name: ios_ntp - namespace: "" - - description: OSPFv2 resource module + - description: Resource module to configure OSPFv2. name: ios_ospfv2 namespace: "" - - description: Tests reachability using ping from Cisco IOS network devices + - description: Tests reachability using ping from IOS switch. name: ios_ping namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manage static IP routes - on Cisco IOS network devices - name: ios_static_route - namespace: "" - - description: Static routes resource module + - description: Resource module to configure static routes. name: ios_static_routes namespace: "" - - description: Manage the system attributes on Cisco IOS devices + - description: Module to manage the system attributes. name: ios_system namespace: "" - - description: Manage the aggregate of local users on Cisco IOS device + - description: Module to manage the aggregates of local users. name: ios_user namespace: "" - - description: - (deprecated, removed after 2022-06-01) Manage VLANs on IOS network - devices - name: ios_vlan - namespace: "" - - description: VLANs resource module + - description: Resource module to configure VLANs. name: ios_vlans namespace: "" - - description: Manage the collection of VRF definitions on Cisco IOS devices + - description: Module to configure VRF definitions. name: ios_vrf namespace: "" plugins: @@ -153,7 +121,7 @@ releases: minor_changes: - Add ios_ospfv3 module. modules: - - description: OSPFv3 resource module + - description: Resource module to configure OSPFv3. name: ios_ospfv3 namespace: "" release_date: "2020-10-01" @@ -172,7 +140,7 @@ releases: minor_changes: - Add ios_ospf_interfaces module. modules: - - description: OSPF Interfaces resource module + - description: Resource module to configure OSPF interfaces. name: ios_ospf_interfaces namespace: "" release_date: "2020-11-01" @@ -196,7 +164,7 @@ releases: minor_changes: - Add ios_bgp_global module. modules: - - description: BGP Global resource module + - description: Resource module to configure BGP. name: ios_bgp_global namespace: "" release_date: "2021-01-29" @@ -214,7 +182,7 @@ releases: - Add ios_bgp_address_family Resource Module. (https://github.com/ansible-collections/cisco.ios/pull/219). - Adds support for single_user_mode command output caching. (https://github.com/ansible-collections/cisco.ios/pull/204). modules: - - description: BGP Address Family resource module. + - description: Resource module to configure BGP Address family. name: ios_bgp_address_family namespace: "" release_date: "2021-02-25" @@ -246,7 +214,7 @@ releases: security_fixes: - To fix Cisco IOS no log issue and add ignore txt for 2.12 (https://github.com/ansible-collections/cisco.ios/pull/304). modules: - - description: Route Maps resource module. + - description: Resource module to configure route maps. name: ios_route_maps namespace: "" release_date: "2021-04-27" @@ -265,10 +233,10 @@ releases: - Add ios_logging_global module. - IOS Prefix list resource module. modules: - - description: Logging resource module. + - description: Resource module to configure logging. name: ios_logging_global namespace: "" - - description: Prefix Lists resource module. + - description: Resource module to configure prefix lists. name: ios_prefix_lists namespace: "" release_date: "2021-05-18" @@ -377,7 +345,7 @@ releases: - sd_wan_support.yaml - set_allow_duplicates.yaml modules: - - description: ntp_global resource module + - description: Resource module to configure NTP. name: ios_ntp_global namespace: "" release_date: "2021-09-24" @@ -409,7 +377,7 @@ releases: - sanity-213.yaml - snmp_server_resource_module.yaml modules: - - description: snmp_server resource module + - description: Resource module to configure snmp server. name: ios_snmp_server namespace: "" release_date: "2021-12-07" @@ -452,7 +420,7 @@ releases: - snmp_server_feature_user.yaml - static_route_interface_issue.yaml modules: - - description: hostname resource module + - description: Resource module to configure hostname. name: ios_hostname namespace: "" release_date: "2022-01-31" @@ -1180,3 +1148,15 @@ releases: fragments: - remove_deprecated.yml release_date: "2024-04-01" + 8.0.0: + changes: + major_changes: + - Update the netcommon base version 6.1.0 to support cli_restore plugin. + minor_changes: + - Add support for cli_restore functionality. + - Please refer the PR to know more about core changes (https://github.com/ansible-collections/ansible.netcommon/pull/618). + - cli_restore module is part of netcommon. + fragments: + - add_restore_support.yaml + - sanityfix.yml + release_date: "2024-04-12" diff --git a/changelogs/fragments/add_restore_support.yaml b/changelogs/fragments/add_restore_support.yaml deleted file mode 100644 index ff161ac71..000000000 --- a/changelogs/fragments/add_restore_support.yaml +++ /dev/null @@ -1,6 +0,0 @@ -major_changes: - - Update the netcommon base version 6.1.0 to support cli_restore plugin. -minor_changes: - - Add support for cli_restore functionality. - - cli_restore module is part of netcommon. - - Please refer the PR to know more about core changes (https://github.com/ansible-collections/ansible.netcommon/pull/618). diff --git a/changelogs/fragments/sanityfix.yml b/changelogs/fragments/sanityfix.yml deleted file mode 100644 index c1cc85eb0..000000000 --- a/changelogs/fragments/sanityfix.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -trivial: - - Add ignore-2.18.txt - - Add build-import workflow diff --git a/galaxy.yml b/galaxy.yml index 734a21040..22c3d2613 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -2,7 +2,7 @@ authors: - Ansible Network Community (ansible-network) dependencies: - "ansible.netcommon": ">=6.0.0" + "ansible.netcommon": ">=6.1.0" license_file: LICENSE name: ios namespace: cisco @@ -11,4 +11,4 @@ readme: README.md repository: https://github.com/ansible-collections/cisco.ios issues: https://github.com/ansible-collections/cisco.ios/issues tags: [cisco, ios, iosxe, networking] -version: "7.0.0" +version: "8.0.0" From 0c5ee86c86782f3a29d7bd7e930b03f9dee81ec2 Mon Sep 17 00:00:00 2001 From: Vinay M <63404819+roverflow@users.noreply.github.com> Date: Thu, 2 May 2024 10:03:30 +0530 Subject: [PATCH 03/10] l3_interfaces - Fix gathering wrong facts for source interface in ipv4. (#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> --- changelogs/fragments/l3_sinterface_parser.yml | 3 ++ .../network/ios/rm_templates/l3_interfaces.py | 4 +-- .../network/ios/test_ios_l3_interfaces.py | 29 ++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/l3_sinterface_parser.yml diff --git a/changelogs/fragments/l3_sinterface_parser.yml b/changelogs/fragments/l3_sinterface_parser.yml new file mode 100644 index 000000000..c16a5e179 --- /dev/null +++ b/changelogs/fragments/l3_sinterface_parser.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - ios_l3_interfaces - Fix gathering wrong facts for source interface in ipv4. diff --git a/plugins/module_utils/network/ios/rm_templates/l3_interfaces.py b/plugins/module_utils/network/ios/rm_templates/l3_interfaces.py index bd337befa..f049d061b 100644 --- a/plugins/module_utils/network/ios/rm_templates/l3_interfaces.py +++ b/plugins/module_utils/network/ios/rm_templates/l3_interfaces.py @@ -166,7 +166,7 @@ def __init__(self, lines=None, module=None): "name": "ipv4.source_interface", "getval": re.compile( r"""\s+ip\sunnumbered - (\s(?P\S+)) + (\s(?P\S+)) (\s(?Ppoll))? (\s(?Ppoint-to-point))? $""", @@ -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 }}", }, diff --git a/tests/unit/modules/network/ios/test_ios_l3_interfaces.py b/tests/unit/modules/network/ios/test_ios_l3_interfaces.py index 3e3cc038b..f0d593afa 100644 --- a/tests/unit/modules/network/ios/test_ios_l3_interfaces.py +++ b/tests/unit/modules/network/ios/test_ios_l3_interfaces.py @@ -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)) @@ -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) From 39af3bcf077a04488bae0b4ef0c55da01315d1bb Mon Sep 17 00:00:00 2001 From: Vinay M <63404819+roverflow@users.noreply.github.com> Date: Mon, 6 May 2024 12:15:01 +0100 Subject: [PATCH 04/10] Fix Integration tests (#1060) * Fix Integtaion tests * remove only loopback in lacp * add back the purge in lacp * Added false condition for l2 appliance tests * Add false condition for evpn tests * vlans intergation test condition * fix evpn_global intergration test issues * skip vxlan_vtep l2 tests * Fix l3 interface test issuesss * fix lacp int test issue * fix test * vxlan fix * evpn global * bgp address family fix * lint fix * Remove vlans * Remove debug statement --- .../ios_bgp_address_family/tasks/main.yaml | 4 +++ .../tests/cli/merged.yaml | 33 ++++++++++--------- .../ios_bgp_address_family/vars/main.yaml | 14 ++++---- .../targets/ios_evpn_evi/tasks/cli.yaml | 1 + .../targets/ios_evpn_evi/tasks/main.yaml | 4 +++ .../targets/ios_evpn_global/tasks/cli.yaml | 1 + .../targets/ios_evpn_global/tasks/main.yaml | 4 +++ .../ios_evpn_global/tests/cli/deleted.yaml | 1 + .../ios_evpn_global/tests/cli/merged.yaml | 1 + .../ios_evpn_global/tests/cli/replaced.yaml | 1 + .../ios_facts/tests/cli/all_facts.yaml | 5 +-- .../tests/cli/_remove_config.yaml | 1 + .../tests/cli/_remove_config.yaml | 10 ++++++ .../ios_l3_interfaces/tests/cli/merged.yaml | 6 ++-- .../targets/ios_l3_interfaces/vars/main.yaml | 9 ++--- .../tests/cli/_remove_config.yaml | 1 + .../tests/cli/_remove_config.yaml | 1 + .../targets/ios_vlans/tasks/cli.yaml | 6 +++- .../targets/ios_vlans/tasks/main.yaml | 4 +++ .../tests/cli/deleted_vlan_config.yaml | 1 + .../tests/cli/merged_vlan_config.yaml | 1 + .../tests/cli/overridden_vlan_config.yaml | 1 + .../targets/ios_vlans/tests/cli/rendered.yaml | 5 +-- .../targets/ios_vlans/vars/main.yaml | 4 +-- .../targets/ios_vxlan_vtep/tasks/cli.yaml | 1 + .../targets/ios_vxlan_vtep/tasks/main.yaml | 4 +++ 26 files changed, 86 insertions(+), 38 deletions(-) diff --git a/tests/integration/targets/ios_bgp_address_family/tasks/main.yaml b/tests/integration/targets/ios_bgp_address_family/tasks/main.yaml index 8b66c1ad5..6b04c2ccc 100644 --- a/tests/integration/targets/ios_bgp_address_family/tasks/main.yaml +++ b/tests/integration/targets/ios_bgp_address_family/tasks/main.yaml @@ -1,4 +1,8 @@ --- +- name: Set a fact for 'skip_test' + ansible.builtin.set_fact: + skip_test: false + - name: Main task for bgp_address_family module ansible.builtin.include_tasks: cli.yaml tags: diff --git a/tests/integration/targets/ios_bgp_address_family/tests/cli/merged.yaml b/tests/integration/targets/ios_bgp_address_family/tests/cli/merged.yaml index 81aa0512d..e0d2a452c 100644 --- a/tests/integration/targets/ios_bgp_address_family/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_bgp_address_family/tests/cli/merged.yaml @@ -11,22 +11,23 @@ cisco.ios.ios_bgp_address_family: &id001 config: address_family: - - afi: l2vpn - safi: evpn - neighbor: - - address: 198.51.100.1 - activate: true - inherit: LEAF-EVPN-PEER-POLICY - - afi: ipv4 - vrf: green - redistribute: - - static: - set: true - - connected: - set: true - advertise: - afi: l2vpn - safi: evpn + # L2 specific configuration + # - afi: l2vpn + # safi: evpn + # neighbor: + # - address: 198.51.100.1 + # activate: true + # inherit: LEAF-EVPN-PEER-POLICY + # - afi: ipv4 + # vrf: green + # redistribute: + # - static: + # set: true + # - connected: + # set: true + # advertise: + # afi: l2vpn + # safi: evpn - afi: ipv4 redistribute: - connected: diff --git a/tests/integration/targets/ios_bgp_address_family/vars/main.yaml b/tests/integration/targets/ios_bgp_address_family/vars/main.yaml index e22a90dc0..9198405ac 100644 --- a/tests/integration/targets/ios_bgp_address_family/vars/main.yaml +++ b/tests/integration/targets/ios_bgp_address_family/vars/main.yaml @@ -4,13 +4,13 @@ merged: commands: - router bgp 65000 - - address-family l2vpn evpn - - neighbor 198.51.100.1 activate - - neighbor 198.51.100.1 inherit peer-policy LEAF-EVPN-PEER-POLICY - - address-family ipv4 vrf green - - advertise l2vpn evpn - - redistribute connected - - redistribute static + # - address-family l2vpn evpn + # - neighbor 198.51.100.1 activate + # - neighbor 198.51.100.1 inherit peer-policy LEAF-EVPN-PEER-POLICY + # - address-family ipv4 vrf green + # - advertise l2vpn evpn + # - redistribute connected + # - redistribute static - address-family ipv4 multicast - default-metric 12 - distance bgp 10 10 100 diff --git a/tests/integration/targets/ios_evpn_evi/tasks/cli.yaml b/tests/integration/targets/ios_evpn_evi/tasks/cli.yaml index 6f505600c..843294310 100644 --- a/tests/integration/targets/ios_evpn_evi/tasks/cli.yaml +++ b/tests/integration/targets/ios_evpn_evi/tasks/cli.yaml @@ -13,6 +13,7 @@ delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) + when: skip_test ansible.builtin.include_tasks: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/ios_evpn_evi/tasks/main.yaml b/tests/integration/targets/ios_evpn_evi/tasks/main.yaml index 39c4567e9..ccf906bc5 100644 --- a/tests/integration/targets/ios_evpn_evi/tasks/main.yaml +++ b/tests/integration/targets/ios_evpn_evi/tasks/main.yaml @@ -1,4 +1,8 @@ --- +- name: Set a fact for 'skip_test' + ansible.builtin.set_fact: + skip_test: false + - name: Main task for EVPN EVI module ansible.builtin.include_tasks: cli.yaml tags: diff --git a/tests/integration/targets/ios_evpn_global/tasks/cli.yaml b/tests/integration/targets/ios_evpn_global/tasks/cli.yaml index 6f505600c..843294310 100644 --- a/tests/integration/targets/ios_evpn_global/tasks/cli.yaml +++ b/tests/integration/targets/ios_evpn_global/tasks/cli.yaml @@ -13,6 +13,7 @@ delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) + when: skip_test ansible.builtin.include_tasks: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/ios_evpn_global/tasks/main.yaml b/tests/integration/targets/ios_evpn_global/tasks/main.yaml index 83b543a3f..601063522 100644 --- a/tests/integration/targets/ios_evpn_global/tasks/main.yaml +++ b/tests/integration/targets/ios_evpn_global/tasks/main.yaml @@ -1,4 +1,8 @@ --- +- name: Set a fact for 'skip_test' + ansible.builtin.set_fact: + skip_test: false + - name: Main task for evpn_global module ansible.builtin.include_tasks: cli.yaml tags: diff --git a/tests/integration/targets/ios_evpn_global/tests/cli/deleted.yaml b/tests/integration/targets/ios_evpn_global/tests/cli/deleted.yaml index 6ed823307..05320aa1f 100644 --- a/tests/integration/targets/ios_evpn_global/tests/cli/deleted.yaml +++ b/tests/integration/targets/ios_evpn_global/tests/cli/deleted.yaml @@ -30,6 +30,7 @@ - name: Ios_evpn_global deleted - play (idempotent) register: result cisco.ios.ios_evpn_global: *id001 + - name: Ios_evpn_global deleted - assert above task was idempotent ansible.builtin.assert: that: diff --git a/tests/integration/targets/ios_evpn_global/tests/cli/merged.yaml b/tests/integration/targets/ios_evpn_global/tests/cli/merged.yaml index 485c85778..7ee2196d7 100644 --- a/tests/integration/targets/ios_evpn_global/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_evpn_global/tests/cli/merged.yaml @@ -42,6 +42,7 @@ - name: Ios_evpn_global merged - play (idempotent) register: result cisco.ios.ios_evpn_global: *id001 + - name: Ios_evpn_global merged - assert above task was idempotent ansible.builtin.assert: that: diff --git a/tests/integration/targets/ios_evpn_global/tests/cli/replaced.yaml b/tests/integration/targets/ios_evpn_global/tests/cli/replaced.yaml index 47a9bb62f..48d230d37 100644 --- a/tests/integration/targets/ios_evpn_global/tests/cli/replaced.yaml +++ b/tests/integration/targets/ios_evpn_global/tests/cli/replaced.yaml @@ -37,6 +37,7 @@ - name: Ios_evpn_global replaced - play (idempotent) register: result cisco.ios.ios_evpn_global: *id001 + - name: Ios_evpn_global replaced - assert above task was idempotent ansible.builtin.assert: that: diff --git a/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml b/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml index 44d57ed9b..e01263fe4 100644 --- a/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml +++ b/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml @@ -19,8 +19,9 @@ - result.ansible_facts.ansible_net_memfree_mb > 1 - result.ansible_facts.ansible_net_memtotal_mb > 1 -- ansible.builtin.assert: - that: "{{ my_var.value.spacetotal_kb }} > {{ my_var.value.spacefree_kb }}" +- name: Assert that free spacee is less than total space + ansible.builtin.assert: + that: "my_var.value.spacetotal_kb > my_var.value.spacefree_kb" loop: "{{ lookup('dict', result.ansible_facts.ansible_net_filesystems_info, wantlist=True) }}" loop_control: loop_var: my_var diff --git a/tests/integration/targets/ios_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/ios_interfaces/tests/cli/_remove_config.yaml index a3f5b0a44..6225d4a84 100644 --- a/tests/integration/targets/ios_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/ios_interfaces/tests/cli/_remove_config.yaml @@ -15,4 +15,5 @@ - name: Port-channel11 - name: Port-channel22 - name: Port-channel40 + - name: Loopback1 state: purged diff --git a/tests/integration/targets/ios_l3_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/ios_l3_interfaces/tests/cli/_remove_config.yaml index 554173b64..56083c1b5 100644 --- a/tests/integration/targets/ios_l3_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/ios_l3_interfaces/tests/cli/_remove_config.yaml @@ -6,3 +6,13 @@ \ ipv6 address\n" ansible.netcommon.cli_config: config: "{{ lines }}" + +- name: Delete attributes of all configured interfaces + register: result + cisco.ios.ios_interfaces: + config: + - name: Loopback1 + - name: Vlan101 + - name: Vlan901 + - name: Vlan902 + state: purged diff --git a/tests/integration/targets/ios_l3_interfaces/tests/cli/merged.yaml b/tests/integration/targets/ios_l3_interfaces/tests/cli/merged.yaml index 75217f5e5..8169e8584 100644 --- a/tests/integration/targets/ios_l3_interfaces/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_l3_interfaces/tests/cli/merged.yaml @@ -23,10 +23,6 @@ - address: 198.51.100.2/24 ipv6: - address: 2001:db8:0:3::/64 - - name: Vlan101 - ipv4: - - address: 198.51.100.2/24 - mac_address: dead:beef:abcd - name: Vlan901 autostate: false ipv4: @@ -38,6 +34,8 @@ autostate: true ipv6: - enable: true + - name: Vlan101 + autostate: false state: merged - name: L3_interface merged - assert that correct set of commands were generated diff --git a/tests/integration/targets/ios_l3_interfaces/vars/main.yaml b/tests/integration/targets/ios_l3_interfaces/vars/main.yaml index 73996896e..1d869bf08 100644 --- a/tests/integration/targets/ios_l3_interfaces/vars/main.yaml +++ b/tests/integration/targets/ios_l3_interfaces/vars/main.yaml @@ -25,6 +25,8 @@ merged: - ipv6 enable - interface Vlan902 - ipv6 enable + - interface Vlan101 + - no autostate after: - name: Loopback888 - ipv4: @@ -46,10 +48,7 @@ merged: - address: 2001:DB8:0:3::/64 name: GigabitEthernet3 - name: GigabitEthernet4 - - name: Vlan101 - ipv4: - - address: 198.51.100.2/24 - mac_address: dead:beef:abcd + - name: Loopback1 - name: Vlan901 ipv4: - source_interface: @@ -61,6 +60,8 @@ merged: ipv6: - enable: true autostate: true + - name: Vlan101 + autostate: false replaced: before: diff --git a/tests/integration/targets/ios_lacp_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/ios_lacp_interfaces/tests/cli/_remove_config.yaml index 8544171de..df035f588 100644 --- a/tests/integration/targets/ios_lacp_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/ios_lacp_interfaces/tests/cli/_remove_config.yaml @@ -12,6 +12,7 @@ register: result cisco.ios.ios_interfaces: config: + - name: Loopback1 - name: Port-channel10 - name: Port-channel11 - name: Port-channel22 diff --git a/tests/integration/targets/ios_ospf_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/ios_ospf_interfaces/tests/cli/_remove_config.yaml index 2979674f4..3e45f6a9a 100644 --- a/tests/integration/targets/ios_ospf_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/ios_ospf_interfaces/tests/cli/_remove_config.yaml @@ -13,6 +13,7 @@ register: result cisco.ios.ios_interfaces: config: + - name: Loopback1 - name: Port-channel10 - name: Port-channel11 - name: Port-channel22 diff --git a/tests/integration/targets/ios_vlans/tasks/cli.yaml b/tests/integration/targets/ios_vlans/tasks/cli.yaml index 25c50045a..37e561a6b 100644 --- a/tests/integration/targets/ios_vlans/tasks/cli.yaml +++ b/tests/integration/targets/ios_vlans/tasks/cli.yaml @@ -16,10 +16,14 @@ cisco.ios.ios_facts: gather_subset: all +- name: Set filtered paths to run only non l2 tests + ansible.builtin.set_fact: + filtered_file_paths: "{{ test_items | reject('search', 'vlan_config') | list }}" + - name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli - with_items: "{{ test_items }}" + with_items: "{{ filtered_file_paths }}" loop_control: loop_var: test_case_to_run diff --git a/tests/integration/targets/ios_vlans/tasks/main.yaml b/tests/integration/targets/ios_vlans/tasks/main.yaml index 0bf380edb..e741ecb68 100644 --- a/tests/integration/targets/ios_vlans/tasks/main.yaml +++ b/tests/integration/targets/ios_vlans/tasks/main.yaml @@ -1,4 +1,8 @@ --- +- name: Set a fact for 'skip_test' + ansible.builtin.set_fact: + skip_test: false + - name: Main task for vlans module ansible.builtin.include_tasks: cli.yaml tags: diff --git a/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml index ae7215669..2bc9234a9 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml @@ -30,6 +30,7 @@ - name: Delete vlans attributes for all configured vlans (idempotent) register: result cisco.ios.ios_vlans: *id001 + - name: Assert that the previous task was idempotent ansible.builtin.assert: that: diff --git a/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml index 5af123bcd..68674c3e3 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml @@ -37,6 +37,7 @@ - name: Merge provided configuration with device configuration (idempotent) register: result cisco.ios.ios_vlans: *id001 + - name: Assert that the previous task was idempotent ansible.builtin.assert: that: diff --git a/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml index a739c6117..146c03572 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml @@ -39,6 +39,7 @@ - name: Override device configuration of all interfaces with provided configuration (idempotent) register: result cisco.ios.ios_vlans: *id001 + - name: Assert that task was idempotent ansible.builtin.assert: that: diff --git a/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml b/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml index 38b0304c8..43fcd910c 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml @@ -24,8 +24,9 @@ shutdown: enabled state: rendered - - ansible.builtin.assert: + - name: Assert that correct set of commands were generated + ansible.builtin.assert: that: - result.changed == false - - result.rendered|symmetric_difference(rendered.commands) == [] + - "{{ rendered['commands'] | symmetric_difference(result['rendered']) | length == 0 }}" when: ansible_net_version != "15.6(2)T" diff --git a/tests/integration/targets/ios_vlans/vars/main.yaml b/tests/integration/targets/ios_vlans/vars/main.yaml index 6092684a9..4160dee6f 100644 --- a/tests/integration/targets/ios_vlans/vars/main.yaml +++ b/tests/integration/targets/ios_vlans/vars/main.yaml @@ -573,11 +573,11 @@ rendered: - name Vlan_20 - state active - mtu 610 - - shutdown + - no shutdown - vlan 30 - name Vlan_30 - state suspend - - shutdown + - no shutdown rendered_vlan_config: commands: diff --git a/tests/integration/targets/ios_vxlan_vtep/tasks/cli.yaml b/tests/integration/targets/ios_vxlan_vtep/tasks/cli.yaml index 6f505600c..843294310 100644 --- a/tests/integration/targets/ios_vxlan_vtep/tasks/cli.yaml +++ b/tests/integration/targets/ios_vxlan_vtep/tasks/cli.yaml @@ -13,6 +13,7 @@ delegate_to: localhost - name: Run test case (connection=ansible.netcommon.network_cli) + when: skip_test ansible.builtin.include_tasks: "{{ test_case_to_run }}" vars: ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/ios_vxlan_vtep/tasks/main.yaml b/tests/integration/targets/ios_vxlan_vtep/tasks/main.yaml index d80ee1ae2..a19087c8d 100644 --- a/tests/integration/targets/ios_vxlan_vtep/tasks/main.yaml +++ b/tests/integration/targets/ios_vxlan_vtep/tasks/main.yaml @@ -1,4 +1,8 @@ --- +- name: Set a fact for 'skip_test' + ansible.builtin.set_fact: + skip_test: false + - name: Main task for VXLAN VTEP module ansible.builtin.include_tasks: cli.yaml tags: From e700001b49fd17317f27d15d0b523204cd9474c0 Mon Sep 17 00:00:00 2001 From: Sagar Paul Date: Mon, 13 May 2024 15:26:30 +0530 Subject: [PATCH 05/10] fix ios_service issues (#1068) * fix ios_service issues * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clean debug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Confirm changes * [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> --- changelogs/fragments/ios_service_fix.yml | 4 + docs/cisco.ios.ios_service_module.rst | 61 +++++- .../network/ios/argspec/service/service.py | 6 +- .../network/ios/config/service/service.py | 6 +- .../network/ios/facts/service/service.py | 8 +- .../network/ios/rm_templates/service.py | 178 ++++++++++++------ plugins/modules/ios_service.py | 25 ++- .../modules/network/ios/test_ios_service.py | 45 ++--- 8 files changed, 234 insertions(+), 99 deletions(-) create mode 100644 changelogs/fragments/ios_service_fix.yml diff --git a/changelogs/fragments/ios_service_fix.yml b/changelogs/fragments/ios_service_fix.yml new file mode 100644 index 000000000..3ec24d6a9 --- /dev/null +++ b/changelogs/fragments/ios_service_fix.yml @@ -0,0 +1,4 @@ +--- +bugfixes: + - ios_service - Fix timestamps attribute, to generate right configuration. + - ios_service - Add tcp_small_servers and udp_small_servers attributes, to generate configuration. diff --git a/docs/cisco.ios.ios_service_module.rst b/docs/cisco.ios.ios_service_module.rst index ed859129d..a2d5eef38 100644 --- a/docs/cisco.ios.ios_service_module.rst +++ b/docs/cisco.ios.ios_service_module.rst @@ -45,7 +45,7 @@ Parameters -
A dictionnary of service configuration
+
A dictionary of service configuration
@@ -658,7 +658,7 @@ Parameters -
TCP and UDP small servers are servers (daemons, in Unix parlance) that run in the router which are useful for diagnostics.
+
TCP small servers are servers (daemons, in Unix parlance) that run in the router which are useful for diagnostics.
@@ -690,14 +690,35 @@ Parameters max_servers
- string + integer
Set number of allowable TCP small servers
-
1 to 2147483647 or no-limit
+
1 to 2147483647
+ + + + + + +
+ no_limit + +
+ boolean +
+ + +
    Choices: +
  • no
  • +
  • yes
  • +
+ + +
No limit on number of allowable TCP small servers
@@ -921,7 +942,7 @@ Parameters -
TCP and UDP small servers are servers (daemons, in Unix parlance) that run in the router which are useful for diagnostics.
+
UDP small servers are servers (daemons, in Unix parlance) that run in the router which are useful for diagnostics.
@@ -953,14 +974,35 @@ Parameters max_servers
- string + integer
-
Set number of allowable TCP small servers
-
1 to 2147483647 or no-limit
+
Set number of allowable UDP small servers
+
1 to 2147483647
+ + + + + + +
+ no_limit + +
+ boolean +
+ + +
    Choices: +
  • no
  • +
  • yes
  • +
+ + +
No limit on number of allowable UDP small servers
@@ -1036,7 +1078,7 @@ Notes ----- .. note:: - - Tested against Cisco IOSXE Version 16.9 + - Tested against Cisco IOSXE Version 17.9.1a on CML. - This module works with connection ``network_cli``. See https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html @@ -1556,3 +1598,4 @@ Authors ~~~~~~~ - Ambroise Rosset (@earendilfr) +- Sagar Paul (@KB-perByte) diff --git a/plugins/module_utils/network/ios/argspec/service/service.py b/plugins/module_utils/network/ios/argspec/service/service.py index 238fc64a2..647eeb3d2 100644 --- a/plugins/module_utils/network/ios/argspec/service/service.py +++ b/plugins/module_utils/network/ios/argspec/service/service.py @@ -68,7 +68,8 @@ class ServiceArgs(object): # pylint: disable=R0903 "tcp_small_servers": { "options": { "enable": {"type": "bool"}, - "max_servers": {"type": "str"}, + "max_servers": {"type": "int"}, + "no_limit": {"type": "bool"}, }, "type": "dict", }, @@ -97,7 +98,8 @@ class ServiceArgs(object): # pylint: disable=R0903 "udp_small_servers": { "options": { "enable": {"type": "bool"}, - "max_servers": {"type": "str"}, + "max_servers": {"type": "int"}, + "no_limit": {"type": "bool"}, }, "type": "dict", }, diff --git a/plugins/module_utils/network/ios/config/service/service.py b/plugins/module_utils/network/ios/config/service/service.py index 6a4c8a1ff..603e1060b 100644 --- a/plugins/module_utils/network/ios/config/service/service.py +++ b/plugins/module_utils/network/ios/config/service/service.py @@ -75,7 +75,9 @@ def __init__(self, module): "slave_log", "tcp_keepalives_in", "tcp_keepalives_out", + "tcp_small_servers", "telnet_zeroidle", + "udp_small_servers", "unsupported_transceiver", ] @@ -138,9 +140,9 @@ def _compare_lists_attrs(self, want, have): for key, wanting in iteritems(i_want): haveing = i_have.pop(key, {}) if wanting != haveing: - self.addcmd(wanting, "timestamps") + self.addcmd(wanting, key + "_timestamps", False) for key, haveing in iteritems(i_have): - self.addcmd(haveing, "timestamps", negate=True) + self.addcmd(haveing, key + "_timestamps", negate=True) def _service_list_to_dict(self, data): """Convert all list of dicts to dicts of dicts""" diff --git a/plugins/module_utils/network/ios/facts/service/service.py b/plugins/module_utils/network/ios/facts/service/service.py index df2dcf993..6ada10748 100644 --- a/plugins/module_utils/network/ios/facts/service/service.py +++ b/plugins/module_utils/network/ios/facts/service/service.py @@ -33,7 +33,7 @@ def __init__(self, module, subspec="config", options="options"): self.argument_spec = ServiceArgs.argument_spec def get_service_data(self, connection): - return connection.get("show running-config all | section ^service ") + return connection.get("show running-config all | section ^service") def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for Service network resource @@ -59,7 +59,11 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("service", None) params = utils.remove_empties( - service_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), + service_parser.validate_config( + self.argument_spec, + {"config": objs}, + redact=True, + ), ) facts["service"] = params.get("config", {}) diff --git a/plugins/module_utils/network/ios/rm_templates/service.py b/plugins/module_utils/network/ios/rm_templates/service.py index 992892db8..c81593226 100644 --- a/plugins/module_utils/network/ios/rm_templates/service.py +++ b/plugins/module_utils/network/ios/rm_templates/service.py @@ -22,6 +22,21 @@ ) +def handleTimestamp(config_data): + command = "service timestamps" + command += " " + config_data.get("msg") if config_data.get("msg") else "" + command += " " + config_data.get("timestamp") if config_data.get("timestamp") else "" + + if config_data.get("datetime_options"): + datetime_op = config_data.get("datetime_options") + command += " mesc" if datetime_op.get("msec") else "" + command += " localtime" if datetime_op.get("localtime") else "" + command += " show-timezone" if datetime_op.get("show_timezone") else "" + command += " year" if datetime_op.get("year") else "" + + return command + + class ServiceTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): super(ServiceTemplate, self).__init__(lines=lines, tmplt=self, module=module) @@ -32,36 +47,36 @@ def __init__(self, lines=None, module=None): "name": "call_home", "getval": re.compile( r""" - ^service\s(?Pcall-home) + ^service\scall-home """, re.VERBOSE, ), "setval": "service call-home", "result": { - "call_home": "{{ not not call_home }}", + "call_home": True, }, }, { "name": "compress_config", "getval": re.compile( r""" - ^service\s(?Pcompress-config) + ^service\scompress-config """, re.VERBOSE, ), "setval": "service compress-config", "result": { - "compress_config": "{{ not not compress_config }}", + "compress_config": True, }, }, { "name": "config", "getval": re.compile( r""" - ^service\s(?Pconfig) + ^service\sconfig """, re.VERBOSE, ), "setval": "service config", "result": { - "config": "{{ not not config }}", + "config": True, }, }, { @@ -92,120 +107,120 @@ def __init__(self, lines=None, module=None): "name": "disable_ip_fast_frag", "getval": re.compile( r""" - ^service\s(?Pdisable-ip-fast-frag) + ^service\sdisable-ip-fast-frag """, re.VERBOSE, ), "setval": "service disable-ip-fast-frag", "result": { - "disable_ip_fast_frag": "{{ not not disable_ip_fast_frag }}", + "disable_ip_fast_frag": True, }, }, { "name": "exec_callback", "getval": re.compile( r""" - ^service\s(?Pexec-callback) + ^service\sexec-callback """, re.VERBOSE, ), "setval": "service exec-callback", "result": { - "exec_callback": "{{ not not exec_callback }}", + "exec_callback": True, }, }, { "name": "exec_wait", "getval": re.compile( r""" - ^service\s(?Pexec-wait) + ^service\sexec-wait """, re.VERBOSE, ), "setval": "service exec-wait", "return": { - "exec_wait": "{{ not not exec_wait }}", + "exec_wait": True, }, }, { "name": "hide_telnet_addresses", "getval": re.compile( r""" - ^service\s(?Phide-telnet-addresses) + ^service\shide-telnet-addresses """, re.VERBOSE, ), "setval": "service hide-telnet-addresses", "result": { - "hide_telnet_addresses": "{{ not not hide_telnet_addresses }}", + "hide_telnet_addresses": True, }, }, { "name": "internal", "getval": re.compile( r""" - ^service\s(?Pinternal) + ^service\sinternal """, re.VERBOSE, ), "setval": "service internal", "result": { - "internal": "{{ not not internal }}", + "internal": True, }, }, { "name": "linenumber", "getval": re.compile( r""" - ^service\s(?Plinenumber) + ^service\slinenumber """, re.VERBOSE, ), "setval": "service linenumber", "result": { - "linenumber": "{{ not not linenumber }}", + "linenumber": True, }, }, { "name": "log", "getval": re.compile( r""" - ^service\slog(\s(?Pbacktrace))? + ^service\slog\sbacktrace? """, re.VERBOSE, ), "setval": "service log backtrace", "result": { - "log": "{{ not not backtrace }}", + "log": True, }, }, { "name": "log_hidden", "getval": re.compile( r""" - ^service\s(?Plog-hidden) + ^service\slog-hidden """, re.VERBOSE, ), "setval": "service log-hidden", "result": { - "log_hidden": "{{ not not log_hidden }}", + "log_hidden": True, }, }, { "name": "nagle", "getval": re.compile( r""" - ^service\s(?Pnagle) + ^service\snagle """, re.VERBOSE, ), "setval": "service nagle", "result": { - "nagle": "{{ not not nagle }}", + "nagle": True, }, }, { "name": "old_slip_prompts", "getval": re.compile( r""" - ^service\s(?Pold-slip-prompts) + ^service\sold-slip-prompts """, re.VERBOSE, ), "setval": "service old-slip-prompts", "result": { - "old_slip_prompts": "{{ not not old_slip_prompts }}", + "old_slip_prompts": True, }, }, { @@ -260,12 +275,12 @@ def __init__(self, lines=None, module=None): "name": "password_encryption", "getval": re.compile( r""" - ^service\s(?Ppassword-encryption) + ^service\spassword-encryption """, re.VERBOSE, ), "setval": "service password-encryption", "result": { - "password_encryption": "{{ not not password_encryption }}", + "password_encryption": True, }, }, { @@ -309,48 +324,48 @@ def __init__(self, lines=None, module=None): "name": "pt_vty_logging", "getval": re.compile( r""" - ^service\s(?Ppt-vty-logging) + ^service\spt-vty-logging """, re.VERBOSE, ), "setval": "service pt-vty-logging", "result": { - "pt_vty_logging": "{{ not not pt_vty_logging }}", + "pt_vty_logging": True, }, }, { "name": "scripting", "getval": re.compile( r""" - ^service\s(?Pscripting) + ^service\sscripting """, re.VERBOSE, ), "setval": "service scripting", "result": { - "scripting": "{{ not not scripting }}", + "scripting": True, }, }, { "name": "sequence_numbers", "getval": re.compile( r""" - ^service\s(?Psequence-numbers) + ^service\ssequence-numbers """, re.VERBOSE, ), "setval": "service sequence-numbers", "result": { - "sequence_numbers": "{{ not not sequence_numbers }}", + "sequence_numbers": True, }, }, { "name": "slave_coredump", "getval": re.compile( r""" - ^service\s(?Pslave-coredump) + ^service\sslave-coredump """, re.VERBOSE, ), "setval": "service slave-coredump", "result": { - "slave_coredump": "{{ not not slave_coredump }}", + "slave_coredump": True, }, }, { @@ -389,6 +404,46 @@ def __init__(self, lines=None, module=None): "tcp_keepalives_out": True, }, }, + { + "name": "tcp_small_servers", + "getval": re.compile( + r""" + ^service\stcp-small-servers + (\s(?P\d+))? + (\s(?Pno-limit))? + """, re.VERBOSE, + ), + "setval": "service tcp-small-servers" + "{{ (' ' + tcp_small_servers.max_servers|string) if tcp_small_servers.max_servers is defined else '' }}" + "{{ (' no-limit') if tcp_small_servers.no_limit|d(False) else '' }}", + "result": { + "tcp_small_servers": { + "enable": True, + "max_servers": "{{ max_servers }}", + "no_limit": "{{ not not no_limit }}", + }, + }, + }, + { + "name": "udp_small_servers", + "getval": re.compile( + r""" + ^service\sudp-small-servers + (\s(?P\d+))? + (\s(?Pno-limit))? + """, re.VERBOSE, + ), + "setval": "{{ ('service udp-small-servers') if udp_small_servers.enable|d(False) else '' }}" + "{{ (' ' + udp_small_servers.max_servers|string) if udp_small_servers.max_servers is defined else '' }}" + "{{ (' no-limit') if udp_small_servers.no_limit|d(False) else '' }}", + "result": { + "udp_small_servers": { + "enable": True, + "max_servers": "{{ max_servers }}", + "no_limit": "{{ not not no_limit }}", + }, + }, + }, { "name": "telnet_zeroidle", "getval": re.compile( @@ -402,11 +457,39 @@ def __init__(self, lines=None, module=None): }, }, { - "name": "timestamps", + "name": "log_timestamps", + "getval": re.compile( + r""" + ^service\stimestamps\slog + (\s(?P\S+))? + (\s(?Pmsec))? + (\s(?Plocaltime))? + (\s(?Pshow-timezone))? + (\s(?Pyear))? + """, re.VERBOSE, + ), + "remval": "service timestamps log", + "setval": handleTimestamp, + "result": { + "timestamps": [ + { + "msg": "log", + "timestamp": "{{ timestamp if timestamp is defined else 'uptime' }}", + "datetime_options": { + "msec": "{{ True if msec else False}}", + "localtime": "{{ True if localtime else False }}", + "show_timezone": "{{ True if show_timezone else False }}", + "year": "{{ True if year else False }}", + }, + }, + ], + }, + }, + { + "name": "debug_timestamps", "getval": re.compile( r""" - ^service\stimestamps - (\s(?P\S+))? + ^service\stimestamps\sdebug (\s(?P\S+))? (\s(?Pmsec))? (\s(?Plocaltime))? @@ -414,23 +497,12 @@ def __init__(self, lines=None, module=None): (\s(?Pyear))? """, re.VERBOSE, ), - "remval": "service timestamps{{ (' ' + msg) if msg is defined else '' }}", - "setval": "service timestamps" - "{{ (' ' + msg) if msg is defined else '' }}" - "{% if msg is defined %}" - "{{ (' ' + timestamp) if timestamp is defined else '' }}" - "{% if timestamp == 'datetime' and datetime_options is defined %}" - "{{ ' msec' if datetime_options.msec else '' }}" - "{{ ' localtime' if datetime_options.localtime else '' }}" - "{{ ' show-timezone' if datetime_options.show_timezone else '' }}" - "{{ ' year' if datetime_options.year else '' }}" - "{% endif %}" - "{% endif %}" - "", + "remval": "service timestamps debug", + "setval": handleTimestamp, "result": { "timestamps": [ { - "msg": "{{ msg if msg is defined else 'debug' }}", + "msg": "debug", "timestamp": "{{ timestamp if timestamp is defined else 'uptime' }}", "datetime_options": { "msec": "{{ True if msec else False}}", diff --git a/plugins/modules/ios_service.py b/plugins/modules/ios_service.py index 46c456569..ebe0e7881 100644 --- a/plugins/modules/ios_service.py +++ b/plugins/modules/ios_service.py @@ -22,13 +22,14 @@ version_added: 4.6.0 author: - Ambroise Rosset (@earendilfr) + - Sagar Paul (@KB-perByte) notes: - - Tested against Cisco IOSXE Version 16.9 + - Tested against Cisco IOSXE Version 17.9.1a on CML. - This module works with connection C(network_cli). See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html) options: config: - description: A dictionnary of service configuration + description: A dictionary of service configuration suboptions: call_home: description: Cisco call-home service @@ -128,7 +129,7 @@ type: bool tcp_small_servers: description: - - TCP and UDP small servers are servers (daemons, in Unix parlance) that run in the + - TCP small servers are servers (daemons, in Unix parlance) that run in the router which are useful for diagnostics. suboptions: enable: @@ -137,8 +138,11 @@ max_servers: description: - Set number of allowable TCP small servers - - 1 to 2147483647 or no-limit - type: str + - 1 to 2147483647 + type: int + no_limit: + description: No limit on number of allowable TCP small servers + type: bool type: dict telnet_zeroidle: description: Set TCP window 0 when connection is idle @@ -181,7 +185,7 @@ type: list udp_small_servers: description: - - TCP and UDP small servers are servers (daemons, in Unix parlance) that run in the + - UDP small servers are servers (daemons, in Unix parlance) that run in the router which are useful for diagnostics. suboptions: enable: @@ -189,9 +193,12 @@ type: bool max_servers: description: - - Set number of allowable TCP small servers - - 1 to 2147483647 or no-limit - type: str + - Set number of allowable UDP small servers + - 1 to 2147483647 + type: int + no_limit: + description: No limit on number of allowable UDP small servers + type: bool type: dict unsupported_transceiver: description: enable support for third-party transceivers diff --git a/tests/unit/modules/network/ios/test_ios_service.py b/tests/unit/modules/network/ios/test_ios_service.py index fa92efcdc..69af87eda 100644 --- a/tests/unit/modules/network/ios/test_ios_service.py +++ b/tests/unit/modules/network/ios/test_ios_service.py @@ -128,14 +128,13 @@ def test_ios_service_merged(self): }, } merged = [ - "service timestamps debug uptime", - "service timestamps log datetime msec localtime show-timezone year", "service password-encryption", + "service timestamps debug uptime mesc", + "service timestamps log datetime mesc localtime show-timezone year", ] playbook["state"] = "merged" set_module_args(playbook) result = self.execute_module(changed=True) - self.assertEqual(sorted(result["commands"]), sorted(merged)) def test_ios_snm_server_deleted(self): @@ -213,18 +212,17 @@ def test_ios_service_overridden(self): overridden = [ "no service call-home", "no service config", - "no service pad", "service counters max age 5", + "no service pad", "service password-encryption", "service tcp-keepalives-in", "service tcp-keepalives-out", + "service timestamps log datetime mesc localtime show-timezone year", "service timestamps debug datetime", - "service timestamps log datetime msec localtime show-timezone year", ] playbook["state"] = "overridden" set_module_args(playbook) result = self.execute_module(changed=True) - self.assertEqual(sorted(result["commands"]), sorted(overridden)) def test_ios_service_replaced(self): @@ -258,6 +256,10 @@ def test_ios_service_replaced(self): { "msg": "debug", "timestamp": "datetime", + "datetime_options": { + "localtime": True, + "msec": True, + }, }, ], "tcp_keepalives_in": True, @@ -269,18 +271,17 @@ def test_ios_service_replaced(self): replaced = [ "no service call-home", "no service config", - "no service pad", "service counters max age 5", + "no service pad", "service password-encryption", "service tcp-keepalives-in", "service tcp-keepalives-out", - "service timestamps debug datetime", - "service timestamps log datetime msec localtime show-timezone year", + "service timestamps log datetime mesc localtime show-timezone year", + "service timestamps debug datetime mesc localtime", ] playbook["state"] = "replaced" set_module_args(playbook) result = self.execute_module(changed=True) - self.assertEqual(sorted(result["commands"]), sorted(replaced)) def test_ios_service_replaced_idempotent(self): @@ -368,8 +369,6 @@ def test_ios_service_replaced_idempotent_old(self): self.assertEqual(sorted(result["commands"]), sorted(replaced)) - #################### - def test_ios_service_parsed(self): set_module_args( dict( @@ -426,36 +425,36 @@ def test_ios_service_gathered(self): service timestamps log datetime msec localtime show-timezone year service timestamps debug uptime service call-home + service udp-small-servers + service tcp-small-servers no-limit """, ) set_module_args(dict(state="gathered")) gathered = { "timestamps": [ - { - "msg": "debug", - "timestamp": "uptime", - }, { "msg": "log", "timestamp": "datetime", "datetime_options": { - "localtime": True, "msec": True, + "localtime": True, "show_timezone": True, "year": True, }, }, + {"msg": "debug", "timestamp": "uptime"}, ], "call_home": True, - "dhcp": True, + "udp_small_servers": {"enable": True}, + "tcp_small_servers": {"enable": True, "no_limit": True}, "counters": 0, + "dhcp": True, "password_recovery": True, "prompt": True, "slave_log": True, } result = self.execute_module(changed=False) self.maxDiff = None - self.assertEqual(sorted(result["gathered"]), sorted(gathered)) def test_ios_service_rendered(self): @@ -472,6 +471,9 @@ def test_ios_service_rendered(self): { "msg": "debug", "timestamp": "uptime", + "datetime_options": { + "localtime": True, + }, }, { "msg": "log", @@ -497,10 +499,9 @@ def test_ios_service_rendered(self): "service slave-log", "service tcp-keepalives-in", "service tcp-keepalives-out", - "service timestamps debug uptime", - "service timestamps log datetime msec localtime show-timezone year", + "service timestamps debug uptime localtime", + "service timestamps log datetime mesc localtime show-timezone year", ] result = self.execute_module(changed=False) self.maxDiff = None - self.assertEqual(sorted(result["rendered"]), sorted(rendered)) From 46108d05362c6696df52dddfb1edbe77647af9b8 Mon Sep 17 00:00:00 2001 From: Vinay M <63404819+roverflow@users.noreply.github.com> Date: Tue, 14 May 2024 15:08:31 +0530 Subject: [PATCH 06/10] Fix snmp host syntax (#1073) --- changelogs/fragments/snmp_server_host.yml | 3 +++ plugins/module_utils/network/ios/rm_templates/snmp_server.py | 4 ++-- tests/unit/modules/network/ios/test_ios_snmp_server.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/snmp_server_host.yml diff --git a/changelogs/fragments/snmp_server_host.yml b/changelogs/fragments/snmp_server_host.yml new file mode 100644 index 000000000..b8bbe1ee0 --- /dev/null +++ b/changelogs/fragments/snmp_server_host.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - snmp_server - Fix wrong syntax of snmp-server host command generation. diff --git a/plugins/module_utils/network/ios/rm_templates/snmp_server.py b/plugins/module_utils/network/ios/rm_templates/snmp_server.py index 45cabaae9..6f0c04c69 100644 --- a/plugins/module_utils/network/ios/rm_templates/snmp_server.py +++ b/plugins/module_utils/network/ios/rm_templates/snmp_server.py @@ -63,12 +63,12 @@ def cmd_option_hosts(config_data): # contain sub list attr cmd += " {host}".format(host=config_data.get("host")) if config_data.get("informs"): cmd += " informs" + if config_data.get("vrf"): + cmd += " vrf {vrf}".format(vrf=config_data.get("vrf")) if config_data.get("version"): cmd += " version {version}".format(version=config_data.get("version")) if config_data.get("version_option"): cmd += " {version}".format(version=config_data.get("version_option")) - if config_data.get("vrf"): - cmd += " vrf {vrf}".format(vrf=config_data.get("vrf")) if config_data.get("community_string"): cmd += " {community_string}".format( community_string=config_data.get("community_string"), diff --git a/tests/unit/modules/network/ios/test_ios_snmp_server.py b/tests/unit/modules/network/ios/test_ios_snmp_server.py index 0b8f797a1..9674c894d 100644 --- a/tests/unit/modules/network/ios/test_ios_snmp_server.py +++ b/tests/unit/modules/network/ios/test_ios_snmp_server.py @@ -1928,7 +1928,7 @@ def test_ios_snmp_server_rendered(self): "snmp-server enable traps ospf state-change", "snmp-server enable traps ethernet cfm cc mep-up mep-down cross-connect loop config", "snmp-server enable traps ethernet cfm crosscheck mep-missing mep-unknown service-up", - "snmp-server host 172.16.1.1 version 3 auth vrf mgmt group0 tty", + "snmp-server host 172.16.1.1 vrf mgmt version 3 auth group0 tty", "snmp-server host 172.16.2.1 version 3 priv newtera rsrb", "snmp-server host 172.16.2.1 version 3 noauth replaceUser slb", "snmp-server host 172.16.2.1 version 2c trapsac tty", From 746df9662a67605ba181ef9f8ddecef1300c1e9c Mon Sep 17 00:00:00 2001 From: Vinay M <63404819+roverflow@users.noreply.github.com> Date: Mon, 20 May 2024 18:29:04 +0530 Subject: [PATCH 07/10] Fix snmp-server host commad parsing (#1077) * Fix snmp-server host commad parsing * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove extra spaces * removed extra spaces --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- changelogs/fragments/snmp_parse_fix.yml | 3 +++ .../network/ios/rm_templates/snmp_server.py | 2 +- .../modules/network/ios/test_ios_snmp_server.py | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/snmp_parse_fix.yml diff --git a/changelogs/fragments/snmp_parse_fix.yml b/changelogs/fragments/snmp_parse_fix.yml new file mode 100644 index 000000000..fb2672474 --- /dev/null +++ b/changelogs/fragments/snmp_parse_fix.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - snmp_server - Fix configuration command for snmp-server host. diff --git a/plugins/module_utils/network/ios/rm_templates/snmp_server.py b/plugins/module_utils/network/ios/rm_templates/snmp_server.py index 6f0c04c69..777d4fbd9 100644 --- a/plugins/module_utils/network/ios/rm_templates/snmp_server.py +++ b/plugins/module_utils/network/ios/rm_templates/snmp_server.py @@ -322,9 +322,9 @@ def __init__(self, lines=None, module=None): ^snmp-server\shost (\s(?P\S+))? (\s(?Pinforms))? + (\svrf\s(?P\S+))? (\sversion\s(?P1|3|2c))? (\s(?Pauth|noauth|priv))? - (\svrf\s(?P\S+))? (\s(?P\S+))? (\s+(?P.+$))? """, re.VERBOSE, diff --git a/tests/unit/modules/network/ios/test_ios_snmp_server.py b/tests/unit/modules/network/ios/test_ios_snmp_server.py index 9674c894d..1c60a6628 100644 --- a/tests/unit/modules/network/ios/test_ios_snmp_server.py +++ b/tests/unit/modules/network/ios/test_ios_snmp_server.py @@ -1681,9 +1681,10 @@ def test_ios_snmp_server_parsed(self): def test_ios_snmp_server_gathered(self): self.execute_show_command.return_value = dedent( """\ - snmp-server host 172.16.2.99 checktrap isis hsrp - snmp-server host 172.16.2.1 version 3 priv newtera rsrb pim rsvp slb pki - snmp-server host 172.16.2.1 version 3 noauth replace-User! slb pki + snmp-server host 172.16.2.99 checktrap isis hsrp + snmp-server host 172.16.2.1 version 3 priv newtera rsrb pim rsvp slb pki + snmp-server host 172.16.2.1 version 3 noauth replace-User! slb pki + snmp-server host 172.16.2.1 vrf vrf1 version 3 priv newtera1 rsrb pim """, ) self.execute_show_command_user.return_value = dedent( @@ -1753,6 +1754,14 @@ def test_ios_snmp_server_gathered(self): "community_string": "checktrap", "traps": ["isis", "hsrp"], }, + { + "host": "172.16.2.99", + "vrf": "vrf1", + "version": "3", + "version_option": "priv", + "community_string": "newtera1", + "traps": ["rsrb", "pim"], + }, ], "users": [ { From 410718f4f56f3b4e832dab758cb5859c270c0b08 Mon Sep 17 00:00:00 2001 From: Vito <4026137+eleksis@users.noreply.github.com> Date: Wed, 22 May 2024 11:55:28 +0200 Subject: [PATCH 08/10] FIX: Include netmask into static_routes parser as part of result key (#1076) * Include netmask into static_routes parser Netmask is part of route destination and should be included as 'primary' key for distinguishing routes. For ipv6 it is already part of dest parameter. * Add changelog & extend unit test for parsing facts * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Vito Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Vinay M <63404819+roverflow@users.noreply.github.com> --- .../fragments/static_routes_facts_fix.yml | 3 + .../network/ios/rm_templates/static_routes.py | 2 +- .../network/ios/test_ios_static_routes.py | 55 ++++++++++++++++++- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/static_routes_facts_fix.yml diff --git a/changelogs/fragments/static_routes_facts_fix.yml b/changelogs/fragments/static_routes_facts_fix.yml new file mode 100644 index 000000000..82bc47710 --- /dev/null +++ b/changelogs/fragments/static_routes_facts_fix.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - ios_static_routes - Fix gathering facts by properly distinguising routes. diff --git a/plugins/module_utils/network/ios/rm_templates/static_routes.py b/plugins/module_utils/network/ios/rm_templates/static_routes.py index a43d59cf7..bee1aed63 100644 --- a/plugins/module_utils/network/ios/rm_templates/static_routes.py +++ b/plugins/module_utils/network/ios/rm_templates/static_routes.py @@ -64,7 +64,7 @@ def __init__(self, lines=None, module=None): "{{ (' dhcp' ) if ipv4.dhcp|d(False) else '' }}" "{{ (' global' ) if ipv4.global|d(False) else '' }}", "result": { - "{{ dest }}_{{ vrf|d() }}_{{ topology|d() }}_ipv4": [ + "{{ dest }}_{{ netmask }}_{{ vrf|d() }}_{{ topology|d() }}_ipv4": [ { "_vrf": "{{ vrf }}", "_topology": "{{ topology }}", diff --git a/tests/unit/modules/network/ios/test_ios_static_routes.py b/tests/unit/modules/network/ios/test_ios_static_routes.py index 57a416433..4bb89cc79 100644 --- a/tests/unit/modules/network/ios/test_ios_static_routes.py +++ b/tests/unit/modules/network/ios/test_ios_static_routes.py @@ -2138,6 +2138,11 @@ def test_ios_static_route_gathered(self): self.execute_show_command.return_value = dedent( """\ ip route 10.0.0.0 255.0.0.0 Null0 permanent + ip route 192.168.1.0 255.255.255.0 GigabitEthernet0/1.22 10.0.0.1 tag 30 + ip route 192.168.1.0 255.255.255.0 10.0.0.2 + ip route 192.168.1.0 255.255.255.248 GigabitEthernet0/1.23 10.0.0.3 tag 30 + ipv6 route 2001:DB8:0:3::/128 2001:DB8:0:3::33 + ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::3 """, ) set_module_args(dict(state="gathered")) @@ -2150,7 +2155,54 @@ def test_ios_static_route_gathered(self): { "dest": "10.0.0.0/8", "next_hops": [ - {"interface": "Null0", "permanent": True}, + { + "interface": "Null0", + "permanent": True, + }, + ], + }, + { + "dest": "192.168.1.0/24", + "next_hops": [ + { + "forward_router_address": "10.0.0.1", + "interface": "GigabitEthernet0/1.22", + "tag": 30, + }, + { + "forward_router_address": "10.0.0.2", + }, + ], + }, + { + "dest": "192.168.1.0/29", + "next_hops": [ + { + "forward_router_address": "10.0.0.3", + "interface": "GigabitEthernet0/1.23", + "tag": 30, + }, + ], + }, + ], + }, + { + "afi": "ipv6", + "routes": [ + { + "dest": "2001:DB8:0:3::/128", + "next_hops": [ + { + "forward_router_address": "2001:DB8:0:3::33", + }, + ], + }, + { + "dest": "2001:DB8:0:3::/64", + "next_hops": [ + { + "forward_router_address": "2001:DB8:0:3::3", + }, ], }, ], @@ -2162,4 +2214,3 @@ def test_ios_static_route_gathered(self): self.maxDiff = None print(result["gathered"]) self.assertEqual(sorted(result["gathered"]), sorted(gathered)) - # self.assertEqual(result["gathered"], gathered) From 37d99e153e3190612aa380fdc8582e9f6f091931 Mon Sep 17 00:00:00 2001 From: Vinay M <63404819+roverflow@users.noreply.github.com> Date: Thu, 23 May 2024 22:57:21 +0530 Subject: [PATCH 09/10] Acls - fix incorrectly mapping of port 135/udp to msrpc (#1078) * acls - add option to ace udp port to 135 * added changelog * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix changelog * remove print commands --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- changelogs/fragments/ios_acls_udp.yml | 3 ++ .../network/ios/config/acls/acls.py | 6 ++-- .../unit/modules/network/ios/test_ios_acls.py | 33 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/ios_acls_udp.yml diff --git a/changelogs/fragments/ios_acls_udp.yml b/changelogs/fragments/ios_acls_udp.yml new file mode 100644 index 000000000..71df169e5 --- /dev/null +++ b/changelogs/fragments/ios_acls_udp.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - ios_acls - fix incorrect mapping of port 135/udp to msrpc. diff --git a/plugins/module_utils/network/ios/config/acls/acls.py b/plugins/module_utils/network/ios/config/acls/acls.py index f604e4360..86feba1b0 100644 --- a/plugins/module_utils/network/ios/config/acls/acls.py +++ b/plugins/module_utils/network/ios/config/acls/acls.py @@ -323,7 +323,7 @@ def list_to_dict(self, param): ace.get("destination", {}).get("port_protocol", {}).items() ): ace["destination"]["port_protocol"][k] = ( - self.port_protocl_no_to_protocol(v) + self.port_protocl_no_to_protocol(v, ace.get("protocol")) ) if acl.get("acl_type") == "standard": for ks in list(ace.keys()): @@ -376,7 +376,7 @@ def list_to_dict(self, param): temp.update({each["afi"]: {"acls": temp_acls}}) return temp - def port_protocl_no_to_protocol(self, num): + def port_protocl_no_to_protocol(self, num, protocol): map_protocol = { "179": "bgp", "19": "chargen", @@ -414,4 +414,6 @@ def port_protocl_no_to_protocol(self, num): "43": "whois", "80": "www", } # NOTE - "514": "syslog" duplicate value device renders "cmd" + if protocol == "udp" and num in ["135"]: + return num return map_protocol.get(num, num) diff --git a/tests/unit/modules/network/ios/test_ios_acls.py b/tests/unit/modules/network/ios/test_ios_acls.py index 36d96365a..b06978c3b 100644 --- a/tests/unit/modules/network/ios/test_ios_acls.py +++ b/tests/unit/modules/network/ios/test_ios_acls.py @@ -362,6 +362,36 @@ def test_ios_acls_merged_remarks_positional(self): "acl_type": "extended", "name": "mytest", }, + { + "aces": [ + { + "destination": { + "any": True, + "port_protocol": { + "eq": "135", + }, + }, + "grant": "permit", + "protocol": "tcp", + "sequence": 10, + "source": {"any": True}, + }, + { + "destination": { + "any": True, + "port_protocol": { + "eq": "135", + }, + }, + "grant": "permit", + "protocol": "udp", + "sequence": 20, + "source": {"any": True}, + }, + ], + "name": "example", + "acl_type": "extended", + }, ], "afi": "ipv4", }, @@ -467,6 +497,9 @@ def test_ios_acls_merged_remarks_positional(self): "110 permit ip host 10.40.150.0 any", "remark I am the peace ace", "remark Peace out", + "ip access-list extended example", + "10 permit tcp any any eq msrpc", + "20 permit udp any any eq 135", "ip access-list extended TEST", "10 remark FIRST REMARK BEFORE LINE 10", "10 remark ============", From 302007e52b7277cd473cde0c5fd8f6d25801f776 Mon Sep 17 00:00:00 2001 From: Vinay M <63404819+roverflow@users.noreply.github.com> Date: Fri, 31 May 2024 14:21:03 +0530 Subject: [PATCH 10/10] Added doc changes for logging_global (#1074) * Added doc changes for logging_global * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * added test * doc changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Asseting dicts * Update plugins/modules/ios_logging_global.py Co-authored-by: Nilashish Chakraborty * Update plugins/modules/ios_logging_global.py Co-authored-by: Nilashish Chakraborty * [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> Co-authored-by: Nilashish Chakraborty --- changelogs/fragments/ios_logging.yml | 3 +++ docs/cisco.ios.ios_logging_global_module.rst | 4 ++++ plugins/modules/ios_logging_global.py | 5 ++++- .../ios_logging_global/tests/cli/merged.yaml | 19 +++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ios_logging.yml diff --git a/changelogs/fragments/ios_logging.yml b/changelogs/fragments/ios_logging.yml new file mode 100644 index 000000000..2ae48d1b6 --- /dev/null +++ b/changelogs/fragments/ios_logging.yml @@ -0,0 +1,3 @@ +--- +doc_changes: + - logging_global - update documentation for severity attribute within buffered. diff --git a/docs/cisco.ios.ios_logging_global_module.rst b/docs/cisco.ios.ios_logging_global_module.rst index 504441719..979918e67 100644 --- a/docs/cisco.ios.ios_logging_global_module.rst +++ b/docs/cisco.ios.ios_logging_global_module.rst @@ -127,6 +127,7 @@ Parameters
Logging severity level
+
Idempotency is not maintained for this attribute for the value 'debugging' since this value is not shown in running-config.
@@ -633,6 +634,7 @@ Parameters
Logging severity level
+
Idempotency is not maintained for this attribute for the value 'debugging' since this value is not shown in running-config.
@@ -1461,6 +1463,7 @@ Parameters
Logging severity level
+
Idempotency is not maintained for this attribute for the value 'debugging' since this value is not shown in running-config.
@@ -1970,6 +1973,7 @@ Parameters
Logging severity level
+
Idempotency is not maintained for this attribute for the value 'debugging' since this value is not shown in running-config.
diff --git a/plugins/modules/ios_logging_global.py b/plugins/modules/ios_logging_global.py index aab889772..4a78dbb5f 100644 --- a/plugins/modules/ios_logging_global.py +++ b/plugins/modules/ios_logging_global.py @@ -38,7 +38,10 @@ description: Logging buffer size type: int severity: &severity - description: Logging severity level + description: + - Logging severity level + - Idempotency is not maintained for this attribute for the value 'debugging' + since this value is not shown in running-config. type: str choices: &severity_subgroup - alerts diff --git a/tests/integration/targets/ios_logging_global/tests/cli/merged.yaml b/tests/integration/targets/ios_logging_global/tests/cli/merged.yaml index 7c3a84b8e..72fd5af2a 100644 --- a/tests/integration/targets/ios_logging_global/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_logging_global/tests/cli/merged.yaml @@ -57,5 +57,24 @@ that: - merged['after'] == result['after'] + - name: Test - [merged] merge buffered severity with device configuration (idempotent) + cisco.ios.ios_logging_global: &id001 + config: + buffered: + severity: debugging + size: 5099 + xml: true + + - name: Test - [merged] merge console severity with device configuration (idempotent) + register: resultdeb + cisco.ios.ios_logging_global: *id001 + + - name: Test - [merged] assert that debugging value is not idempotent + ansible.builtin.assert: + that: + - resultdeb['changed'] == true + - "'logging buffered xml 5099 debugging' in resultdeb['commands']" + - resultdeb["before"]["buffered"] == resultdeb["after"]["buffered"] + always: - ansible.builtin.include_tasks: _remove_config.yaml