From 0f96bbd12025f7a05d0fd1267e965ed4b02144ab Mon Sep 17 00:00:00 2001 From: Ashwini Mhatre Date: Wed, 7 Feb 2024 17:55:26 +0530 Subject: [PATCH 01/11] Fix nightly failures (#469) * Fix nightly failures * Update test-requirements.txt * Update test-requirements.txt * Update test-requirements.txt --------- Co-authored-by: Ashwini Mhatre --- changelogs/fragments/fix_nightly.yaml | 3 +++ test-requirements.txt | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/fix_nightly.yaml diff --git a/changelogs/fragments/fix_nightly.yaml b/changelogs/fragments/fix_nightly.yaml new file mode 100644 index 000000000..58ef4ac50 --- /dev/null +++ b/changelogs/fragments/fix_nightly.yaml @@ -0,0 +1,3 @@ +--- +trivial: + - Fix nightly job updating valid pytest-ansible and black version. diff --git a/test-requirements.txt b/test-requirements.txt index 2f1724f01..146694586 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,4 @@ -black==22.3.0 ; python_version > '3.5' +black==23.3.0 flake8 mock pexpect @@ -8,4 +8,6 @@ coverage==4.5.4 google-api-python-client grpcio protobuf -git+https://github.com/ansible-community/pytest-ansible-units.git +pytest-ansible +pytest-xdist +pytest-cov From 8dbc9237830214984225317e39573bf3ab20cc90 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:09:57 +0530 Subject: [PATCH 02/11] move platform guide to this repo (#471) --- README.md | 3 +- platform_guide.rst | 142 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 platform_guide.rst diff --git a/README.md b/README.md index d95ac05f6..cb27ec6a9 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ PEP440 is the schema used to describe the versions of Ansible. ### Supported connections -The Cisco IOSXR collection supports ``network_cli`` and ``netconf`` connections. + +The Cisco IOS-XR collection supports ``network_cli`` and ``netconf`` connections. A detailed platform guide can be found [here](https://github.com/ansible-collections/cisco.iosxr/blob/main/platform_guide.rst). ## Included content diff --git a/platform_guide.rst b/platform_guide.rst new file mode 100644 index 000000000..f1e8996ca --- /dev/null +++ b/platform_guide.rst @@ -0,0 +1,142 @@ +.. _iosxr_platform_options: + +*************************************** +IOS-XR Platform Options +*************************************** + +The `Cisco IOS-XR collection `_ supports multiple connections. This page offers details on how each connection works in Ansible and how to use it. + +.. contents:: + :local: + +Connections available +================================================================================ + +.. table:: + :class: documentation-table + + ==================== ========================================== ============================================================================================================ + .. CLI NETCONF + only for modules ``iosxr_banner``, ``iosxr_interface``, ``iosxr_logging``, ``iosxr_system``, ``iosxr_user`` + ==================== ========================================== ============================================================================================================ + Protocol SSH XML over SSH + + Credentials uses SSH keys / SSH-agent if present uses SSH keys / SSH-agent if present + accepts ``-u myuser -k`` if using password accepts ``-u myuser -k`` if using password + + Indirect Access by a bastion (jump host) by a bastion (jump host) + + Connection Settings ``ansible_connection:`` ``ansible_connection:`` + ``ansible.netcommon.network_cli`` ``ansible.netcommon.netconf`` + + Enable Mode not supported not supported + (Privilege Escalation) + + Returned Data Format Refer to individual module documentation Refer to individual module documentation + ==================== ========================================== ============================================================================================================ + + +The ``ansible_connection: local`` has been deprecated. Please use ``ansible_connection: ansible.netcommon.network_cli`` or ``ansible_connection: ansible.netcommon.netconf`` instead. + +Using CLI in Ansible +==================== + +Example CLI inventory ``[iosxr:vars]`` +---------------------------------------- + +.. code-block:: yaml + + [iosxr:vars] + ansible_connection=ansible.netcommon.network_cli + ansible_network_os=cisco.iosxr.iosxr + ansible_user=myuser + ansible_password=!vault... + ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q bastion01"' + +- If you are using SSH keys (including an ssh-agent) you can remove the ``ansible_password`` configuration. +- If you are accessing your host directly (not through a bastion/jump host) you can remove the ``ansible_ssh_common_args`` configuration. +- If you are accessing your host through a bastion/jump host, you cannot include your SSH password in the ``ProxyCommand`` directive. To prevent secrets from leaking out (for example in ``ps`` output), SSH does not support providing passwords through environment variables. + +Example CLI task +---------------- + +.. code-block:: yaml + + - name: Retrieve IOS-XR version + cisco.iosxr.iosxr_command: + commands: show version + when: ansible_network_os == 'cisco.iosxr.iosxr' + +Using NETCONF in Ansible +========================== + +Enabling NETCONF +--------------- + +Before you can use NETCONF to connect to a switch, you must: + + - install the ``ncclient`` python package on your control node(s) with ``pip install ncclient`` + - enable NETCONF on the Cisco IOS-XR device(s) + +To enable NETCONF on a new switch with Ansible, use the ``cisco.iosxr.iosxr_netconf`` module through the CLI connection. Set up your platform-level variables just like in the CLI example above, then run a playbook task like this: + +.. code-block:: yaml + + - name: Enable NETCONF + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_netconf: + when: ansible_network_os == 'cisco.iosxr.iosxr' + +Once NETCONF is enabled, change your variables to use the NETCONF connection. + +Example NETCONF inventory ``[iosxr:vars]`` +------------------------------------------ + +.. code-block:: yaml + + [iosxr:vars] + ansible_connection=ansible.netcommon.netconf + ansible_network_os=cisco.iosxr.iosxr + ansible_user=myuser + ansible_password=!vault | + ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q bastion01"' + + +Example NETCONF task +----------------------- + +.. code-block:: yaml + + - name: Configure hostname and domain-name + cisco.iosxr.iosxr_system: + hostname: iosxr01 + domain_name: test.example.com + domain_search: + - ansible.com + - redhat.com + - cisco.com + + +Warning +-------- +Never store passwords in plain text. We recommend using SSH keys to authenticate SSH connections. Ansible supports ssh-agent to manage your SSH keys. If you must use passwords to authenticate SSH connections, we recommend encrypting them with Ansible Vault. + +Cisco IOS-XR platform support matrix +=================================== + +The following platforms and software versions have been certified by Cisco to work with this version of Ansible. + +.. table:: Platform / Software Minimum Requirements + :align: center + + =================== ====================== + Supported Platforms Minimum IOS-XR Version + =================== ====================== + Cisco IOS-XR 7.0.2 and later + =================== ====================== + + +Notes +----- + +`Setting Timeout Option `_ From 478c93dd3945af40f53311dd385580d6132a8d7c Mon Sep 17 00:00:00 2001 From: Ashwini Mhatre Date: Wed, 14 Feb 2024 14:07:40 +0530 Subject: [PATCH 03/11] =?UTF-8?q?Add=20missing=20options=20in=20afi=20and?= =?UTF-8?q?=20safi=20in=20address-family=20of=20bgp=5Ftemplate=E2=80=A6=20?= =?UTF-8?q?(#472)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add missing options in afi and safi in address-family of bgp_templates RM. * Add uts * Update test_iosxr_bgp_templates.py --------- Co-authored-by: Ashwini Mhatre --- .../fragments/bugfix_bgp_templates.yaml | 3 ++ ...cisco.iosxr.iosxr_bgp_templates_module.rst | 8 +++++ .../argspec/bgp_templates/bgp_templates.py | 13 +++++++- plugins/modules/iosxr_bgp_templates.py | 5 +-- .../network/iosxr/test_iosxr_bgp_templates.py | 32 +++++++++++++++++++ 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/bugfix_bgp_templates.yaml diff --git a/changelogs/fragments/bugfix_bgp_templates.yaml b/changelogs/fragments/bugfix_bgp_templates.yaml new file mode 100644 index 000000000..042cb47de --- /dev/null +++ b/changelogs/fragments/bugfix_bgp_templates.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Add missing options in afi and safi in address-family of bgp_templates RM. diff --git a/docs/cisco.iosxr.iosxr_bgp_templates_module.rst b/docs/cisco.iosxr.iosxr_bgp_templates_module.rst index ed91c05d2..f923b3af6 100644 --- a/docs/cisco.iosxr.iosxr_bgp_templates_module.rst +++ b/docs/cisco.iosxr.iosxr_bgp_templates_module.rst @@ -225,6 +225,10 @@ Parameters
    Choices:
  • ipv4
  • ipv6
  • +
  • vpn4
  • +
  • vpn6
  • +
  • link-state
  • +
  • l2vpn
@@ -1419,6 +1423,10 @@ Parameters
  • unicast
  • labeled-unicast
  • sr-policy
  • +
  • link-state
  • +
  • evpn
  • +
  • mspw
  • +
  • vpls-vpws
  • diff --git a/plugins/module_utils/network/iosxr/argspec/bgp_templates/bgp_templates.py b/plugins/module_utils/network/iosxr/argspec/bgp_templates/bgp_templates.py index 793f26282..1bcd97b70 100644 --- a/plugins/module_utils/network/iosxr/argspec/bgp_templates/bgp_templates.py +++ b/plugins/module_utils/network/iosxr/argspec/bgp_templates/bgp_templates.py @@ -48,7 +48,14 @@ class Bgp_templatesArgs(object): # pylint: disable=R0903 "options": { "afi": { "type": "str", - "choices": ["ipv4", "ipv6"], + "choices": [ + "ipv4", + "ipv6", + "vpn4", + "vpn6", + "link-state", + "l2vpn", + ], }, "safi": { "type": "str", @@ -62,6 +69,10 @@ class Bgp_templatesArgs(object): # pylint: disable=R0903 "unicast", "labeled-unicast", "sr-policy", + "link-state", + "evpn", + "mspw", + "vpls-vpws", ], }, "signalling": { diff --git a/plugins/modules/iosxr_bgp_templates.py b/plugins/modules/iosxr_bgp_templates.py index 5db2cb2ad..5cbb03359 100644 --- a/plugins/modules/iosxr_bgp_templates.py +++ b/plugins/modules/iosxr_bgp_templates.py @@ -46,11 +46,12 @@ afi: description: address family. type: str - choices: [ 'ipv4', 'ipv6' ] + choices: [ 'ipv4', 'ipv6', 'vpn4', 'vpn6', 'link-state', 'l2vpn'] safi: description: Address Family modifier type: str - choices: [ 'flowspec', 'mdt', 'multicast', 'mvpn', 'rt-filter', 'tunnel', 'unicast', 'labeled-unicast' , 'sr-policy'] + choices: [ 'flowspec', 'mdt', 'multicast', 'mvpn', 'rt-filter', 'tunnel', + 'unicast', 'labeled-unicast' , 'sr-policy', 'link-state', 'evpn', 'mspw', 'vpls-vpws'] signalling: type: dict description: Signalling protocols to disable, BGP or LDP diff --git a/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py b/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py index 4efc04503..c97dd7031 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py @@ -239,6 +239,22 @@ def test_iosxr_bgp_tmpl_merged(self): safi="unicast", advertise=dict(local_labeled_route=dict(set=True)), ), + dict( + afi="vpn4", + safi="unicast", + ), + dict( + afi="vpn6", + safi="unicast", + ), + dict( + afi="link-state", + safi="link-state", + ), + dict( + afi="l2vpn", + safi="evpn", + ), ], ), dict( @@ -324,6 +340,10 @@ def test_iosxr_bgp_tmpl_merged(self): "bfd fast-detect strict-mode", "internal-vpn-client", "precedence critical", + "address-family vpn4 unicast", + "address-family vpn6 unicast", + "address-family link-state link-state", + "address-family l2vpn evpn", "address-family ipv4 unicast", "advertise local-labeled-route", "neighbor-group test1", @@ -1128,6 +1148,14 @@ def test_iosxr_bgp_tmpl_gathered(self): precedence critical advertisement-interval 10 internal-vpn-client + address-family vpn4 unicast + ! + address-family vpn6 unicast + ! + address-family link-state link-state + ! + address-family l2vpn evpn + ! address-family ipv4 unicast advertise local-labeled-route ! @@ -1199,6 +1227,10 @@ def test_iosxr_bgp_tmpl_gathered(self): "advertisement_interval": 10, "internal_vpn_client": True, "address_family": [ + {"afi": "vpn4", "safi": "unicast"}, + {"afi": "vpn6", "safi": "unicast"}, + {"afi": "link-state", "safi": "link-state"}, + {"afi": "l2vpn", "safi": "evpn"}, { "afi": "ipv4", "safi": "unicast", From 8d7c66a24776a97cf0a4544e2f0926a24bcaeaa7 Mon Sep 17 00:00:00 2001 From: Ashwini Mhatre Date: Thu, 22 Feb 2024 21:16:16 +0530 Subject: [PATCH 04/11] Fix issue in afi choices (#473) * Fix issue in afi choices * Fix uts --------- Co-authored-by: Ashwini Mhatre --- changelogs/fragments/bugfix_bgp_templates.yaml | 2 +- changelogs/fragments/fix_bgp_template.yaml | 3 +++ docs/cisco.iosxr.iosxr_bgp_templates_module.rst | 4 ++-- .../iosxr/argspec/bgp_templates/bgp_templates.py | 4 ++-- plugins/modules/iosxr_bgp_templates.py | 2 +- .../network/iosxr/test_iosxr_bgp_templates.py | 16 ++++++++-------- 6 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 changelogs/fragments/fix_bgp_template.yaml diff --git a/changelogs/fragments/bugfix_bgp_templates.yaml b/changelogs/fragments/bugfix_bgp_templates.yaml index 042cb47de..4b1b1e4b4 100644 --- a/changelogs/fragments/bugfix_bgp_templates.yaml +++ b/changelogs/fragments/bugfix_bgp_templates.yaml @@ -1,3 +1,3 @@ --- -bugfixes: +minor_changes: - Add missing options in afi and safi in address-family of bgp_templates RM. diff --git a/changelogs/fragments/fix_bgp_template.yaml b/changelogs/fragments/fix_bgp_template.yaml new file mode 100644 index 000000000..1cce27038 --- /dev/null +++ b/changelogs/fragments/fix_bgp_template.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fix 'afi' value in bgp_templates RM to valid values. diff --git a/docs/cisco.iosxr.iosxr_bgp_templates_module.rst b/docs/cisco.iosxr.iosxr_bgp_templates_module.rst index f923b3af6..72440deaa 100644 --- a/docs/cisco.iosxr.iosxr_bgp_templates_module.rst +++ b/docs/cisco.iosxr.iosxr_bgp_templates_module.rst @@ -225,8 +225,8 @@ Parameters
      Choices:
    • ipv4
    • ipv6
    • -
    • vpn4
    • -
    • vpn6
    • +
    • vpnv4
    • +
    • vpnv6
    • link-state
    • l2vpn
    diff --git a/plugins/module_utils/network/iosxr/argspec/bgp_templates/bgp_templates.py b/plugins/module_utils/network/iosxr/argspec/bgp_templates/bgp_templates.py index 1bcd97b70..51a70c5fd 100644 --- a/plugins/module_utils/network/iosxr/argspec/bgp_templates/bgp_templates.py +++ b/plugins/module_utils/network/iosxr/argspec/bgp_templates/bgp_templates.py @@ -51,8 +51,8 @@ class Bgp_templatesArgs(object): # pylint: disable=R0903 "choices": [ "ipv4", "ipv6", - "vpn4", - "vpn6", + "vpnv4", + "vpnv6", "link-state", "l2vpn", ], diff --git a/plugins/modules/iosxr_bgp_templates.py b/plugins/modules/iosxr_bgp_templates.py index 5cbb03359..b57ac4f9f 100644 --- a/plugins/modules/iosxr_bgp_templates.py +++ b/plugins/modules/iosxr_bgp_templates.py @@ -46,7 +46,7 @@ afi: description: address family. type: str - choices: [ 'ipv4', 'ipv6', 'vpn4', 'vpn6', 'link-state', 'l2vpn'] + choices: [ 'ipv4', 'ipv6', 'vpnv4', 'vpnv6', 'link-state', 'l2vpn'] safi: description: Address Family modifier type: str diff --git a/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py b/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py index c97dd7031..ddc6dfb89 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py @@ -240,11 +240,11 @@ def test_iosxr_bgp_tmpl_merged(self): advertise=dict(local_labeled_route=dict(set=True)), ), dict( - afi="vpn4", + afi="vpnv4", safi="unicast", ), dict( - afi="vpn6", + afi="vpnv6", safi="unicast", ), dict( @@ -340,8 +340,8 @@ def test_iosxr_bgp_tmpl_merged(self): "bfd fast-detect strict-mode", "internal-vpn-client", "precedence critical", - "address-family vpn4 unicast", - "address-family vpn6 unicast", + "address-family vpnv4 unicast", + "address-family vpnv6 unicast", "address-family link-state link-state", "address-family l2vpn evpn", "address-family ipv4 unicast", @@ -1148,9 +1148,9 @@ def test_iosxr_bgp_tmpl_gathered(self): precedence critical advertisement-interval 10 internal-vpn-client - address-family vpn4 unicast + address-family vpnv4 unicast ! - address-family vpn6 unicast + address-family vpnv6 unicast ! address-family link-state link-state ! @@ -1227,8 +1227,8 @@ def test_iosxr_bgp_tmpl_gathered(self): "advertisement_interval": 10, "internal_vpn_client": True, "address_family": [ - {"afi": "vpn4", "safi": "unicast"}, - {"afi": "vpn6", "safi": "unicast"}, + {"afi": "vpnv4", "safi": "unicast"}, + {"afi": "vpnv6", "safi": "unicast"}, {"afi": "link-state", "safi": "link-state"}, {"afi": "l2vpn", "safi": "evpn"}, { From e14227cd1f16228d69427b4194a7837c35121387 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> Date: Wed, 6 Mar 2024 18:56:37 +0530 Subject: [PATCH 05/11] Prepare for release 7.2.0 (#476) * Prepare for release * update galaxy.yml --------- Co-authored-by: Ashwini Mhatre --- CHANGELOG.rst | 13 +++++++++++++ changelogs/changelog.yaml | 11 +++++++++++ changelogs/fragments/bugfix_bgp_templates.yaml | 3 --- changelogs/fragments/fix_bgp_template.yaml | 3 --- changelogs/fragments/fix_nightly.yaml | 3 --- galaxy.yml | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) delete mode 100644 changelogs/fragments/bugfix_bgp_templates.yaml delete mode 100644 changelogs/fragments/fix_bgp_template.yaml delete mode 100644 changelogs/fragments/fix_nightly.yaml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b6040dcfa..81065138c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,19 @@ Cisco Iosxr Collection Release Notes .. contents:: Topics +v7.2.0 +====== + +Minor Changes +------------- + +- Add missing options in afi and safi in address-family of bgp_templates RM. + +Bugfixes +-------- + +- Fix 'afi' value in bgp_templates RM to valid values. + v7.1.0 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 4f12383cc..ab7c68a9a 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -709,3 +709,14 @@ releases: - fix_add_cdp_neighbors.yaml - fix_iosxr_config.yaml release_date: "2024-01-08" + 7.2.0: + changes: + bugfixes: + - Fix 'afi' value in bgp_templates RM to valid values. + minor_changes: + - Add missing options in afi and safi in address-family of bgp_templates RM. + fragments: + - bugfix_bgp_templates.yaml + - fix_bgp_template.yaml + - fix_nightly.yaml + release_date: "2024-03-01" diff --git a/changelogs/fragments/bugfix_bgp_templates.yaml b/changelogs/fragments/bugfix_bgp_templates.yaml deleted file mode 100644 index 4b1b1e4b4..000000000 --- a/changelogs/fragments/bugfix_bgp_templates.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -minor_changes: - - Add missing options in afi and safi in address-family of bgp_templates RM. diff --git a/changelogs/fragments/fix_bgp_template.yaml b/changelogs/fragments/fix_bgp_template.yaml deleted file mode 100644 index 1cce27038..000000000 --- a/changelogs/fragments/fix_bgp_template.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -bugfixes: - - Fix 'afi' value in bgp_templates RM to valid values. diff --git a/changelogs/fragments/fix_nightly.yaml b/changelogs/fragments/fix_nightly.yaml deleted file mode 100644 index 58ef4ac50..000000000 --- a/changelogs/fragments/fix_nightly.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -trivial: - - Fix nightly job updating valid pytest-ansible and black version. diff --git a/galaxy.yml b/galaxy.yml index 342b74121..194566307 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -13,4 +13,4 @@ issues: https://github.com/ansible-collections/cisco.iosxr/issues tags: [cisco, iosxr, networking, netconf] # NOTE(pabelanger): We create an empty version key to keep ansible-galaxy # happy. We dynamically inject version info based on git information. -version: "7.1.0" +version: "7.2.0" From 2429e30148efb60e2007250a17e2eab76d3d5fb3 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> Date: Tue, 26 Mar 2024 17:16:09 +0530 Subject: [PATCH 06/11] Enable content-actions (#477) * enable content-actions * lint changes * lint changes * lint changes * lint changes * revised changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update README.md * add auto-versioning * changes * disable autoversion --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .ansible-lint | 3 +-- .github/CODEOWNERS | 0 .../workflows/{ack.yml => check_label.yml} | 10 +++---- .github/workflows/codecoverage.yml | 3 ++- .github/workflows/draft_release.yml | 18 +++++++++++++ .github/workflows/lint.yml | 13 --------- .github/workflows/push.yml | 27 ------------------- .github/workflows/release.yml | 4 +-- .github/workflows/tests.yml | 14 ++++++---- .pre-commit-config.yaml | 2 +- README.md | 4 +-- requirements.txt | 1 - test-requirements.txt | 1 - tests/sanity/ignore-2.14.txt | 2 +- tests/sanity/ignore-2.15.txt | 2 +- tests/sanity/ignore-2.16.txt | 2 +- tests/sanity/ignore-2.17.txt | 2 +- tox-ansible.ini | 10 +++++++ 18 files changed, 52 insertions(+), 66 deletions(-) create mode 100644 .github/CODEOWNERS rename .github/workflows/{ack.yml => check_label.yml} (60%) create mode 100644 .github/workflows/draft_release.yml delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/push.yml create mode 100644 tox-ansible.ini diff --git a/.ansible-lint b/.ansible-lint index 4ff85b9c0..7324ff454 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -1,7 +1,6 @@ --- + profile: production -exclude_paths: - - changelogs/changelog.yaml skip_list: # ansible-lint does not like the `import-3.11` ignore in tests/sanity/ignore-*.txt - sanity diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..e69de29bb diff --git a/.github/workflows/ack.yml b/.github/workflows/check_label.yml similarity index 60% rename from .github/workflows/ack.yml rename to .github/workflows/check_label.yml index fda595dc5..b120bfa32 100644 --- a/.github/workflows/ack.yml +++ b/.github/workflows/check_label.yml @@ -1,15 +1,11 @@ --- -# See https://github.com/ansible-community/devtools/blob/main/.github/workflows/ack.yml -name: ack - +name: "Check label" concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true - on: # yamllint disable-line rule:truthy pull_request_target: types: [opened, labeled, unlabeled, synchronize] - jobs: - ack: - uses: ansible/devtools/.github/workflows/ack.yml@main + check_label: + uses: ansible/ansible-content-actions/.github/workflows/check_label.yaml@main diff --git a/.github/workflows/codecoverage.yml b/.github/workflows/codecoverage.yml index b425edcc2..3e0f17919 100644 --- a/.github/workflows/codecoverage.yml +++ b/.github/workflows/codecoverage.yml @@ -1,8 +1,9 @@ --- -name: Code Coverage +name: "Code coverage" on: # yamllint disable-line rule:truthy push: + branches: [main] pull_request: branches: [ main ] diff --git a/.github/workflows/draft_release.yml b/.github/workflows/draft_release.yml new file mode 100644 index 000000000..88b45f2b0 --- /dev/null +++ b/.github/workflows/draft_release.yml @@ -0,0 +1,18 @@ +--- +name: "Draft release" +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +on: # yamllint disable-line rule:truthy + workflow_dispatch: +env: + NAMESPACE: ${{ github.repository_owner }} + COLLECTION_NAME: iosxr + ANSIBLE_COLLECTIONS_PATHS: ./ +jobs: + update_release_draft: + uses: ansible/ansible-content-actions/.github/workflows/draft_release.yaml@main + with: + repo: ${{ github.event.pull_request.head.repo.full_name }} + secrets: + BOT_PAT: ${{ secrets.BOT_PAT }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 4e45c595d..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -name: ansible-lint -on: # yamllint disable-line rule:truthy - pull_request: - branches: ["main"] -jobs: - build: - name: Ansible Lint # Naming the build is important to use it as a status check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Run ansible-lint - uses: ansible/ansible-lint@main # or version tag instead of 'main' diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml deleted file mode 100644 index 06d11b8a0..000000000 --- a/.github/workflows/push.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -# push workflow is shared and expected to perform actions after a merge happens -# on a maintenance branch (default or release). For example updating the -# draft release-notes. -# based on great work from -# https://github.com/T-Systems-MMS/ansible-collection-icinga-director -name: push - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -on: # yamllint disable-line rule:truthy - workflow_dispatch: - -env: - NAMESPACE: cisco - COLLECTION_NAME: iosxr - ANSIBLE_COLLECTIONS_PATHS: ./ - -jobs: - update_release_draft: - uses: ansible/devtools/.github/workflows/push_network.yml@main - with: - repo: ansible-collections/cisco.iosxr - secrets: - BOT_PAT: ${{ secrets.BOT_PAT }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb04259d1..6dbb1aa39 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,12 +1,12 @@ --- -name: release +name: "Release collection" on: # yamllint disable-line rule:truthy release: types: [published] jobs: release: - uses: ansible/devtools/.github/workflows/release_collection.yml@main + uses: ansible/ansible-content-actions/.github/workflows/release.yaml@main with: environment: release secrets: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 506c33aa0..a59a35d77 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,5 +1,5 @@ --- -name: CI +name: "CI" concurrency: group: ${{ github.head_ref || github.run_id }} @@ -14,12 +14,14 @@ on: # yamllint disable-line rule:truthy jobs: changelog: - uses: ansible-network/github_actions/.github/workflows/changelog.yml@main + uses: ansible/ansible-content-actions/.github/workflows/changelog.yaml@main if: github.event_name == 'pull_request' + ansible-lint: + uses: ansible/ansible-content-actions/.github/workflows/ansible_lint.yaml@main sanity: - uses: ansible-network/github_actions/.github/workflows/sanity.yml@main + uses: ansible/ansible-content-actions/.github/workflows/sanity.yaml@main unit-galaxy: - uses: ansible-network/github_actions/.github/workflows/unit_galaxy.yml@main + uses: ansible/ansible-content-actions/.github/workflows/unit.yaml@main unit-source: uses: ansible-network/github_actions/.github/workflows/unit_source.yml@main with: @@ -32,6 +34,7 @@ jobs: - changelog - sanity - unit-galaxy + - ansible-lint - unit-source runs-on: ubuntu-latest steps: @@ -41,5 +44,6 @@ jobs: '${{ needs.changelog.result }}', '${{ needs.sanity.result }}', '${{ needs.unit-galaxy.result }}', - '${{ needs.unit-source.result }}' + '${{ needs.ansible-lint.result }}', + '${{ needs.unit-source.outputs.result }}' ])" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8fdbd4b3a..d034d8da3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: - repo: https://github.com/ansible-network/collection_prep rev: 1.1.1 hooks: - # - id: autoversion # removed as being handled by GHA push and release drafter + # - id: autoversion # removed as being handled by GHA push and release drafter - id: update-docs - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/README.md b/README.md index cb27ec6a9..a0faec864 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ The Ansible Cisco IOSXR collection includes a variety of Ansible content to help automate the management of Cisco IOSXR network appliances. -This collection has been tested against Cisco IOSXR version 7.0.2. +This collection has been tested against Cisco IOS-XR version 7.0.2 ## Ansible version compatibility @@ -77,7 +77,7 @@ Click the ``Content`` button to see the list of content included in this collect ## Installing this collection -You can install the Cisco IOSXR collection with the Ansible Galaxy CLI: +You can install the Cisco IOS-XR collection with the Ansible Galaxy CLI: ansible-galaxy collection install cisco.iosxr diff --git a/requirements.txt b/requirements.txt index 2fb85f407..ece31d550 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ ncclient paramiko -ipaddress grpcio protobuf ansible-pylibssh diff --git a/test-requirements.txt b/test-requirements.txt index 146694586..b8dae64f8 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,6 @@ black==23.3.0 flake8 mock pexpect -pytest-xdist yamllint coverage==4.5.4 google-api-python-client diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt index 63b93ff5a..1e8023a57 100644 --- a/tests/sanity/ignore-2.14.txt +++ b/tests/sanity/ignore-2.14.txt @@ -1,4 +1,4 @@ -plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local +plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.9!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.11!skip diff --git a/tests/sanity/ignore-2.15.txt b/tests/sanity/ignore-2.15.txt index 63b93ff5a..1e8023a57 100644 --- a/tests/sanity/ignore-2.15.txt +++ b/tests/sanity/ignore-2.15.txt @@ -1,4 +1,4 @@ -plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local +plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.9!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.11!skip diff --git a/tests/sanity/ignore-2.16.txt b/tests/sanity/ignore-2.16.txt index 450f3eab7..6d49e3dcb 100644 --- a/tests/sanity/ignore-2.16.txt +++ b/tests/sanity/ignore-2.16.txt @@ -1,4 +1,4 @@ -plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local +plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.11!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.12!skip diff --git a/tests/sanity/ignore-2.17.txt b/tests/sanity/ignore-2.17.txt index 450f3eab7..6d49e3dcb 100644 --- a/tests/sanity/ignore-2.17.txt +++ b/tests/sanity/ignore-2.17.txt @@ -1,4 +1,4 @@ -plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local +plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.11!skip plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.12!skip diff --git a/tox-ansible.ini b/tox-ansible.ini new file mode 100644 index 000000000..5e1f4b36a --- /dev/null +++ b/tox-ansible.ini @@ -0,0 +1,10 @@ +[ansible] + +skip = + py3.7 + py3.8 + 2.9 + 2.10 + 2.11 + 2.12 + 2.13 From cbb648ce9ae8a547694e4dc31cfc0e93753ff8d4 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:41:35 +0530 Subject: [PATCH 07/11] Remove py27 compat files & update imports for patch & magicmock (#480) * remove compat files & imports * [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> --- .github/workflows/tests.yml | 2 +- .../fragments/trivial_tests_updates.yaml | 4 + tests/unit/compat/__init__.py | 0 tests/unit/compat/mock.py | 129 ------------------ tests/unit/compat/unittest.py | 41 ------ tests/unit/mock/path.py | 4 +- .../modules/network/iosxr/test_hostname.py | 2 +- .../unit/modules/network/iosxr/test_iosxr.py | 4 +- .../iosxr/test_iosxr_acl_interfaces.py | 3 +- .../modules/network/iosxr/test_iosxr_acls.py | 3 +- .../network/iosxr/test_iosxr_banner.py | 2 +- .../iosxr/test_iosxr_bgp_address_family.py | 2 +- .../network/iosxr/test_iosxr_bgp_global.py | 2 +- .../test_iosxr_bgp_neighbor_address_family.py | 2 +- .../network/iosxr/test_iosxr_bgp_templates.py | 2 +- .../network/iosxr/test_iosxr_command.py | 3 +- .../network/iosxr/test_iosxr_config.py | 2 +- .../modules/network/iosxr/test_iosxr_facts.py | 3 +- .../network/iosxr/test_iosxr_interfaces.py | 3 +- .../network/iosxr/test_iosxr_l2_interfaces.py | 3 +- .../network/iosxr/test_iosxr_l3_interfaces.py | 3 +- .../modules/network/iosxr/test_iosxr_lacp.py | 3 +- .../iosxr/test_iosxr_lacp_interfaces.py | 3 +- .../iosxr/test_iosxr_lag_interfaces.py | 3 +- .../network/iosxr/test_iosxr_lldp_global.py | 3 +- .../iosxr/test_iosxr_lldp_interfaces.py | 3 +- .../iosxr/test_iosxr_logging_global.py | 2 +- .../modules/network/iosxr/test_iosxr_n540.py | 4 +- .../network/iosxr/test_iosxr_netconf.py | 3 +- .../network/iosxr/test_iosxr_ntp_global.py | 2 +- .../iosxr/test_iosxr_ospf_interfaces.py | 3 +- .../network/iosxr/test_iosxr_ospfv2.py | 3 +- .../network/iosxr/test_iosxr_ospfv3.py | 3 +- .../modules/network/iosxr/test_iosxr_ping.py | 2 +- .../network/iosxr/test_iosxr_prefix_lists.py | 2 +- .../network/iosxr/test_iosxr_snmp_server.py | 2 +- .../network/iosxr/test_iosxr_static_routes.py | 3 +- .../network/iosxr/test_iosxr_system.py | 3 +- .../modules/network/iosxr/test_iosxr_user.py | 3 +- .../modules/network/iosxr/test_iosxr_utils.py | 6 +- tests/unit/modules/utils.py | 8 +- tox.ini | 2 +- 42 files changed, 70 insertions(+), 215 deletions(-) create mode 100644 changelogs/fragments/trivial_tests_updates.yaml delete mode 100644 tests/unit/compat/__init__.py delete mode 100644 tests/unit/compat/mock.py delete mode 100644 tests/unit/compat/unittest.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a59a35d77..5c01a71c7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -45,5 +45,5 @@ jobs: '${{ needs.sanity.result }}', '${{ needs.unit-galaxy.result }}', '${{ needs.ansible-lint.result }}', - '${{ needs.unit-source.outputs.result }}' + '${{ needs.unit-source.result }}' ])" diff --git a/changelogs/fragments/trivial_tests_updates.yaml b/changelogs/fragments/trivial_tests_updates.yaml new file mode 100644 index 000000000..6f9f7d906 --- /dev/null +++ b/changelogs/fragments/trivial_tests_updates.yaml @@ -0,0 +1,4 @@ +--- +trivial: + - remove compat files as we stopped testing against python 2.7. + - update direct imports for patch and MagicMock from unittest. diff --git a/tests/unit/compat/__init__.py b/tests/unit/compat/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/unit/compat/mock.py b/tests/unit/compat/mock.py deleted file mode 100644 index e4ce72b34..000000000 --- a/tests/unit/compat/mock.py +++ /dev/null @@ -1,129 +0,0 @@ -# (c) 2014, Toshio Kuratomi -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish -from __future__ import absolute_import, division, print_function - - -__metaclass__ = type - -""" -Compat module for Python3.x's unittest.mock module -""" -import sys - -import _io - - -# Python 2.7 - -# Note: Could use the pypi mock library on python3.x as well as python2.x. It -# is the same as the python3 stdlib mock library - -try: - # Allow wildcard import because we really do want to import all of mock's - # symbols into this compat shim - # pylint: disable=wildcard-import,unused-wildcard-import - from unittest.mock import * -except ImportError: - # Python 2 - # pylint: disable=wildcard-import,unused-wildcard-import - try: - from mock import * - except ImportError: - print("You need the mock library installed on python2.x to run tests") - - -# Prior to 3.4.4, mock_open cannot handle binary read_data -if sys.version_info >= (3,) and sys.version_info < (3, 4, 4): - file_spec = None - - def _iterate_read_data(read_data): - # Helper for mock_open: - # Retrieve lines from read_data via a generator so that separate calls to - # readline, read, and readlines are properly interleaved - sep = b"\n" if isinstance(read_data, bytes) else "\n" - data_as_list = [l + sep for l in read_data.split(sep)] - - if data_as_list[-1] == sep: - # If the last line ended in a newline, the list comprehension will have an - # extra entry that's just a newline. Remove this. - data_as_list = data_as_list[:-1] - else: - # If there wasn't an extra newline by itself, then the file being - # emulated doesn't have a newline to end the last line remove the - # newline that our naive format() added - data_as_list[-1] = data_as_list[-1][:-1] - - for line in data_as_list: - yield line - - def mock_open(mock=None, read_data=""): - """ - A helper function to create a mock to replace the use of `open`. It works - for `open` called directly or used as a context manager. - - The `mock` argument is the mock object to configure. If `None` (the - default) then a `MagicMock` will be created for you, with the API limited - to methods or attributes available on standard file handles. - - `read_data` is a string for the `read` methoddline`, and `readlines` of the - file handle to return. This is an empty string by default. - """ - - def _readlines_side_effect(*args, **kwargs): - if handle.readlines.return_value is not None: - return handle.readlines.return_value - return list(_data) - - def _read_side_effect(*args, **kwargs): - if handle.read.return_value is not None: - return handle.read.return_value - return type(read_data)().join(_data) - - def _readline_side_effect(): - if handle.readline.return_value is not None: - while True: - yield handle.readline.return_value - for line in _data: - yield line - - global file_spec - if file_spec is None: - file_spec = list( - set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))), - ) - - if mock is None: - mock = MagicMock(name="open", spec=open) - - handle = MagicMock(spec=file_spec) - handle.__enter__.return_value = handle - - _data = _iterate_read_data(read_data) - - handle.write.return_value = None - handle.read.return_value = None - handle.readline.return_value = None - handle.readlines.return_value = None - - handle.read.side_effect = _read_side_effect - handle.readline.side_effect = _readline_side_effect() - handle.readlines.side_effect = _readlines_side_effect - - mock.return_value = handle - return mock diff --git a/tests/unit/compat/unittest.py b/tests/unit/compat/unittest.py deleted file mode 100644 index df4266ec9..000000000 --- a/tests/unit/compat/unittest.py +++ /dev/null @@ -1,41 +0,0 @@ -# (c) 2014, Toshio Kuratomi -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish -from __future__ import absolute_import, division, print_function - - -__metaclass__ = type - -""" -Compat module for Python2.7's unittest module -""" - -import sys - - -# Allow wildcard import because we really do want to import all of -# unittests's symbols into this compat shim -# pylint: disable=wildcard-import,unused-wildcard-import -if sys.version_info < (2, 7): - try: - # Need unittest2 on python2.6 - from unittest2 import * - except ImportError: - print("You need unittest2 installed on python2.6.x to run tests") -else: - from unittest import * diff --git a/tests/unit/mock/path.py b/tests/unit/mock/path.py index 0c87896da..7d287a5fb 100644 --- a/tests/unit/mock/path.py +++ b/tests/unit/mock/path.py @@ -2,9 +2,9 @@ __metaclass__ = type -from ansible.utils.path import unfrackpath +from unittest.mock import MagicMock -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import MagicMock +from ansible.utils.path import unfrackpath mock_unfrackpath_noop = MagicMock( diff --git a/tests/unit/modules/network/iosxr/test_hostname.py b/tests/unit/modules/network/iosxr/test_hostname.py index 7c676530b..9eda36615 100644 --- a/tests/unit/modules/network/iosxr/test_hostname.py +++ b/tests/unit/modules/network/iosxr/test_hostname.py @@ -23,9 +23,9 @@ __metaclass__ = type from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_hostname -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr.py b/tests/unit/modules/network/iosxr/test_iosxr.py index af2fd3a5c..32eb85797 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr.py +++ b/tests/unit/modules/network/iosxr/test_iosxr.py @@ -22,15 +22,15 @@ __metaclass__ = type from os import path +from unittest import TestCase from ansible.module_utils._text import to_bytes, to_text from mock import MagicMock from ansible_collections.cisco.iosxr.plugins.cliconf import iosxr -from ansible_collections.cisco.iosxr.tests.unit.compat import unittest -class TestPluginCLIConfIOSXR(unittest.TestCase): +class TestPluginCLIConfIOSXR(TestCase): """Test class for IOSXR CLI Conf Methods""" def setUp(self): diff --git a/tests/unit/modules/network/iosxr/test_iosxr_acl_interfaces.py b/tests/unit/modules/network/iosxr/test_iosxr_acl_interfaces.py index 8500c0733..0c29c6c13 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_acl_interfaces.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_acl_interfaces.py @@ -22,8 +22,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_acl_interfaces -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_acls.py b/tests/unit/modules/network/iosxr/test_iosxr_acls.py index 181b239d8..d301bda7b 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_acls.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_acls.py @@ -8,8 +8,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_acls -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_banner.py b/tests/unit/modules/network/iosxr/test_iosxr_banner.py index 5dcbada13..32085d51e 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_banner.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_banner.py @@ -38,9 +38,9 @@ __metaclass__ = type +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_banner -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_bgp_address_family.py b/tests/unit/modules/network/iosxr/test_iosxr_bgp_address_family.py index 57770b59d..ce8d12c95 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_bgp_address_family.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_bgp_address_family.py @@ -23,9 +23,9 @@ __metaclass__ = type from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_bgp_address_family -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr_bgp_global.py b/tests/unit/modules/network/iosxr/test_iosxr_bgp_global.py index 901b5b4d8..6527fb48d 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_bgp_global.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_bgp_global.py @@ -23,9 +23,9 @@ __metaclass__ = type from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_bgp_global -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr_bgp_neighbor_address_family.py b/tests/unit/modules/network/iosxr/test_iosxr_bgp_neighbor_address_family.py index d6fd0610d..6714adee8 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_bgp_neighbor_address_family.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_bgp_neighbor_address_family.py @@ -23,9 +23,9 @@ __metaclass__ = type from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_bgp_neighbor_address_family -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py b/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py index ddc6dfb89..58cec9977 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_bgp_templates.py @@ -23,9 +23,9 @@ __metaclass__ = type from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_bgp_templates -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr_command.py b/tests/unit/modules/network/iosxr/test_iosxr_command.py index cd691d6c4..b3787e600 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_command.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_command.py @@ -21,8 +21,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_command -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_config.py b/tests/unit/modules/network/iosxr/test_iosxr_config.py index 9ac6866af..dffd4b4c9 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_config.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_config.py @@ -21,10 +21,10 @@ __metaclass__ = type +from unittest.mock import MagicMock, patch from ansible_collections.cisco.iosxr.plugins.cliconf.iosxr import Cliconf from ansible_collections.cisco.iosxr.plugins.modules import iosxr_config -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import MagicMock, patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_facts.py b/tests/unit/modules/network/iosxr/test_iosxr_facts.py index c9efd77e1..6c0e02e0f 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_facts.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_facts.py @@ -23,8 +23,9 @@ import json +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_facts -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_interfaces.py b/tests/unit/modules/network/iosxr/test_iosxr_interfaces.py index bff925c60..15a8de4e5 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_interfaces.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_interfaces.py @@ -22,8 +22,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_interfaces -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_l2_interfaces.py b/tests/unit/modules/network/iosxr/test_iosxr_l2_interfaces.py index f28561777..9bef80c39 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_l2_interfaces.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_l2_interfaces.py @@ -22,8 +22,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_l2_interfaces -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_l3_interfaces.py b/tests/unit/modules/network/iosxr/test_iosxr_l3_interfaces.py index 071b16b8f..14b5a1e51 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_l3_interfaces.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_l3_interfaces.py @@ -22,8 +22,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_l3_interfaces -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_lacp.py b/tests/unit/modules/network/iosxr/test_iosxr_lacp.py index 23c4b8cd9..09e7fa8ec 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_lacp.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_lacp.py @@ -22,8 +22,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_lacp -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_lacp_interfaces.py b/tests/unit/modules/network/iosxr/test_iosxr_lacp_interfaces.py index 55358a061..d6bb57c40 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_lacp_interfaces.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_lacp_interfaces.py @@ -22,8 +22,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_lacp_interfaces -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_lag_interfaces.py b/tests/unit/modules/network/iosxr/test_iosxr_lag_interfaces.py index b0d68fc62..032539115 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_lag_interfaces.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_lag_interfaces.py @@ -22,8 +22,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_lag_interfaces -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_lldp_global.py b/tests/unit/modules/network/iosxr/test_iosxr_lldp_global.py index 4830058df..d2b74103b 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_lldp_global.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_lldp_global.py @@ -22,8 +22,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_lldp_global -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_lldp_interfaces.py b/tests/unit/modules/network/iosxr/test_iosxr_lldp_interfaces.py index 78b6d79f0..889eb8e57 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_lldp_interfaces.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_lldp_interfaces.py @@ -22,8 +22,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_lldp_interfaces -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_logging_global.py b/tests/unit/modules/network/iosxr/test_iosxr_logging_global.py index bffee2b17..205740f19 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_logging_global.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_logging_global.py @@ -23,9 +23,9 @@ __metaclass__ = type from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_logging_global -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr_n540.py b/tests/unit/modules/network/iosxr/test_iosxr_n540.py index d2820cfa1..e7ec26877 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_n540.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_n540.py @@ -22,15 +22,15 @@ __metaclass__ = type from os import path +from unittest import TestCase from ansible.module_utils._text import to_bytes, to_text from mock import MagicMock from ansible_collections.cisco.iosxr.plugins.cliconf import iosxr -from ansible_collections.cisco.iosxr.tests.unit.compat import unittest -class TestPluginCLIConfIOSXR(unittest.TestCase): +class TestPluginCLIConfIOSXR(TestCase): """Test class for IOSXR CLI Conf Methods""" def setUp(self): diff --git a/tests/unit/modules/network/iosxr/test_iosxr_netconf.py b/tests/unit/modules/network/iosxr/test_iosxr_netconf.py index 727752948..db1f03449 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_netconf.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_netconf.py @@ -21,8 +21,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_netconf -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr_ntp_global.py b/tests/unit/modules/network/iosxr/test_iosxr_ntp_global.py index 702e2a007..e9e0e66fd 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_ntp_global.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_ntp_global.py @@ -23,9 +23,9 @@ __metaclass__ = type from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_ntp_global -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py b/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py index 5b967be00..f5030c703 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py @@ -8,8 +8,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_ospf_interfaces -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py b/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py index b51727dbd..3d4e26298 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py @@ -8,8 +8,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_ospfv2 -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py b/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py index 23c9d071b..447323e7f 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py @@ -8,8 +8,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_ospfv3 -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_ping.py b/tests/unit/modules/network/iosxr/test_iosxr_ping.py index d0ceda0fb..b5701c655 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_ping.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_ping.py @@ -9,9 +9,9 @@ __metaclass__ = type from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_ping -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr_prefix_lists.py b/tests/unit/modules/network/iosxr/test_iosxr_prefix_lists.py index 6dca5d920..9c2f895ac 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_prefix_lists.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_prefix_lists.py @@ -23,9 +23,9 @@ __metaclass__ = type from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_prefix_lists -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr_snmp_server.py b/tests/unit/modules/network/iosxr/test_iosxr_snmp_server.py index 148625190..eaad485d8 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_snmp_server.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_snmp_server.py @@ -23,9 +23,9 @@ __metaclass__ = type from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.iosxr.plugins.modules import iosxr_snmp_server -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule diff --git a/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py b/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py index a185b0c4f..4cce2eb6e 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py @@ -8,8 +8,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_static_routes -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_system.py b/tests/unit/modules/network/iosxr/test_iosxr_system.py index 253725979..973f07066 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_system.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_system.py @@ -21,8 +21,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_system -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_user.py b/tests/unit/modules/network/iosxr/test_iosxr_user.py index 0d783d4cd..0ab53a529 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_user.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_user.py @@ -21,8 +21,9 @@ __metaclass__ = type +from unittest.mock import patch + from ansible_collections.cisco.iosxr.plugins.modules import iosxr_user -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args from .iosxr_module import TestIosxrModule, load_fixture diff --git a/tests/unit/modules/network/iosxr/test_iosxr_utils.py b/tests/unit/modules/network/iosxr/test_iosxr_utils.py index 7707adf41..c63e57030 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_utils.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_utils.py @@ -7,11 +7,13 @@ __metaclass__ = type + +from unittest import TestCase + from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.utils.utils import Version -from ansible_collections.cisco.iosxr.tests.unit.compat import unittest -class TestIosxrUtils(unittest.TestCase): +class TestIosxrUtils(TestCase): def setUp(self): pass diff --git a/tests/unit/modules/utils.py b/tests/unit/modules/utils.py index d63a86922..87be9cf8e 100644 --- a/tests/unit/modules/utils.py +++ b/tests/unit/modules/utils.py @@ -4,12 +4,12 @@ __metaclass__ = type import json +from unittest import TestCase +from unittest.mock import patch + from ansible.module_utils import basic from ansible.module_utils._text import to_bytes -from ansible_collections.cisco.iosxr.tests.unit.compat import unittest -from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch - def set_module_args(args): if "_ansible_remote_tmp" not in args: @@ -40,7 +40,7 @@ def fail_json(*args, **kwargs): raise AnsibleFailJson(kwargs) -class ModuleTestCase(unittest.TestCase): +class ModuleTestCase(TestCase): def setUp(self): self.mock_module = patch.multiple( basic.AnsibleModule, diff --git a/tox.ini b/tox.ini index 6ada631cb..7dbe41e8f 100644 --- a/tox.ini +++ b/tox.ini @@ -28,4 +28,4 @@ show-source = True ignore = E123,E125,E203,E402,E501,E741,F401,F811,F841,W503 max-line-length = 160 builtins = _ -exclude = .git,.tox,tests/unit/compat/ +exclude = .git,.tox From f7335f6a038abc8db4d1ccdafe82179171c39c18 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> Date: Wed, 27 Mar 2024 12:31:24 +0530 Subject: [PATCH 08/11] Remove deprecated module (#479) * removes deprecated modules * add changelog * review changes * remove meta runtimes * changelog update * pylint errors * undo compat & other 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> --- README.md | 1 - changelogs/fragments/remove_deprecated.yaml | 5 + docs/cisco.iosxr.iosxr_logging_module.rst | 538 ------- meta/runtime.yml | 9 - plugins/modules/iosxr_logging.py | 1270 ----------------- .../targets/iosxr_logging/defaults/main.yaml | 3 - .../targets/iosxr_logging/meta/main.yaml | 3 - .../targets/iosxr_logging/tasks/cli.yaml | 24 - .../targets/iosxr_logging/tasks/main.yaml | 6 - .../targets/iosxr_logging/tasks/netconf.yaml | 24 - .../iosxr_logging/tests/cli/basic.yaml | 140 -- .../iosxr_logging/tests/netconf/basic.yaml | 208 --- 12 files changed, 5 insertions(+), 2226 deletions(-) create mode 100644 changelogs/fragments/remove_deprecated.yaml delete mode 100644 docs/cisco.iosxr.iosxr_logging_module.rst delete mode 100644 plugins/modules/iosxr_logging.py delete mode 100644 tests/integration/targets/iosxr_logging/defaults/main.yaml delete mode 100644 tests/integration/targets/iosxr_logging/meta/main.yaml delete mode 100644 tests/integration/targets/iosxr_logging/tasks/cli.yaml delete mode 100644 tests/integration/targets/iosxr_logging/tasks/main.yaml delete mode 100644 tests/integration/targets/iosxr_logging/tasks/netconf.yaml delete mode 100644 tests/integration/targets/iosxr_logging/tests/cli/basic.yaml delete mode 100644 tests/integration/targets/iosxr_logging/tests/netconf/basic.yaml diff --git a/README.md b/README.md index a0faec864..d3e158bba 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ Name | Description [cisco.iosxr.iosxr_lag_interfaces](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_lag_interfaces_module.rst)|Resource module to configure LAG interfaces. [cisco.iosxr.iosxr_lldp_global](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_lldp_global_module.rst)|Resource module to configure LLDP. [cisco.iosxr.iosxr_lldp_interfaces](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_lldp_interfaces_module.rst)|Resource module to configure LLDP interfaces. -[cisco.iosxr.iosxr_logging](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_logging_module.rst)|(deprecated, removed after 2023-08-01) Configuration management of system logging services on network devices [cisco.iosxr.iosxr_logging_global](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_logging_global_module.rst)|Resource module to configure logging. [cisco.iosxr.iosxr_netconf](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_netconf_module.rst)|Configures NetConf sub-system service on Cisco IOS-XR devices [cisco.iosxr.iosxr_ntp_global](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_ntp_global_module.rst)|Resource module to configure NTP. diff --git a/changelogs/fragments/remove_deprecated.yaml b/changelogs/fragments/remove_deprecated.yaml new file mode 100644 index 000000000..29600e2d9 --- /dev/null +++ b/changelogs/fragments/remove_deprecated.yaml @@ -0,0 +1,5 @@ +--- +major_changes: + - "This release removes the iosxr_logging deprecated module from this collection in favour of iosxr_logging_global module." +removed_features: + - The iosxr_logging module has been removed with this release. diff --git a/docs/cisco.iosxr.iosxr_logging_module.rst b/docs/cisco.iosxr.iosxr_logging_module.rst deleted file mode 100644 index c75f0dc7d..000000000 --- a/docs/cisco.iosxr.iosxr_logging_module.rst +++ /dev/null @@ -1,538 +0,0 @@ -.. _cisco.iosxr.iosxr_logging_module: - - -************************* -cisco.iosxr.iosxr_logging -************************* - -**(deprecated, removed after 2023-08-01) Configuration management of system logging services on network devices** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - -DEPRECATED ----------- -:Removed in collection release after 2023-08-01 -:Why: Updated module released with more functionality. -:Alternative: iosxr_logging_global - - - -Synopsis --------- -- This module provides declarative management configuration of system logging (syslog) on Cisco IOS XR devices. - - - -Requirements ------------- -The below requirements are needed on the host that executes this module. - -- ncclient >= 0.5.3 when using netconf -- lxml >= 4.1.1 when using netconf - - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ParameterChoices/DefaultsComments
    -
    - aggregate - -
    - list - / elements=dictionary -
    -
    - -
    List of syslog logging configuration definitions.
    -
    -
    - dest - -
    - string -
    -
    -
      Choices: -
    • host
    • -
    • console
    • -
    • monitor
    • -
    • buffered
    • -
    • file
    • -
    -
    -
    Destination for system logging (syslog) messages.
    -
    -
    - facility - -
    - string -
    -
    - -
    To configure the type of syslog facility in which system logging (syslog) messages are sent to syslog servers Optional config for dest = host
    -
    -
    - hostnameprefix - -
    - string -
    -
    - -
    To append a hostname prefix to system logging (syslog) messages logged to syslog servers. Optional config for dest = host
    -
    -
    - level - -
    - string -
    -
    -
      Choices: -
    • emergencies
    • -
    • alerts
    • -
    • critical
    • -
    • errors
    • -
    • warning
    • -
    • notifications
    • -
    • informational
    • -
    • debugging
    • -
    -
    -
    Specifies the severity level for the logging.
    -

    aliases: severity
    -
    -
    - name - -
    - string -
    -
    - -
    When dest = file name indicates file-name
    -
    When dest = host name indicates the host-name or ip-address of syslog server.
    -
    -
    - path - -
    - string -
    -
    - -
    Set file path.
    -
    -
    - size - -
    - integer -
    -
    - -
    Size of buffer when dest = buffered. The acceptable value is in the range 307200 to 125000000 bytes. Default 307200
    -
    Size of file when dest = file. The acceptable value is in the range 1 to 2097152KB. Default 2 GB
    -
    -
    - state - -
    - string -
    -
    -
      Choices: -
    • present
    • -
    • absent
    • -
    -
    -
    Existential state of the logging configuration on the node.
    -
    -
    - vrf - -
    - string -
    -
    - -
    vrf name when syslog server is configured, dest = host
    -
    -
    - dest - -
    - string -
    -
    -
      Choices: -
    • host
    • -
    • console
    • -
    • monitor
    • -
    • buffered
    • -
    • file
    • -
    -
    -
    Destination for system logging (syslog) messages.
    -
    -
    - facility - -
    - string -
    -
    - Default:
    "local7"
    -
    -
    To configure the type of syslog facility in which system logging (syslog) messages are sent to syslog servers Optional config for dest = host
    -
    -
    - hostnameprefix - -
    - string -
    -
    - -
    To append a hostname prefix to system logging (syslog) messages logged to syslog servers. Optional config for dest = host
    -
    -
    - level - -
    - string -
    -
    -
      Choices: -
    • emergencies
    • -
    • alerts
    • -
    • critical
    • -
    • errors
    • -
    • warning
    • -
    • notifications
    • -
    • informational
    • -
    • debugging ←
    • -
    -
    -
    Specifies the severity level for the logging.
    -

    aliases: severity
    -
    -
    - name - -
    - string -
    -
    - -
    When dest = file name indicates file-name
    -
    When dest = host name indicates the host-name or ip-address of syslog server.
    -
    -
    - path - -
    - string -
    -
    - -
    Set file path.
    -
    -
    - size - -
    - integer -
    -
    - -
    Size of buffer when dest = buffered. The acceptable value is in the range 307200 to 125000000 bytes. Default 307200
    -
    Size of file when dest = file. The acceptable value is in the range 1 to 2097152KB. Default 2 GB
    -
    -
    - state - -
    - string -
    -
    -
      Choices: -
    • present ←
    • -
    • absent
    • -
    -
    -
    Existential state of the logging configuration on the node.
    -
    -
    - vrf - -
    - string -
    -
    - Default:
    "default"
    -
    -
    vrf name when syslog server is configured, dest = host
    -
    -
    - - -Notes ------ - -.. note:: - - This module works with connection ``network_cli`` and ``netconf``. See `the IOS-XR Platform Options <../network/user_guide/platform_iosxr.html>`_. - - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` - - For more information on using Ansible to manage Cisco devices see the `Cisco integration page `_. - - - -Examples --------- - -.. code-block:: yaml - - - name: configure logging for syslog server host - cisco.iosxr.iosxr_logging: - dest: host - name: 10.10.10.1 - level: critical - state: present - - - name: add hostnameprefix configuration - cisco.iosxr.iosxr_logging: - hostnameprefix: host1 - state: absent - - - name: add facility configuration - cisco.iosxr.iosxr_logging: - facility: local1 - state: present - - - name: configure console logging level - cisco.iosxr.iosxr_logging: - dest: console - level: debugging - state: present - - - name: configure monitor logging level - cisco.iosxr.iosxr_logging: - dest: monitor - level: errors - state: present - - - name: configure syslog to a file - cisco.iosxr.iosxr_logging: - dest: file - name: file_name - size: 2048 - level: errors - state: present - - - name: configure buffered logging with size - cisco.iosxr.iosxr_logging: - dest: buffered - size: 5100000 - - - name: Configure logging using aggregate - cisco.iosxr.iosxr_logging: - aggregate: - - {dest: console, level: warning} - - {dest: buffered, size: 4800000} - - {dest: file, name: file3, size: 2048} - - {dest: host, name: host3, level: critical} - - - name: Delete logging using aggregate - cisco.iosxr.iosxr_logging: - aggregate: - - {dest: console, level: warning} - - {dest: buffered, size: 4800000} - - {dest: file, name: file3, size: 2048} - - {dest: host, name: host3, level: critical} - state: absent - - - -Return Values -------------- -Common return values are documented `here `_, the following are the fields unique to this module: - -.. raw:: html - - - - - - - - - - - - - - - - - -
    KeyReturnedDescription
    -
    - commands - -
    - list -
    -
    always (empty list when no commands to send) -
    The list of configuration mode commands to send to the device
    -
    -
    Sample:
    -
    ['logging 10.10.10.1 vrf default severity debugging', 'logging facility local7', 'logging hostnameprefix host1', 'logging console critical', 'logging buffered 2097153', 'logging buffered warnings', 'logging monitor errors', 'logging file log_file maxfilesize 1024 severity info']
    -
    -
    - xml - -
    - list -
    -
    always (empty list when no xml rpc to send) -
    NetConf rpc xml sent to device with transport netconf
    -
    -
    Sample:
    -
    ['<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> <syslog xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-infra-syslog-cfg"> <files> <file xc:operation="delete"> <file-name>file1</file-name> <file-log-attributes> <max-file-size>2097152</max-file-size> <severity>2</severity> </file-log-attributes> </file> </files> </syslog> </config>']
    -
    -

    - - -Status ------- - - -- This module will be removed in a release after 2023-08-01. *[deprecated]* -- For more information see `DEPRECATED`_. - - -Authors -~~~~~~~ - -- Trishna Guha (@trishnaguha) -- Kedar Kekan (@kedarX) diff --git a/meta/runtime.yml b/meta/runtime.yml index eb381faa7..5bf8ab65f 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -30,15 +30,6 @@ plugin_routing: redirect: cisco.iosxr.iosxr_lldp_global lldp_interfaces: redirect: cisco.iosxr.iosxr_lldp_interfaces - logging: - redirect: cisco.iosxr.iosxr_logging - deprecation: - removal_date: "2023-08-01" - warning_text: See the plugin documentation for more details - iosxr_logging: - deprecation: - removal_date: "2023-08-01" - warning_text: See the plugin documentation for more details logging_global: redirect: cisco.iosxr.iosxr_logging_global netconf: diff --git a/plugins/modules/iosxr_logging.py b/plugins/modules/iosxr_logging.py deleted file mode 100644 index abca845df..000000000 --- a/plugins/modules/iosxr_logging.py +++ /dev/null @@ -1,1270 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# (c) 2017, Ansible by Red Hat, inc -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -from __future__ import absolute_import, division, print_function - - -__metaclass__ = type - - -DOCUMENTATION = """ -module: iosxr_logging -author: -- Trishna Guha (@trishnaguha) -- Kedar Kekan (@kedarX) -short_description: (deprecated, removed after 2023-08-01) Configuration management of system logging services on network - devices -description: -- This module provides declarative management configuration of system logging (syslog) - on Cisco IOS XR devices. -version_added: 1.0.0 -deprecated: - alternative: iosxr_logging_global - why: Updated module released with more functionality. - removed_at_date: '2023-08-01' -requirements: -- ncclient >= 0.5.3 when using netconf -- lxml >= 4.1.1 when using netconf -notes: -- This module works with connection C(network_cli) and C(netconf). See L(the IOS-XR - Platform Options,../network/user_guide/platform_iosxr.html). -options: - dest: - description: - - Destination for system logging (syslog) messages. - choices: - - host - - console - - monitor - - buffered - - file - type: str - name: - description: - - When C(dest) = I(file) name indicates file-name - - When C(dest) = I(host) name indicates the host-name or ip-address of syslog - server. - type: str - vrf: - description: - - vrf name when syslog server is configured, C(dest) = C(host) - type: str - default: default - size: - description: - - Size of buffer when C(dest) = C(buffered). The acceptable value is in the range - I(307200 to 125000000 bytes). Default 307200 - - Size of file when C(dest) = C(file). The acceptable value is in the range I(1 - to 2097152)KB. Default 2 GB - type: int - facility: - description: - - To configure the type of syslog facility in which system logging (syslog) messages - are sent to syslog servers Optional config for C(dest) = C(host) - default: local7 - type: str - hostnameprefix: - description: - - To append a hostname prefix to system logging (syslog) messages logged to syslog - servers. Optional config for C(dest) = C(host) - type: str - level: - description: - - Specifies the severity level for the logging. - type: str - default: debugging - aliases: - - severity - choices: ["emergencies", "alerts", "critical", "errors", "warning", "notifications", "informational", "debugging"] - path: - description: - Set file path. - type: str - aggregate: - description: List of syslog logging configuration definitions. - type: list - elements: dict - suboptions: - dest: - description: - - Destination for system logging (syslog) messages. - choices: - - host - - console - - monitor - - buffered - - file - type: str - name: - description: - - When C(dest) = I(file) name indicates file-name - - When C(dest) = I(host) name indicates the host-name or ip-address of syslog - server. - type: str - path: - description: - Set file path. - type: str - vrf: - description: - - vrf name when syslog server is configured, C(dest) = C(host) - type: str - size: - description: - - Size of buffer when C(dest) = C(buffered). The acceptable value is in the range - I(307200 to 125000000 bytes). Default 307200 - - Size of file when C(dest) = C(file). The acceptable value is in the range I(1 - to 2097152)KB. Default 2 GB - type: int - facility: - description: - - To configure the type of syslog facility in which system logging (syslog) messages - are sent to syslog servers Optional config for C(dest) = C(host) - type: str - hostnameprefix: - description: - - To append a hostname prefix to system logging (syslog) messages logged to syslog - servers. Optional config for C(dest) = C(host) - type: str - level: - description: - - Specifies the severity level for the logging. - type: str - aliases: - - severity - choices: ["emergencies", "alerts", "critical", "errors", "warning", "notifications", "informational", "debugging"] - state: - description: - - Existential state of the logging configuration on the node. - choices: - - present - - absent - type: str - state: - description: - - Existential state of the logging configuration on the node. - default: present - choices: - - present - - absent - type: str -extends_documentation_fragment: -- cisco.iosxr.iosxr -""" - -EXAMPLES = """ -- name: configure logging for syslog server host - cisco.iosxr.iosxr_logging: - dest: host - name: 10.10.10.1 - level: critical - state: present - -- name: add hostnameprefix configuration - cisco.iosxr.iosxr_logging: - hostnameprefix: host1 - state: absent - -- name: add facility configuration - cisco.iosxr.iosxr_logging: - facility: local1 - state: present - -- name: configure console logging level - cisco.iosxr.iosxr_logging: - dest: console - level: debugging - state: present - -- name: configure monitor logging level - cisco.iosxr.iosxr_logging: - dest: monitor - level: errors - state: present - -- name: configure syslog to a file - cisco.iosxr.iosxr_logging: - dest: file - name: file_name - size: 2048 - level: errors - state: present - -- name: configure buffered logging with size - cisco.iosxr.iosxr_logging: - dest: buffered - size: 5100000 - -- name: Configure logging using aggregate - cisco.iosxr.iosxr_logging: - aggregate: - - {dest: console, level: warning} - - {dest: buffered, size: 4800000} - - {dest: file, name: file3, size: 2048} - - {dest: host, name: host3, level: critical} - -- name: Delete logging using aggregate - cisco.iosxr.iosxr_logging: - aggregate: - - {dest: console, level: warning} - - {dest: buffered, size: 4800000} - - {dest: file, name: file3, size: 2048} - - {dest: host, name: host3, level: critical} - state: absent -""" - -RETURN = """ -commands: - description: The list of configuration mode commands to send to the device - returned: always (empty list when no commands to send) - type: list - sample: - - logging 10.10.10.1 vrf default severity debugging - - logging facility local7 - - logging hostnameprefix host1 - - logging console critical - - logging buffered 2097153 - - logging buffered warnings - - logging monitor errors - - logging file log_file maxfilesize 1024 severity info -xml: - description: NetConf rpc xml sent to device with transport C(netconf) - returned: always (empty list when no xml rpc to send) - type: list - sample: - - ' - - - - file1 - - 2097152 - 2 - - - - - ' -""" - -import collections -import re - -from copy import deepcopy - -from ansible.module_utils._text import to_text -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - remove_default_spec, -) - -from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.iosxr import ( - build_xml, - etree_find, - etree_findall, - get_capabilities, - get_config, - get_os_version, - is_cliconf, - is_netconf, - load_config, -) -from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.utils.utils import Version - - -severity_level = { - "emergency": "0", - "alert": "1", - "critical": "2", - "error": "3", - "warning": "4", - "notice": "5", - "info": "6", - "debug": "7", - "disable": "15", -} - -severity_transpose = { - "emergencies": "emergency", - "alerts": "alert", - "critical": "critical", - "errors": "error", - "warning": "warning", - "notifications": "notice", - "informational": "info", - "debugging": "debug", -} - - -class ConfigBase(object): - def __init__(self, module): - self._flag = None - self._module = module - self._result = {"changed": False, "warnings": []} - self._want = list() - self._have = list() - - def validate_size(self, value, type=None): - if value: - if type == "buffer": - if value and not int(307200) <= value <= int(125000000): - self._module.fail_json( - msg="buffer size must be between 307200 and 125000000", - ) - elif type == "file": - if value and not int(1) <= value <= int(2097152): - self._module.fail_json( - msg="file size must be between 1 and 2097152", - ) - return value - - def map_params_to_obj(self, required_if=None): - aggregate = self._module.params.get("aggregate") - if aggregate: - for item in aggregate: - for key in item: - if item.get(key) is None: - item[key] = self._module.params[key] - - d = item.copy() - - if d["dest"] not in ("host", "file"): - d["name"] = None - - if d["dest"] == "buffered": - if d["size"] is not None: - d["size"] = str( - self.validate_size(d["size"], "buffer"), - ) - else: - d["size"] = str(307200) - elif d["dest"] == "file": - if d["size"] is not None: - d["size"] = str(self.validate_size(d["size"], "file")) - else: - d["size"] = str(2097152) - else: - d["size"] = None - - if self._flag == "NC": - d["level"] = severity_transpose[d["level"]] - - self._want.append(d) - - else: - params = self._module.params - if params["dest"] not in ("host", "file"): - params["name"] = None - - if params["dest"] == "buffered": - if params["size"] is not None: - params["size"] = str( - self.validate_size(params["size"], "buffer"), - ) - else: - params["size"] = str(307200) - elif params["dest"] == "file": - if params["size"] is not None: - params["size"] = str( - self.validate_size(params["size"], "file"), - ) - else: - params["size"] = str(2097152) - else: - params["size"] = None - - if self._flag == "NC": - params["level"] = severity_transpose[params["level"]] - - self._want.append( - { - "dest": params["dest"], - "name": params["name"], - "vrf": params["vrf"], - "size": params["size"], - "path": params["path"], - "facility": params["facility"], - "level": params["level"], - "hostnameprefix": params["hostnameprefix"], - "state": params["state"], - }, - ) - - -class CliConfiguration(ConfigBase): - def __init__(self, module): - super(CliConfiguration, self).__init__(module) - self._file_list = set() - self._host_list = set() - - def map_obj_to_commands(self, os_version): - commands = list() - for want_item in self._want: - dest = want_item["dest"] - name = want_item["name"] - size = want_item["size"] - path = want_item["path"] - facility = want_item["facility"] - level = want_item["level"] - vrf = want_item["vrf"] - hostnameprefix = want_item["hostnameprefix"] - state = want_item["state"] - del want_item["state"] - - have_size = None - have_console_level = None - have_monitor_level = None - have_prefix = None - have_facility = None - - for item in self._have: - if item["dest"] == "buffered": - have_size = item["size"] - if item["dest"] == "console": - have_console_level = item["level"] - if item["dest"] == "monitor": - have_monitor_level = item["level"] - if item["dest"] is None and item["hostnameprefix"] is not None: - have_prefix = item["hostnameprefix"] - if ( - item["dest"] is None - and item["hostnameprefix"] is None - and item["facility"] is not None - ): - have_facility = item["facility"] - - if state == "absent": - if dest == "host" and name in self._host_list: - commands.append("no logging {0} vrf {1}".format(name, vrf)) - elif dest == "file" and name in self._file_list: - commands.append("no logging file {0}".format(name)) - elif dest == "console" and have_console_level is not None: - commands.append("no logging {0}".format(dest)) - elif dest == "monitor" and have_monitor_level: - commands.append("no logging {0}".format(dest)) - elif dest == "buffered" and have_size: - commands.append("no logging {0}".format(dest)) - - if dest is None and hostnameprefix is not None and have_prefix == hostnameprefix: - commands.append( - "no logging hostnameprefix {0}".format(hostnameprefix), - ) - if dest is None and facility is not None and have_facility == facility: - commands.append("no logging facility {0}".format(facility)) - - if state == "present": - if dest == "host" and name not in self._host_list: - if level == "errors" or level == "informational": - level = severity_transpose[level] - commands.append( - "logging {0} vrf {1} severity {2}".format( - name, - vrf, - level, - ), - ) - elif dest == "file" and name not in self._file_list: - if level == "errors" or level == "informational": - level = severity_transpose[level] - if os_version and Version(os_version) > Version("7.0"): - commands.append( - "logging file {0} path {1} maxfilesize {2} severity {3}".format( - name, - path, - size, - level, - ), - ) - else: - commands.append( - "logging file {0} maxfilesize {1} severity {2}".format( - name, - size, - level, - ), - ) - elif dest == "buffered" and ( - have_size is None or (have_size is not None and size != have_size) - ): - commands.append("logging buffered {0}".format(size)) - elif dest == "console" and ( - have_console_level is None - or (have_console_level is not None and have_console_level != level) - ): - commands.append("logging console {0}".format(level)) - elif dest == "monitor" and ( - have_monitor_level is None - or (have_monitor_level is not None and have_monitor_level != level) - ): - commands.append("logging monitor {0}".format(level)) - - if ( - dest is None - and hostnameprefix is not None - and ( - have_prefix is None - or (have_prefix is not None and hostnameprefix != have_prefix) - ) - ): - commands.append( - "logging hostnameprefix {0}".format(hostnameprefix), - ) - if dest is None and hostnameprefix is None and facility != have_facility: - commands.append("logging facility {0}".format(facility)) - - self._result["commands"] = commands - if commands: - commit = not self._module.check_mode - diff = load_config(self._module, commands, commit=commit) - if diff: - self._result["diff"] = dict(prepared=diff) - self._result["changed"] = True - - def parse_facility(self, line): - match = re.search(r"logging facility (\S+)", line, re.M) - facility = None - if match: - facility = match.group(1) - - return facility - - def parse_size(self, line, dest): - size = None - - if dest == "buffered": - match = re.search(r"logging buffered (\S+)", line, re.M) - if match: - try: - int_size = int(match.group(1)) - except ValueError: - int_size = None - - if int_size is not None: - if isinstance(int_size, int): - size = str(match.group(1)) - if dest == "file": - match = re.search( - r"logging file (\S+) (path\s\S+\s)?maxfilesize (\S+)", - line, - re.M, - ) - if match: - try: - if "path" in line: - int_size = int(match.group(2)) - else: - int_size = int(match.group(1)) - except ValueError: - int_size = None - - if int_size is not None: - if isinstance(int_size, int): - size = str(int_size) - - return size - - def parse_path(self, line, dest): - path = None - - if dest == "file": - match = re.search(r"logging file (\S+) (path\s\S+\s)", line, re.M) - if match: - try: - path = to_text( - match.group(2), - errors="surrogate_or_strict", - ) - except ValueError: - path = None - - return path - - def parse_hostnameprefix(self, line): - prefix = None - match = re.search(r"logging hostnameprefix (\S+)", line, re.M) - if match: - prefix = match.group(1) - return prefix - - def parse_name(self, line, dest): - name = None - if dest == "file": - match = re.search(r"logging file (\S+)", line, re.M) - if match: - name = match.group(1) - elif dest == "host": - match = re.search(r"logging (\S+)", line, re.M) - if match: - name = match.group(1) - - return name - - def parse_level(self, line, dest): - level_group = ( - "emergencies", - "alerts", - "critical", - "errors", - "warning", - "notifications", - "informational", - "debugging", - ) - - level = None - match = re.search(r"logging {0} (\S+)".format(dest), line, re.M) - if match: - if match.group(1) in level_group: - level = match.group(1) - - return level - - def parse_dest(self, line, group): - dest_group = ("console", "monitor", "buffered", "file") - dest = None - if group in dest_group: - dest = group - elif "vrf" in line: - dest = "host" - - return dest - - def parse_vrf(self, line, dest): - vrf = None - if dest == "host": - match = re.search(r"logging (\S+) vrf (\S+)", line, re.M) - if match: - vrf = match.group(2) - return vrf - - def map_config_to_obj(self): - data = get_config(self._module, config_filter="logging") - lines = data.split("\n") - - for line in lines: - match = re.search(r"logging (\S+)", line, re.M) - if match: - dest = self.parse_dest(line, match.group(1)) - name = self.parse_name(line, dest) - if dest == "host" and name is not None: - self._host_list.add(name) - if dest == "file" and name is not None: - self._file_list.add(name) - - self._have.append( - { - "dest": dest, - "name": name, - "size": self.parse_size(line, dest), - "path": self.parse_path(line, dest), - "facility": self.parse_facility(line), - "level": self.parse_level(line, dest), - "vrf": self.parse_vrf(line, dest), - "hostnameprefix": self.parse_hostnameprefix(line), - }, - ) - - def run(self, os_version): - self.map_params_to_obj() - self.map_config_to_obj() - self.map_obj_to_commands(os_version) - - return self._result - - -class NCConfiguration(ConfigBase): - def __init__(self, module): - super(NCConfiguration, self).__init__(module) - self._flag = "NC" - self._log_file_meta = collections.OrderedDict() - self._log_host_meta = collections.OrderedDict() - self._log_console_meta = collections.OrderedDict() - self._log_monitor_meta = collections.OrderedDict() - self._log_buffered_meta = collections.OrderedDict() - self._log_facility_meta = collections.OrderedDict() - self._log_prefix_meta = collections.OrderedDict() - - def map_obj_to_xml_rpc(self, os_version): - file_attribute_path = "file-log-attributes" - if os_version and Version(os_version) > Version("7.0.0"): - file_attribute_path = "file-specification" - self._log_file_meta.update( - [ - ( - "files", - { - "xpath": "syslog/files", - "tag": True, - "operation": "edit", - }, - ), - ( - "file", - { - "xpath": "syslog/files/file", - "tag": True, - "operation": "edit", - "attrib": "operation", - }, - ), - ( - "a:name", - { - "xpath": "syslog/files/file/file-name", - "operation": "edit", - }, - ), - ( - "file-attrib", - { - "xpath": "syslog/files/file/" + file_attribute_path, - "tag": True, - "operation": "edit", - }, - ), - ( - "a:size", - { - "xpath": "syslog/files/file/" + file_attribute_path + "/max-file-size", - "operation": "edit", - }, - ), - ( - "a:level", - { - "xpath": "syslog/files/file/" + file_attribute_path + "/severity", - "operation": "edit", - }, - ), - ( - "a:path", - { - "xpath": "syslog/files/file/" + file_attribute_path + "/path", - "operation": "edit", - }, - ), - ], - ) - else: - self._log_file_meta.update( - [ - ( - "files", - { - "xpath": "syslog/files", - "tag": True, - "operation": "edit", - }, - ), - ( - "file", - { - "xpath": "syslog/files/file", - "tag": True, - "operation": "edit", - "attrib": "operation", - }, - ), - ( - "a:name", - { - "xpath": "syslog/files/file/file-name", - "operation": "edit", - }, - ), - ( - "file-attrib", - { - "xpath": "syslog/files/file/" + file_attribute_path, - "tag": True, - "operation": "edit", - }, - ), - ( - "a:size", - { - "xpath": "syslog/files/file/" + file_attribute_path + "/max-file-size", - "operation": "edit", - }, - ), - ( - "a:level", - { - "xpath": "syslog/files/file/" + file_attribute_path + "/severity", - "operation": "edit", - }, - ), - ], - ) - self._log_host_meta.update( - [ - ( - "host-server", - { - "xpath": "syslog/host-server", - "tag": True, - "operation": "edit", - }, - ), - ( - "vrfs", - { - "xpath": "syslog/host-server/vrfs", - "tag": True, - "operation": "edit", - }, - ), - ( - "vrf", - { - "xpath": "syslog/host-server/vrfs/vrf", - "tag": True, - "operation": "edit", - }, - ), - ( - "a:vrf", - { - "xpath": "syslog/host-server/vrfs/vrf/vrf-name", - "operation": "edit", - }, - ), - ( - "ipv4s", - { - "xpath": "syslog/host-server/vrfs/vrf/ipv4s", - "tag": True, - "operation": "edit", - }, - ), - ( - "ipv4", - { - "xpath": "syslog/host-server/vrfs/vrf/ipv4s/ipv4", - "tag": True, - "operation": "edit", - "attrib": "operation", - }, - ), - ( - "a:name", - { - "xpath": "syslog/host-server/vrfs/vrf/ipv4s/ipv4/address", - "operation": "edit", - }, - ), - ( - "ipv4-sev", - { - "xpath": "syslog/host-server/vrfs/vrf/ipv4s/ipv4/ipv4-severity-port", - "tag": True, - "operation": "edit", - }, - ), - ( - "a:level", - { - "xpath": "syslog/host-server/vrfs/vrf/ipv4s/ipv4/ipv4-severity-port/severity", - "operation": "edit", - }, - ), - ], - ) - self._log_console_meta.update( - [ - ( - "a:enable-console", - { - "xpath": "syslog/enable-console-logging", - "operation": "edit", - "attrib": "operation", - }, - ), - ( - "console", - { - "xpath": "syslog/console-logging", - "tag": True, - "operation": "edit", - "attrib": "operation", - }, - ), - ( - "a:console-level", - { - "xpath": "syslog/console-logging/logging-level", - "operation": "edit", - }, - ), - ], - ) - self._log_monitor_meta.update( - [ - ( - "monitor", - { - "xpath": "syslog/monitor-logging", - "tag": True, - "operation": "edit", - "attrib": "operation", - }, - ), - ( - "a:monitor-level", - { - "xpath": "syslog/monitor-logging/logging-level", - "operation": "edit", - }, - ), - ], - ) - self._log_buffered_meta.update( - [ - ( - "buffered", - { - "xpath": "syslog/buffered-logging", - "tag": True, - "operation": "edit", - "attrib": "operation", - }, - ), - ( - "a:size", - { - "xpath": "syslog/buffered-logging/buffer-size", - "operation": "edit", - }, - ), - ( - "a:level", - { - "xpath": "syslog/buffered-logging/logging-level", - "operation": "edit", - }, - ), - ], - ) - self._log_facility_meta.update( - [ - ( - "facility", - { - "xpath": "syslog/logging-facilities", - "tag": True, - "operation": "edit", - "attrib": "operation", - }, - ), - ( - "a:facility", - { - "xpath": "syslog/logging-facilities/facility-level", - "operation": "edit", - }, - ), - ], - ) - self._log_prefix_meta.update( - [ - ( - "a:hostnameprefix", - { - "xpath": "syslog/host-name-prefix", - "operation": "edit", - "attrib": "operation", - }, - ), - ], - ) - - state = self._module.params["state"] - - _get_filter = build_xml("syslog", opcode="filter") - running = get_config( - self._module, - source="running", - config_filter=_get_filter, - ) - - file_ele = etree_findall(running, "file") - file_list = list() - if len(file_ele): - for file in file_ele: - file_name = etree_find(file, "file-name") - file_list.append( - file_name.text if file_name is not None else None, - ) - vrf_ele = etree_findall(running, "vrf") - host_list = list() - for vrf in vrf_ele: - host_ele = etree_findall(vrf, "ipv4") - for host in host_ele: - host_name = etree_find(host, "address") - host_list.append( - host_name.text if host_name is not None else None, - ) - - console_ele = etree_find(running, "console-logging") - console_level = ( - etree_find(console_ele, "logging-level") if console_ele is not None else None - ) - have_console = console_level.text if console_level is not None else None - - monitor_ele = etree_find(running, "monitor-logging") - monitor_level = ( - etree_find(monitor_ele, "logging-level") if monitor_ele is not None else None - ) - have_monitor = monitor_level.text if monitor_level is not None else None - - buffered_ele = etree_find(running, "buffered-logging") - buffered_size = ( - etree_find(buffered_ele, "buffer-size") if buffered_ele is not None else None - ) - have_buffered = buffered_size.text if buffered_size is not None else None - - facility_ele = etree_find(running, "logging-facilities") - facility_level = ( - etree_find(facility_ele, "facility-level") if facility_ele is not None else None - ) - have_facility = facility_level.text if facility_level is not None else None - - prefix_ele = etree_find(running, "host-name-prefix") - have_prefix = prefix_ele.text if prefix_ele is not None else None - - file_params = list() - host_params = list() - console_params = dict() - monitor_params = dict() - buffered_params = dict() - facility_params = dict() - prefix_params = dict() - - opcode = None - if state == "absent": - opcode = "delete" - for item in self._want: - if item["dest"] == "file" and item["name"] in file_list: - item["level"] = severity_level[item["level"]] - file_params.append(item) - elif item["dest"] == "host" and item["name"] in host_list: - item["level"] = severity_level[item["level"]] - host_params.append(item) - elif item["dest"] == "console" and have_console: - console_params.update({"console-level": item["level"]}) - elif item["dest"] == "monitor" and have_monitor: - monitor_params.update({"monitor-level": item["level"]}) - elif item["dest"] == "buffered" and have_buffered: - buffered_params["size"] = str(item["size"]) if item["size"] else None - buffered_params["level"] = item["level"] if item["level"] else None - elif ( - item["dest"] is None - and item["hostnameprefix"] is None - and item["facility"] is not None - and have_facility - ): - facility_params.update({"facility": item["facility"]}) - elif item["dest"] is None and item["hostnameprefix"] is not None and have_prefix: - prefix_params.update( - {"hostnameprefix": item["hostnameprefix"]}, - ) - elif state == "present": - opcode = "merge" - for item in self._want: - if item["dest"] == "file": - item["level"] = severity_level[item["level"]] - file_params.append(item) - elif item["dest"] == "host": - item["level"] = severity_level[item["level"]] - host_params.append(item) - elif item["dest"] == "console": - console_params.update({"console-level": item["level"]}) - elif item["dest"] == "monitor": - monitor_params.update({"monitor-level": item["level"]}) - elif item["dest"] == "buffered": - buffered_params["size"] = str(item["size"]) if item["size"] else None - buffered_params["level"] = item["level"] if item["level"] else None - elif ( - item["dest"] is None - and item["hostnameprefix"] is None - and item["facility"] is not None - ): - facility_params.update({"facility": item["facility"]}) - elif item["dest"] is None and item["hostnameprefix"] is not None: - prefix_params.update( - {"hostnameprefix": item["hostnameprefix"]}, - ) - - self._result["xml"] = [] - _edit_filter_list = list() - if opcode: - if len(file_params): - _edit_filter_list.append( - build_xml( - "syslog", - xmap=self._log_file_meta, - params=file_params, - opcode=opcode, - ), - ) - if len(host_params): - _edit_filter_list.append( - build_xml( - "syslog", - xmap=self._log_host_meta, - params=host_params, - opcode=opcode, - ), - ) - if len(console_params): - _edit_filter_list.append( - build_xml( - "syslog", - xmap=self._log_console_meta, - params=console_params, - opcode=opcode, - ), - ) - if len(monitor_params): - _edit_filter_list.append( - build_xml( - "syslog", - xmap=self._log_monitor_meta, - params=monitor_params, - opcode=opcode, - ), - ) - if len(buffered_params): - _edit_filter_list.append( - build_xml( - "syslog", - xmap=self._log_buffered_meta, - params=buffered_params, - opcode=opcode, - ), - ) - if len(facility_params): - _edit_filter_list.append( - build_xml( - "syslog", - xmap=self._log_facility_meta, - params=facility_params, - opcode=opcode, - ), - ) - if len(prefix_params): - _edit_filter_list.append( - build_xml( - "syslog", - xmap=self._log_prefix_meta, - params=prefix_params, - opcode=opcode, - ), - ) - - diff = None - if len(_edit_filter_list): - commit = not self._module.check_mode - diff = load_config( - self._module, - _edit_filter_list, - commit=commit, - running=running, - nc_get_filter=_get_filter, - ) - if diff: - if self._module._diff: - self._result["diff"] = dict(prepared=diff) - - self._result["xml"] = _edit_filter_list - self._result["changed"] = True - - def run(self, os_version): - self.map_params_to_obj() - self.map_obj_to_xml_rpc(os_version) - - return self._result - - -def main(): - """main entry point for module execution""" - element_spec = dict( - dest=dict( - type="str", - choices=["host", "console", "monitor", "buffered", "file"], - ), - name=dict(type="str"), - size=dict(type="int"), - path=dict(type="str"), - vrf=dict(type="str", default="default"), - facility=dict(type="str", default="local7"), - hostnameprefix=dict(type="str"), - level=dict( - type="str", - default="debugging", - aliases=["severity"], - choices=[ - "emergencies", - "alerts", - "critical", - "errors", - "warning", - "notifications", - "informational", - "debugging", - ], - ), - state=dict(default="present", choices=["present", "absent"]), - ) - - aggregate_spec = deepcopy(element_spec) - - # remove default in aggregate spec, to handle common arguments - remove_default_spec(aggregate_spec) - - mutually_exclusive = [("dest", "facility", "hostnameprefix")] - - required_if = [ - ("dest", "host", ["name"]), - ("dest", "file", ["name"]), - ("dest", "buffered", ["size"]), - ("dest", "console", ["level"]), - ("dest", "monitor", ["level"]), - ] - - argument_spec = dict( - aggregate=dict( - type="list", - elements="dict", - options=aggregate_spec, - mutually_exclusive=mutually_exclusive, - required_if=required_if, - ), - ) - - argument_spec.update(element_spec) - - module = AnsibleModule( - argument_spec=argument_spec, - mutually_exclusive=mutually_exclusive, - required_if=required_if, - supports_check_mode=True, - ) - config_object = None - if is_cliconf(module): - config_object = CliConfiguration(module) - os_version = get_os_version(module) - elif is_netconf(module): - config_object = NCConfiguration(module) - os_version = get_capabilities(module).get("device_info").get("network_os_version") - - if config_object: - result = config_object.run(os_version) - module.exit_json(**result) - - -if __name__ == "__main__": - main() diff --git a/tests/integration/targets/iosxr_logging/defaults/main.yaml b/tests/integration/targets/iosxr_logging/defaults/main.yaml deleted file mode 100644 index 9ef5ba516..000000000 --- a/tests/integration/targets/iosxr_logging/defaults/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -testcase: "*" -test_items: [] diff --git a/tests/integration/targets/iosxr_logging/meta/main.yaml b/tests/integration/targets/iosxr_logging/meta/main.yaml deleted file mode 100644 index be631e5d8..000000000 --- a/tests/integration/targets/iosxr_logging/meta/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_iosxr_tests diff --git a/tests/integration/targets/iosxr_logging/tasks/cli.yaml b/tests/integration/targets/iosxr_logging/tasks/cli.yaml deleted file mode 100644 index 88e4708f8..000000000 --- a/tests/integration/targets/iosxr_logging/tasks/cli.yaml +++ /dev/null @@ -1,24 +0,0 @@ ---- -- name: Collect all CLI test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | 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 }}" - loop_control: - loop_var: test_case_to_run - tags: - - network_cli - -- name: Reset connection - ansible.builtin.meta: reset_connection diff --git a/tests/integration/targets/iosxr_logging/tasks/main.yaml b/tests/integration/targets/iosxr_logging/tasks/main.yaml deleted file mode 100644 index 419a6cde6..000000000 --- a/tests/integration/targets/iosxr_logging/tasks/main.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: Include the CLI tasks - ansible.builtin.include_tasks: cli.yaml - -- name: Include the netconf tasks - ansible.builtin.include_tasks: netconf.yaml diff --git a/tests/integration/targets/iosxr_logging/tasks/netconf.yaml b/tests/integration/targets/iosxr_logging/tasks/netconf.yaml deleted file mode 100644 index 26f9ab49a..000000000 --- a/tests/integration/targets/iosxr_logging/tasks/netconf.yaml +++ /dev/null @@ -1,24 +0,0 @@ ---- -- name: Collect all CLI test cases - ansible.builtin.find: - paths: "{{ role_path }}/tests/netconf" - patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost - -- name: Set test_items - ansible.builtin.set_fact: - test_items: "{{ test_cases.files | map(attribute='path') | list }}" - -- name: Run test case (connection=ansible.netcommon.netconf) - ansible.builtin.include_tasks: "{{ test_case_to_run }}" - vars: - ansible_connection: ansible.netcommon.netconf - with_items: "{{ test_items }}" - loop_control: - loop_var: test_case_to_run - tags: - - netconf - -- name: Reset connection - ansible.builtin.meta: reset_connection diff --git a/tests/integration/targets/iosxr_logging/tests/cli/basic.yaml b/tests/integration/targets/iosxr_logging/tests/cli/basic.yaml deleted file mode 100644 index 02280f4a0..000000000 --- a/tests/integration/targets/iosxr_logging/tests/cli/basic.yaml +++ /dev/null @@ -1,140 +0,0 @@ ---- -- name: Remove host logging - cisco.iosxr.iosxr_logging: - dest: host - name: 172.16.0.1 - state: absent - -- name: Remove console logging - register: result - cisco.iosxr.iosxr_logging: - dest: console - state: absent - -- name: Remove buffered logging - register: result - cisco.iosxr.iosxr_logging: - dest: buffered - size: 2097155 - state: absent - -- name: Set up syslog host logging - register: result - cisco.iosxr.iosxr_logging: &id001 - dest: host - name: 172.16.0.1 - level: errors - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"logging 172.16.0.1 vrf default severity error" in result.commands' - -- name: Set up syslog host logging (idempotent) - register: result - cisco.iosxr.iosxr_logging: *id001 -- ansible.builtin.assert: &id003 - that: - - result.changed == false - -- name: Delete/disable syslog host logging - register: result - cisco.iosxr.iosxr_logging: &id002 - dest: host - name: 172.16.0.1 - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - - '"no logging 172.16.0.1 vrf default" in result.commands' - -- name: Delete/disable syslog host logging (idempotent) - register: result - cisco.iosxr.iosxr_logging: *id002 -- ansible.builtin.assert: *id003 -- name: Add console logging with level warning - register: result - cisco.iosxr.iosxr_logging: &id004 - dest: console - level: warning - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"logging console warning" in result.commands' - -- name: Console logging with level warning (idempotent) - register: result - cisco.iosxr.iosxr_logging: *id004 -- ansible.builtin.assert: *id003 -- name: Remove console logging with level warning - register: result - cisco.iosxr.iosxr_logging: - dest: console - level: warning - state: absent - -- ansible.builtin.assert: &id006 - that: - - result.changed == true - -- name: Configure buffered logging size - register: result - cisco.iosxr.iosxr_logging: &id005 - dest: buffered - size: 4800000 - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"logging buffered 4800000" in result.commands' - -- name: Configure buffered logging size (idempotence) - register: result - cisco.iosxr.iosxr_logging: *id005 -- ansible.builtin.assert: *id003 -- name: Remove buffered logging size - register: result - cisco.iosxr.iosxr_logging: - dest: buffered - size: 4800000 - state: absent - -- ansible.builtin.assert: *id006 -- name: Change logging parameters using aggregate - register: result - cisco.iosxr.iosxr_logging: - aggregate: - - dest: console - level: notifications - - - dest: buffered - size: 4700000 - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"logging buffered 4700000" in result.commands' - - '"logging console notifications" in result.commands' - -- name: Remove logging parameters using aggregate - register: result - cisco.iosxr.iosxr_logging: - aggregate: - - dest: console - level: notifications - - - dest: buffered - size: 4700000 - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - - '"no logging console" in result.commands' - - '"no logging buffered" in result.commands' diff --git a/tests/integration/targets/iosxr_logging/tests/netconf/basic.yaml b/tests/integration/targets/iosxr_logging/tests/netconf/basic.yaml deleted file mode 100644 index 2bd05e511..000000000 --- a/tests/integration/targets/iosxr_logging/tests/netconf/basic.yaml +++ /dev/null @@ -1,208 +0,0 @@ ---- -- name: Remove host logging - cisco.iosxr.iosxr_logging: - dest: host - name: 172.16.0.1 - state: absent - -- name: Remove console logging - register: result - cisco.iosxr.iosxr_logging: - dest: console - level: warning - state: absent - -- name: Remove buffered logging - register: result - cisco.iosxr.iosxr_logging: - dest: buffered - size: 2097155 - state: absent - -- name: Set up syslog host logging - register: result - cisco.iosxr.iosxr_logging: &id001 - dest: host - name: 172.16.0.1 - level: errors - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"172.16.0.1" in result.xml[0]' - -- name: Set up syslog host logging (idempotent) - register: result - cisco.iosxr.iosxr_logging: *id001 -- ansible.builtin.assert: &id003 - that: - - result.changed == false - -- name: Delete/disable syslog host logging - register: result - cisco.iosxr.iosxr_logging: &id002 - dest: host - name: 172.16.0.1 - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - - '"172.16.0.1" in result.xml[0]' - - '"delete" in result.xml[0]' - -- name: Delete/disable syslog host logging (idempotent) - register: result - cisco.iosxr.iosxr_logging: *id002 -- ansible.builtin.assert: *id003 -- name: Add console logging with level warning - register: result - cisco.iosxr.iosxr_logging: &id004 - dest: console - level: warning - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"console" in result.xml[0]' - - '"warning" in result.xml[0]' - -- name: Console logging with level warning (idempotent) - register: result - cisco.iosxr.iosxr_logging: *id004 -- ansible.builtin.assert: *id003 -- name: Remove console logging with level warning - register: result - cisco.iosxr.iosxr_logging: - dest: console - level: warning - state: absent - -- ansible.builtin.assert: &id006 - that: - - result.changed == true - -- name: Configure buffered logging size - register: result - cisco.iosxr.iosxr_logging: &id005 - dest: buffered - size: 4800000 - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"buffered" in result.xml[0]' - - '"4800000" in result.xml[0]' - -- name: Configure buffered logging size (idempotence) - register: result - cisco.iosxr.iosxr_logging: *id005 -- ansible.builtin.assert: *id003 -- name: Remove buffered logging size - register: result - cisco.iosxr.iosxr_logging: - dest: buffered - size: 4800000 - state: absent - -- ansible.builtin.assert: *id006 -- name: Change logging parameters using aggregate - register: result - cisco.iosxr.iosxr_logging: - aggregate: - - dest: console - level: notifications - - - dest: buffered - size: 4700000 - - - dest: monitor - level: alerts - - - dest: host - name: 10.10.10.1 - level: errors - - - dest: host - name: 10.10.10.2 - - - dest: file - name: file1 - size: 2048 - level: critical - path: /file1 - - - dest: file - name: file2 - size: 2048 - path: /file2 - - - facility: local3 - - - hostnameprefix: host3 - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"file1" in result.xml[0]' - - '"file2" in result.xml[0]' - - '"10.10.10.1" in result.xml[1]' - - '"10.10.10.2" in result.xml[1]' - - '"notice" in result.xml[2]' - - '"alert" in result.xml[3]' - - '"4700000" in result.xml[4]' - - '"debug" in result.xml[4]' - - '"local3" in result.xml[5]' - - '"host3" in result.xml[6]' - -- name: Remove logging parameters using aggregate - register: result - cisco.iosxr.iosxr_logging: - aggregate: - - dest: console - level: notifications - - - dest: buffered - size: 4700000 - - - dest: monitor - level: alerts - - - dest: host - name: 10.10.10.1 - level: errors - - - dest: host - name: 10.10.10.2 - - - dest: file - name: file1 - size: 2048 - level: critical - - - dest: file - name: file2 - size: 2048 - - - facility: local3 - - - hostnameprefix: host3 - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - - '"file1" in result.xml[0]' - - '"file2" in result.xml[0]' - - '"10.10.10.1" in result.xml[1]' - - '"10.10.10.2" in result.xml[1]' - - '"notice" in result.xml[2]' - - '"alert" in result.xml[3]' - - '"4700000" in result.xml[4]' - - '"debug" in result.xml[4]' - - '"local3" in result.xml[5]' - - '"host3" in result.xml[6]' From 340fbc83c0463ab4da8d46d3d2ef5c2f511e06a6 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> Date: Wed, 27 Mar 2024 17:44:11 +0530 Subject: [PATCH 09/11] Prepare for major release 8.0.0 (#481) * prepare for major release * delete the fragments * changelog.rst file * [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> --- CHANGELOG.rst | 13 +++++++++++++ changelogs/changelog.yaml | 17 ++++++++++++----- changelogs/fragments/remove_deprecated.yaml | 5 ----- changelogs/fragments/trivial_tests_updates.yaml | 4 ---- galaxy.yml | 2 +- 5 files changed, 26 insertions(+), 15 deletions(-) delete mode 100644 changelogs/fragments/remove_deprecated.yaml delete mode 100644 changelogs/fragments/trivial_tests_updates.yaml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 81065138c..70c2fc3b4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,19 @@ Cisco Iosxr Collection Release Notes .. contents:: Topics +v8.0.0 +====== + +Major Changes +------------- + +- This release removes previously deprecated module and attributes from this collection. Please refer to the **Removed Features** section for details. + +Removed Features (previously deprecated) +---------------------------------------- + +- Remove deprecated iosxr_logging module which is replaced with iosxr_logging_global resource module. + v7.2.0 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index ab7c68a9a..2b66f7eca 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -52,11 +52,6 @@ releases: - description: LLDP interfaces resource module name: iosxr_lldp_interfaces namespace: "" - - description: - Configuration management of system logging services on network - devices - name: iosxr_logging - namespace: "" - description: Configures NetConf sub-system service on Cisco IOS-XR devices name: iosxr_netconf namespace: "" @@ -720,3 +715,15 @@ releases: - fix_bgp_template.yaml - fix_nightly.yaml release_date: "2024-03-01" + 8.0.0: + changes: + major_changes: + - This release removes previously deprecated module and attributes from this + collection. Please refer to the **Removed Features** section for details. + removed_features: + - Remove deprecated iosxr_logging module which is replaced with iosxr_logging_global + resource module. + fragments: + - remove_deprecated.yaml + - trivial_tests_updates.yaml + release_date: "2024-03-27" diff --git a/changelogs/fragments/remove_deprecated.yaml b/changelogs/fragments/remove_deprecated.yaml deleted file mode 100644 index 29600e2d9..000000000 --- a/changelogs/fragments/remove_deprecated.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -major_changes: - - "This release removes the iosxr_logging deprecated module from this collection in favour of iosxr_logging_global module." -removed_features: - - The iosxr_logging module has been removed with this release. diff --git a/changelogs/fragments/trivial_tests_updates.yaml b/changelogs/fragments/trivial_tests_updates.yaml deleted file mode 100644 index 6f9f7d906..000000000 --- a/changelogs/fragments/trivial_tests_updates.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -trivial: - - remove compat files as we stopped testing against python 2.7. - - update direct imports for patch and MagicMock from unittest. diff --git a/galaxy.yml b/galaxy.yml index 194566307..acaab18e6 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -13,4 +13,4 @@ issues: https://github.com/ansible-collections/cisco.iosxr/issues tags: [cisco, iosxr, networking, netconf] # NOTE(pabelanger): We create an empty version key to keep ansible-galaxy # happy. We dynamically inject version info based on git information. -version: "7.2.0" +version: "8.0.0" From f53789bb67e348505dc7fbce37f26d500901c5c7 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:59:55 +0530 Subject: [PATCH 10/11] drop tox-linters and add new build-import workflow (#484) * drop zuul * add ignore-2.18.txt * [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> --- .flake8 | 67 +++++++++++++++++++ .github/workflows/tests.yml | 3 + .pre-commit-config.yaml | 12 ++-- .zuul.yaml | 8 --- changelogs/fragments/add_2.18.yaml | 3 + tests/sanity/ignore-2.18.txt | 4 ++ .../modules/network/iosxr/test_iosxr_ping.py | 2 +- tox-ansible.ini | 9 +-- tox.ini | 31 --------- 9 files changed, 87 insertions(+), 52 deletions(-) create mode 100644 .flake8 delete mode 100644 .zuul.yaml create mode 100644 changelogs/fragments/add_2.18.yaml create mode 100644 tests/sanity/ignore-2.18.txt delete mode 100644 tox.ini diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..9a7fc1251 --- /dev/null +++ b/.flake8 @@ -0,0 +1,67 @@ +[flake8] + +builtins = _ + +# Print the total number of errors: +count = true + +# Don't even try to analyze these: +extend-exclude = + # No need to traverse egg info dir + *.egg-info, + # tool cache dirs + *_cache + # project env vars + .env, + # GitHub configs + .github, + # Cache files of MyPy + .mypy_cache, + # Cache files of pytest + .pytest_cache, + # Temp dir of pytest-testmon + .tmontmp, + # Occasional virtualenv dir + .venv + # VS Code + .vscode, + # Temporary build dir + build, + # This contains sdists and wheels of ansible-navigator that we don't want to check + dist, + # Metadata of `pip wheel` cmd is autogenerated + pip-wheel-metadata, + # adjacent venv + venv + # ansible won't let me + __init__.py + +# IMPORTANT: avoid using ignore option, always use extend-ignore instead +# Completely and unconditionally ignore the following errors: +extend-ignore = + F841, + # line-length + E501, + # module level import not at top of file + E402 + +# Accessibility/large fonts and PEP8 unfriendly: +max-line-length = 120 + +# Allow certain violations in certain files: +# Please keep both sections of this list sorted, as it will be easier for others to find and add entries in the future +per-file-ignores = + # The following ignores have been researched and should be considered permanent + # each should be preceeded with an explanation of each of the error codes + # If other ignores are added for a specific file in the section following this, + # these will need to be added to that line as well. + + + # S101: Allow the use of assert within the tests directory, since tests require it. + tests/**.py: S101 + + # The following were present during the initial implementation. + # They are expected to be fixed and unignored over time. + +# Count the number of occurrences of each error/warning code and print a report: +statistics = true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5c01a71c7..64409a9a4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,6 +16,8 @@ jobs: changelog: uses: ansible/ansible-content-actions/.github/workflows/changelog.yaml@main if: github.event_name == 'pull_request' + build-import: + uses: ansible/ansible-content-actions/.github/workflows/build_import.yaml@main ansible-lint: uses: ansible/ansible-content-actions/.github/workflows/ansible_lint.yaml@main sanity: @@ -32,6 +34,7 @@ jobs: if: ${{ always() }} needs: - changelog + - build-import - sanity - unit-galaxy - ansible-lint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d034d8da3..90167726d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,6 @@ repos: - repo: https://github.com/ansible-network/collection_prep rev: 1.1.1 hooks: - # - id: autoversion # removed as being handled by GHA push and release drafter - id: update-docs - repo: https://github.com/pre-commit/pre-commit-hooks @@ -23,7 +22,7 @@ repos: - id: add-trailing-comma - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v3.0.3" + rev: "v4.0.0-alpha.8" hooks: - id: prettier entry: env CI=1 bash -c "prettier --list-different . || ec=$? && prettier --loglevel=error --write . && exit $ec" @@ -34,13 +33,18 @@ repos: - prettier-plugin-toml - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort name: Sort import statements using isort args: ["--filter-files"] - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 23.12.1 hooks: - id: black + + - repo: https://github.com/pycqa/flake8 + rev: 7.0.0 + hooks: + - id: flake8 diff --git a/.zuul.yaml b/.zuul.yaml deleted file mode 100644 index a892ec722..000000000 --- a/.zuul.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- project: - check: - jobs: - - ansible-tox-linters - gate: - jobs: - - ansible-tox-linters diff --git a/changelogs/fragments/add_2.18.yaml b/changelogs/fragments/add_2.18.yaml new file mode 100644 index 000000000..0aaf1f750 --- /dev/null +++ b/changelogs/fragments/add_2.18.yaml @@ -0,0 +1,3 @@ +--- +trivial: + - Add ignore-2.18.txt. diff --git a/tests/sanity/ignore-2.18.txt b/tests/sanity/ignore-2.18.txt new file mode 100644 index 000000000..6d49e3dcb --- /dev/null +++ b/tests/sanity/ignore-2.18.txt @@ -0,0 +1,4 @@ +plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` +plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.10!skip +plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.11!skip +plugins/sub_plugins/grpc/pb/ems_grpc_pb2.py import-3.12!skip diff --git a/tests/unit/modules/network/iosxr/test_iosxr_ping.py b/tests/unit/modules/network/iosxr/test_iosxr_ping.py index b5701c655..87ffc4f13 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_ping.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_ping.py @@ -135,7 +135,7 @@ def test_iosxr_ping_state_absent_pass(self): } self.assertEqual(result, mock_res) - def test_iosxr_ping_state_absent_pass(self): + def test_iosxr_ping_state_absent_pass_1(self): self.execute_show_command.return_value = dedent( """\ Type escape sequence to abort. diff --git a/tox-ansible.ini b/tox-ansible.ini index 5e1f4b36a..b49a359f9 100644 --- a/tox-ansible.ini +++ b/tox-ansible.ini @@ -1,10 +1,3 @@ [ansible] -skip = - py3.7 - py3.8 - 2.9 - 2.10 - 2.11 - 2.12 - 2.13 +skip = "" diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 7dbe41e8f..000000000 --- a/tox.ini +++ /dev/null @@ -1,31 +0,0 @@ -[tox] -minversion = 1.4.2 -envlist = linters -skipsdist = True - -[testenv] -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt - -[testenv:black] -install_command = pip install {opts} {packages} -commands = - black -v {toxinidir} - -[testenv:linters] -install_command = pip install {opts} {packages} -commands = - black -v --diff --check {toxinidir} - flake8 {posargs} - -[testenv:venv] -commands = {posargs} - -[flake8] -# E123, E125 skipped as they are invalid PEP-8. - -show-source = True -ignore = E123,E125,E203,E402,E501,E741,F401,F811,F841,W503 -max-line-length = 160 -builtins = _ -exclude = .git,.tox From 1bba67a670274875550a2a1de46c00014620f4a5 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> Date: Thu, 4 Apr 2024 20:30:06 +0530 Subject: [PATCH 11/11] Remove tests related to iosxr_logging (#483) * remove tests related to iosxr_logging * 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/remove_tests.yaml | 3 +++ .../tests/netconf/common_netconf.yaml | 20 ------------------- 2 files changed, 3 insertions(+), 20 deletions(-) create mode 100644 changelogs/fragments/remove_tests.yaml diff --git a/changelogs/fragments/remove_tests.yaml b/changelogs/fragments/remove_tests.yaml new file mode 100644 index 000000000..6e0e85990 --- /dev/null +++ b/changelogs/fragments/remove_tests.yaml @@ -0,0 +1,3 @@ +--- +trivial: + - Remove tests related to iosxr_logging deprecated module. diff --git a/tests/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml b/tests/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml index 2ab0957ae..5f08fd677 100644 --- a/tests/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml +++ b/tests/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml @@ -23,24 +23,4 @@ - "'this is my login banner' in result.xml" - "'that has a multiline' in result.xml" -# hit etree_findall() -- name: Remove host logging - cisco.iosxr.iosxr_logging: - dest: host - name: 172.16.0.1 - state: absent - -- name: Set up syslog host logging - cisco.iosxr.iosxr_logging: - dest: host - name: 172.16.0.1 - level: errors - state: present - register: result - -- ansible.builtin.assert: - that: - - "result.changed == true" - - '"172.16.0.1" in result.xml[0]' - - ansible.builtin.debug: msg="END iosxr netconf/common_netconf.yaml on connection={{ ansible_connection }}"