From 5a30abb5c4ab863a5e2b51e4c7285ff5fc0c1732 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 10:40:56 +0530 Subject: [PATCH 01/31] feat: Add multi-collection CI support for juniper.device and junipernetworks.junos - Add matrix strategy to run tests for both collections - Support push/PR triggers on main, devel, and master branches - Parameterize working directories for collection-specific testing --- .github/workflows/tests.yml | 41 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 677c0691..08d4b18d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,9 @@ concurrency: on: # yamllint disable-line rule:truthy pull_request: - branches: [master] + branches: [main, devel, master] + push: + branches: [main, devel, master] workflow_dispatch: schedule: - cron: '0 0 * * *' @@ -16,9 +18,14 @@ jobs: changelog: uses: ansible/ansible-content-actions/.github/workflows/changelog.yaml@main if: github.event_name == 'pull_request' + build-import: name: build-import-collection runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + collection: [juniper/device, junipernetworks/junos] steps: - name: Checkout uses: actions/checkout@v5 @@ -36,19 +43,26 @@ jobs: - name: Build the collection tarball and run galaxy importer on it shell: bash - working-directory: ansible_collections/juniper/device + working-directory: ansible_collections/${{ matrix.collection }} run: | python -m galaxy_importer.main --git-clone-path . --output-path /tmp + ansible-lint: uses: ansible/ansible-content-actions/.github/workflows/ansible_lint.yaml@main + strategy: + fail-fast: false + matrix: + collection: [juniper/device, junipernetworks/junos] with: - working_directory: ansible_collections/juniper/device + working_directory: ansible_collections/${{ matrix.collection }} + sanity: name: Sanity Tests runs-on: ubuntu-latest strategy: fail-fast: false matrix: + collection: [juniper/device, junipernetworks/junos] include: - python: "3.10" ansible: "2.17" @@ -80,20 +94,22 @@ jobs: - name: Copy tox-ansible.ini to collection directory run: | if [ -f tox-ansible.ini ]; then - cp tox-ansible.ini ansible_collections/juniper/device/ + cp tox-ansible.ini ansible_collections/${{ matrix.collection }}/ fi - name: Run tox sanity tests - working-directory: ansible_collections/juniper/device + working-directory: ansible_collections/${{ matrix.collection }} run: >- python -m tox --ansible -e sanity-py${{ matrix.python }}-${{ matrix.ansible }} env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + unit-galaxy: name: Unit Tests (Galaxy) runs-on: ubuntu-latest strategy: fail-fast: false matrix: + collection: [juniper/device, junipernetworks/junos] include: - python: "3.10" ansible: "2.17" @@ -125,20 +141,22 @@ jobs: - name: Copy tox-ansible.ini to collection directory run: | if [ -f tox-ansible.ini ]; then - cp tox-ansible.ini ansible_collections/juniper/device/ + cp tox-ansible.ini ansible_collections/${{ matrix.collection }}/ fi - name: Run tox unit tests - working-directory: ansible_collections/juniper/device + working-directory: ansible_collections/${{ matrix.collection }} run: >- python -m tox --ansible -e unit-py${{ matrix.python }}-${{ matrix.ansible }} env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + unit-source: name: Unit Tests (Source) runs-on: ubuntu-latest strategy: fail-fast: false matrix: + collection: [juniper/device, junipernetworks/junos] include: - ansible_version: "stable-2.16" python_version: "3.11" @@ -177,26 +195,27 @@ jobs: ansible-galaxy collection install git+https://github.com/ansible-collections/ansible.utils.git ansible-galaxy collection install git+https://github.com/ansible-collections/ansible.netcommon.git - name: Read collection metadata from galaxy.yml - working-directory: ansible_collections/juniper/device + working-directory: ansible_collections/${{ matrix.collection }} run: | python -c "import yaml; print(yaml.safe_load(open('galaxy.yml'))['version'])" - name: Build and install the collection - working-directory: ansible_collections/juniper/device + working-directory: ansible_collections/${{ matrix.collection }} run: | ansible-galaxy collection build --force - ansible-galaxy collection install juniper-device-*.tar.gz --force + ansible-galaxy collection install *-*.tar.gz --force - name: Print the ansible version run: ansible --version - name: Print the python dependencies run: python -m pip list - name: Run unit tests - working-directory: ansible_collections/juniper/device + working-directory: ansible_collections/${{ matrix.collection }} run: | if [ -d "tests/unit" ]; then ansible-test units --python ${{ matrix.python_version }} --local --requirements else echo "No unit tests directory found, skipping" fi + all_green: if: ${{ always() && (github.event_name != 'schedule') }} needs: From 8545758387582da80c71ff7067186d80d98df570 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 14:24:20 +0530 Subject: [PATCH 02/31] fixes_test --- .../unit/modules/network/junos/test_junos_bgp_address_family.py | 2 +- .../tests/unit/modules/network/junos/test_junos_bgp_global.py | 2 +- .../tests/unit/modules/network/junos/test_junos_command.py | 2 +- .../junos/tests/unit/modules/network/junos/test_junos_config.py | 2 +- .../junos/tests/unit/modules/network/junos/test_junos_facts.py | 2 +- .../tests/unit/modules/network/junos/test_junos_hostname.py | 2 +- .../tests/unit/modules/network/junos/test_junos_interfaces.py | 2 +- .../unit/modules/network/junos/test_junos_l2_interfaces.py | 2 +- .../unit/modules/network/junos/test_junos_l3_interfaces.py | 2 +- .../unit/modules/network/junos/test_junos_logging_global.py | 2 +- .../tests/unit/modules/network/junos/test_junos_netconf.py | 2 +- .../tests/unit/modules/network/junos/test_junos_ntp_global.py | 2 +- .../unit/modules/network/junos/test_junos_ospf_interfaces.py | 2 +- .../junos/tests/unit/modules/network/junos/test_junos_ospfv2.py | 2 +- .../junos/tests/unit/modules/network/junos/test_junos_ospfv3.py | 2 +- .../junos/tests/unit/modules/network/junos/test_junos_ping.py | 2 +- .../tests/unit/modules/network/junos/test_junos_prefix_lists.py | 2 +- .../unit/modules/network/junos/test_junos_routing_instances.py | 2 +- .../unit/modules/network/junos/test_junos_routing_options.py | 2 +- .../junos/tests/unit/modules/network/junos/test_junos_rpc.py | 2 +- .../unit/modules/network/junos/test_junos_security_policies.py | 2 +- .../network/junos/test_junos_security_policies_global.py | 2 +- .../unit/modules/network/junos/test_junos_security_zones.py | 2 +- .../tests/unit/modules/network/junos/test_junos_snmp_server.py | 2 +- .../junos/tests/unit/modules/network/junos/test_junos_vlans.py | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py index 5a743bee..bc226a09 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_bgp_address_family +from ansible_collections.juniper.device.plugins.modules import junos_bgp_address_family from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py index f5d8dfcd..5848ff71 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_bgp_global +from ansible_collections.juniper.device.plugins.modules import junos_bgp_global from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py index 5e066957..387877ce 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_command +from ansible_collections.juniper.device.plugins.modules import junos_command from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py index e24a56c4..c028446e 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py @@ -26,7 +26,7 @@ from ansible.module_utils._text import to_text -from ansible_collections.junipernetworks.junos.plugins.modules import junos_config +from ansible_collections.juniper.device.plugins.modules import junos_config from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py index 154ea4f5..00f440c2 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_facts +from ansible_collections.juniper.device.plugins.modules import junos_facts from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py index 8fe1931d..aeddbc6a 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_hostname +from ansible_collections.juniper.device.plugins.modules import junos_hostname from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py index d2f41bf6..ae5c824a 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_interfaces +from ansible_collections.juniper.device.plugins.modules import junos_interfaces from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py index 06d61143..6e9a862d 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_l2_interfaces +from ansible_collections.juniper.device.plugins.modules import junos_l2_interfaces from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py index 600861a6..a7841b74 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_l3_interfaces +from ansible_collections.juniper.device.plugins.modules import junos_l3_interfaces from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py index 55ac5170..0c62c88e 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_logging_global +from ansible_collections.juniper.device.plugins.modules import junos_logging_global from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py index 70e4fe0b..fba4d461 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py @@ -23,7 +23,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_netconf +from ansible_collections.juniper.device.plugins.modules import junos_netconf from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py index 26836a7c..ecdb3cd8 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_ntp_global +from ansible_collections.juniper.device.plugins.modules import junos_ntp_global from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py index 39ea2b77..a365fa5c 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py @@ -28,7 +28,7 @@ from unittest.mock import MagicMock, patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_ospf_interfaces +from ansible_collections.juniper.device.plugins.modules import junos_ospf_interfaces from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py index 3ec9f589..12418230 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_ospfv2 +from ansible_collections.juniper.device.plugins.modules import junos_ospfv2 from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py index beef248b..ecdc53a3 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py @@ -28,7 +28,7 @@ from unittest.mock import MagicMock, patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_ospfv3 +from ansible_collections.juniper.device.plugins.modules import junos_ospfv3 from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py index 4a6d2701..98166265 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py @@ -23,7 +23,7 @@ from unittest.mock import MagicMock, patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_ping +from ansible_collections.juniper.device.plugins.modules import junos_ping from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py index 9db905a4..d5f5de55 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_prefix_lists +from ansible_collections.juniper.device.plugins.modules import junos_prefix_lists from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py index d281a7ef..5eeefebb 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_routing_instances +from ansible_collections.juniper.device.plugins.modules import junos_routing_instances from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py index 0f506bc8..3d079217 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_routing_options +from ansible_collections.juniper.device.plugins.modules import junos_routing_options from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py index 11a3bb8a..9f5acedc 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_rpc +from ansible_collections.juniper.device.plugins.modules import junos_rpc from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py index 22eb2b14..d18e08c2 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_security_policies +from ansible_collections.juniper.device.plugins.modules import junos_security_policies from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py index 1c1131d9..acc6b768 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_security_policies_global +from ansible_collections.juniper.device.plugins.modules import junos_security_policies_global from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py index b5eb0385..608d1fee 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_security_zones +from ansible_collections.juniper.device.plugins.modules import junos_security_zones from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py index f29381a1..69d15502 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_snmp_server +from ansible_collections.juniper.device.plugins.modules import junos_snmp_server from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py index 1f0890a5..283e82ef 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py @@ -28,7 +28,7 @@ from unittest.mock import patch -from ansible_collections.junipernetworks.junos.plugins.modules import junos_vlans +from ansible_collections.juniper.device.plugins.modules import junos_vlans from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args from .junos_module import TestJunosModule, load_fixture From bf113c4f11d1d58fefa1daa6c38ec63599a1f764 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 14:36:07 +0530 Subject: [PATCH 03/31] fixes_workflow --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 08d4b18d..8675a1b7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -102,7 +102,7 @@ jobs: python -m tox --ansible -e sanity-py${{ matrix.python }}-${{ matrix.ansible }} env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - + unit-galaxy: name: Unit Tests (Galaxy) runs-on: ubuntu-latest @@ -146,7 +146,7 @@ jobs: - name: Run tox unit tests working-directory: ansible_collections/${{ matrix.collection }} run: >- - python -m tox --ansible -e unit-py${{ matrix.python }}-${{ matrix.ansible }} + python -m tox --ansible -c tox-ansible.ini -e unit-py${{ matrix.python }}-${{ matrix.ansible }} env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" From cee4c7e31c8a0507f9967103491e38b13cc6f753 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 14:50:12 +0530 Subject: [PATCH 04/31] fixes_workflow2 --- .github/workflows/tests.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8675a1b7..5e7657d6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -99,10 +99,10 @@ jobs: - name: Run tox sanity tests working-directory: ansible_collections/${{ matrix.collection }} run: >- - python -m tox --ansible -e sanity-py${{ matrix.python }}-${{ matrix.ansible }} + python -m tox --ansible -c tox-ansible.ini -e sanity-py${{ matrix.python }}-${{ matrix.ansible }} env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - + unit-galaxy: name: Unit Tests (Galaxy) runs-on: ubuntu-latest @@ -136,6 +136,15 @@ jobs: python-version: "${{ matrix.python }}" - name: "Install tox-ansible, includes tox" run: python -m pip install tox-ansible + - name: Build local juniper.device dependency + if: matrix.collection == 'junipernetworks/junos' + run: | + cd ansible_collections/juniper/device + ansible-galaxy collection build --force + mv *-*.tar.gz /tmp/juniper-device-local.tar.gz + cd - + # Point galaxy.yml dependency to the local tarball + sed -i 's|juniper.device:.*|juniper.device: /tmp/juniper-device-local.tar.gz|' ansible_collections/junipernetworks/junos/galaxy.yml - name: "Check for tox-ansible.ini file, else add default" uses: ansible/ansible-content-actions/.github/actions/add_tox_ansible@main - name: Copy tox-ansible.ini to collection directory @@ -145,6 +154,7 @@ jobs: fi - name: Run tox unit tests working-directory: ansible_collections/${{ matrix.collection }} + # Added -c tox-ansible.ini to fix configuration loading run: >- python -m tox --ansible -c tox-ansible.ini -e unit-py${{ matrix.python }}-${{ matrix.ansible }} env: From 784a720982a080feff10730891cb11a91f2767fd Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 14:55:38 +0530 Subject: [PATCH 05/31] fixes_requirement --- .../junipernetworks/junos/tests/unit/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/requirements.txt b/ansible_collections/junipernetworks/junos/tests/unit/requirements.txt index a9772bea..98a38587 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/requirements.txt +++ b/ansible_collections/junipernetworks/junos/tests/unit/requirements.txt @@ -1,6 +1,6 @@ boto3 placebo -pycrypto +pycryptodome passlib pypsrp python-memcached From 6c1613443f1bd1ce05ba4a8123fef35acfa1970a Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 15:04:28 +0530 Subject: [PATCH 06/31] fixes_test.yml --- .github/workflows/tests.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5e7657d6..524b1aa7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -134,17 +134,22 @@ jobs: uses: actions/setup-python@v6 with: python-version: "${{ matrix.python }}" - - name: "Install tox-ansible, includes tox" - run: python -m pip install tox-ansible - - name: Build local juniper.device dependency + - name: Prepare local dependencies if: matrix.collection == 'junipernetworks/junos' run: | + echo "Building local juniper.device..." cd ansible_collections/juniper/device ansible-galaxy collection build --force mv *-*.tar.gz /tmp/juniper-device-local.tar.gz cd - - # Point galaxy.yml dependency to the local tarball + echo "Injecting local build into galaxy.yml..." sed -i 's|juniper.device:.*|juniper.device: /tmp/juniper-device-local.tar.gz|' ansible_collections/junipernetworks/junos/galaxy.yml + if ! grep -q "ansible.netcommon" ansible_collections/junipernetworks/junos/galaxy.yml; then + echo "Injecting ansible.netcommon dependency..." + sed -i '/dependencies:/a \ \ ansible.netcommon: "*"' ansible_collections/junipernetworks/junos/galaxy.yml + fi + - name: "Install tox-ansible, includes tox" + run: python -m pip install tox-ansible - name: "Check for tox-ansible.ini file, else add default" uses: ansible/ansible-content-actions/.github/actions/add_tox_ansible@main - name: Copy tox-ansible.ini to collection directory @@ -154,7 +159,6 @@ jobs: fi - name: Run tox unit tests working-directory: ansible_collections/${{ matrix.collection }} - # Added -c tox-ansible.ini to fix configuration loading run: >- python -m tox --ansible -c tox-ansible.ini -e unit-py${{ matrix.python }}-${{ matrix.ansible }} env: @@ -221,6 +225,8 @@ jobs: working-directory: ansible_collections/${{ matrix.collection }} run: | if [ -d "tests/unit" ]; then + # Fix pycrypto here as well for unit-source + if [ -f "requirements.txt" ]; then sed -i 's/pycrypto/pycryptodome/g' requirements.txt; fi ansible-test units --python ${{ matrix.python_version }} --local --requirements else echo "No unit tests directory found, skipping" From a267032639a686ce955e40878f54945d1e7ea569 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 15:31:51 +0530 Subject: [PATCH 07/31] added_ignore_sanity --- .../junipernetworks/junos/tests/sanity/ignore-2.20.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.20.txt diff --git a/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.20.txt b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.20.txt new file mode 100644 index 00000000..34ca8c4a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.20.txt @@ -0,0 +1 @@ +plugins/cliconf/junos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` From b8fd4721f34cd37c2a4441827e71e87987315429 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 15:39:00 +0530 Subject: [PATCH 08/31] added_ignore_sanity --- .../integration/targets/prepare_junos_tests/tasks/prepare.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/prepare_junos_tests/tasks/prepare.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/prepare_junos_tests/tasks/prepare.yml index 179fb0d9..ab396cd6 100644 --- a/ansible_collections/junipernetworks/junos/tests/integration/targets/prepare_junos_tests/tasks/prepare.yml +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/prepare_junos_tests/tasks/prepare.yml @@ -6,7 +6,7 @@ - name: Ensure netconf is enabled connection: ansible.netcommon.network_cli tags: netconf - junipernetworks.junos.junos_netconf: + juniper.device.junos_netconf: state: present - name: Wait for netconf server to come up From 098a92d13808c2d5c83040f2c1ceaa723c6bcbd5 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 15:52:35 +0530 Subject: [PATCH 09/31] fix_junos.py --- .../junos/plugins/cliconf/junos.py | 355 +++++++++++++++++- .../junos/tests/sanity/ignore-2.20.txt | 1 - 2 files changed, 352 insertions(+), 4 deletions(-) delete mode 100644 ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.20.txt diff --git a/ansible_collections/junipernetworks/junos/plugins/cliconf/junos.py b/ansible_collections/junipernetworks/junos/plugins/cliconf/junos.py index 5e825cf4..22843f93 100644 --- a/ansible_collections/junipernetworks/junos/plugins/cliconf/junos.py +++ b/ansible_collections/junipernetworks/junos/plugins/cliconf/junos.py @@ -1,5 +1,354 @@ -from ansible_collections.juniper.device.plugins.cliconf.junos import Cliconf +# +# (c) 2017 Red Hat Inc. +# +# 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 . +# +from __future__ import absolute_import, division, print_function -class Cliconf(Cliconf): - pass +__metaclass__ = type + +DOCUMENTATION = """ +author: Ansible Networking Team (@ansible-network) +name: junos +short_description: Use junos cliconf to run command on Juniper Junos OS platform +description: +- This junos plugin provides low level abstraction apis for sending and receiving + CLI commands from Juniper Junos OS network devices. +version_added: 1.0.0 +options: + config_commands: + description: + - Specifies a list of commands that can make configuration changes + to the target device. + - When `ansible_network_single_user_mode` is enabled, if a command sent + to the device is present in this list, the existing cache is invalidated. + version_added: 2.0.0 + type: list + elements: str + default: [] + vars: + - name: ansible_junos_config_commands +""" + +import json +import re + +from functools import wraps +from itertools import chain + +from ansible.errors import AnsibleConnectionFailure +from ansible.module_utils._text import to_text +from ansible.module_utils.common._collections_compat import Mapping +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list +from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import CliconfBase + + +def configure(func): + @wraps(func) + def wrapped(self, *args, **kwargs): + prompt = self._connection.get_prompt() + if not to_text(prompt, errors="surrogate_or_strict").strip().endswith("#"): + self.send_command("configure") + return func(self, *args, **kwargs) + + return wrapped + + +class Cliconf(CliconfBase): + def __init__(self, *args, **kwargs): + self._device_info = {} + super(Cliconf, self).__init__(*args, **kwargs) + + def get_text(self, ele, tag): + try: + return to_text( + ele.find(tag).text, + errors="surrogate_then_replace", + ).strip() + except AttributeError: + pass + + def get_device_info(self): + if not self._device_info: + device_info = {} + device_info["network_os"] = "junos" + + reply = self.get(command="show version") + data = to_text(reply, errors="surrogate_or_strict").strip() + + match = re.search(r"Junos: (\S+)", data) + if match: + device_info["network_os_version"] = match.group(1) + + match = re.search(r"Model: (\S+)", data, re.M) + if match: + device_info["network_os_model"] = match.group(1) + + match = re.search(r"Hostname: (\S+)", data, re.M) + if match: + device_info["network_os_hostname"] = match.group(1) + + self._device_info = device_info + + return self._device_info + + def get_config(self, source="running", flags=None, format="text"): + if source != "running": + raise ValueError( + "fetching configuration from %s is not supported" % source, + ) + + options_values = self.get_option_values() + if format not in options_values["format"]: + raise ValueError( + "'format' value %s is invalid. Valid values are %s" + % (format, ",".join(options_values["format"])), + ) + + if format == "text": + cmd = "show configuration" + else: + cmd = "show configuration | display %s" % format + + cmd += " ".join(to_list(flags)) + cmd = cmd.strip() + return self.send_command(cmd) + + @configure + def edit_config( + self, + candidate=None, + commit=True, + replace=None, + comment=None, + ): + operations = self.get_device_operations() + self.check_edit_config_capability( + operations, + candidate, + commit, + replace, + comment, + ) + + resp = {} + results = [] + requests = [] + + if replace: + candidate = "load override {0}".format(replace) + + for line in to_list(candidate): + if not isinstance(line, Mapping): + line = {"command": line} + cmd = line["command"] + try: + results.append(self.send_command(**line)) + except AnsibleConnectionFailure as exc: + if "error: commit failed" in exc.message: + self.discard_changes() + raise + requests.append(cmd) + + diff = self.compare_configuration() + if diff: + resp["diff"] = diff + + if commit: + self.commit(comment=comment) + else: + self.discard_changes() + + else: + self.send_command("top") + self.discard_changes() + + resp["request"] = requests + resp["response"] = results + return resp + + def get( + self, + command, + prompt=None, + answer=None, + sendonly=False, + newline=True, + output=None, + check_all=False, + ): + if output: + command = self._get_command_with_output(command, output) + return self.send_command( + command=command, + prompt=prompt, + answer=answer, + sendonly=sendonly, + newline=newline, + check_all=check_all, + ) + + @configure + def commit( + self, + comment=None, + confirmed=False, + at_time=None, + synchronize=False, + ): + """ + Execute commit command on remote device. + :param comment: Comment to be associated with commit + :param confirmed: Boolean flag to indicate if the previous commit should confirmed + :param at_time: Time at which to activate configuration changes + :param synchronize: Boolean flag to indicate if commit should synchronize on remote peers + :return: Command response received from device + """ + command = "commit" + if comment: + command += " comment {0}".format(comment) + if confirmed: + command += " confirmed" + if at_time: + command += " {0}".format(at_time) + if synchronize: + command += " peers-synchronize" + + command += " and-quit" + + try: + response = self.send_command(command) + except AnsibleConnectionFailure: + self.discard_changes() + raise + + return response + + @configure + def discard_changes(self): + command = "rollback 0" + for cmd in chain(to_list(command), ["exit"]): + self.send_command(cmd) + + @configure + def validate(self): + return self.send_command("commit check") + + @configure + def compare_configuration(self, rollback_id=None): + command = "show | compare" + if rollback_id is not None: + command += " rollback %s" % int(rollback_id) + resp = self.send_command(command) + + r = resp.splitlines() + if len(r) == 1 and "[edit]" in r[0] or len(r) == 4 and r[1].startswith("- version"): + resp = "" + + return resp + + @configure + def rollback(self, rollback_id, commit=True): + resp = {} + self.send_command("rollback %s" % int(rollback_id)) + resp["diff"] = self.compare_configuration() + if commit: + self.commit() + else: + self.discard_changes() + return resp + + @configure + def restore(self, filename=None, path=""): + if not filename: + raise ValueError("'file_name' value is required for restore") + cmd = f"load override {path}{filename}" + resp = self.send_command(cmd) + self.commit() + return resp + + def get_diff(self, rollback_id=None): + diff = {"config_diff": None} + response = self.compare_configuration(rollback_id=rollback_id) + if response: + diff["config_diff"] = response + return diff + + def get_device_operations(self): + return { + "supports_diff_replace": False, + "supports_commit": True, + "supports_rollback": True, + "supports_defaults": False, + "supports_onbox_diff": True, + "supports_commit_comment": True, + "supports_multiline_delimiter": False, + "supports_diff_match": False, + "supports_diff_ignore_lines": False, + "supports_generate_diff": False, + "supports_replace": True, + } + + def get_option_values(self): + return { + "format": ["text", "set", "xml", "json"], + "diff_match": [], + "diff_replace": [], + "output": ["text", "set", "xml", "json"], + } + + def get_capabilities(self): + result = super(Cliconf, self).get_capabilities() + result["rpc"] += [ + "commit", + "discard_changes", + "run_commands", + "compare_configuration", + "validate", + "get_diff", + ] + result["device_operations"] = self.get_device_operations() + result.update(self.get_option_values()) + return json.dumps(result) + + def set_cli_prompt_context(self): + """ + Make sure we are in the operational cli mode + :return: None + """ + if self._connection.connected: + self._update_cli_prompt_context(config_context="#") + + def _get_command_with_output(self, command, output): + options_values = self.get_option_values() + if output not in options_values["output"]: + raise ValueError( + "'output' value %s is invalid. Valid values are %s" + % (output, ",".join(options_values["output"])), + ) + + if output == "json" and not command.endswith("| display json"): + cmd = "%s | display json" % command + elif output == "xml" and not command.endswith("| display xml"): + cmd = "%s | display xml" % command + elif output == "text" and ( + command.endswith("| display json") or command.endswith("| display xml") + ): + cmd = command.rsplit("|", 1)[0] + else: + cmd = command + return cmd \ No newline at end of file diff --git a/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.20.txt b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.20.txt deleted file mode 100644 index 34ca8c4a..00000000 --- a/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.20.txt +++ /dev/null @@ -1 +0,0 @@ -plugins/cliconf/junos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` From 094381629011db8cfe16fb69413cae928ca351eb Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 15:55:54 +0530 Subject: [PATCH 10/31] fix_sanity --- .../junipernetworks/junos/plugins/cliconf/junos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible_collections/junipernetworks/junos/plugins/cliconf/junos.py b/ansible_collections/junipernetworks/junos/plugins/cliconf/junos.py index 22843f93..4461c9cb 100644 --- a/ansible_collections/junipernetworks/junos/plugins/cliconf/junos.py +++ b/ansible_collections/junipernetworks/junos/plugins/cliconf/junos.py @@ -351,4 +351,4 @@ def _get_command_with_output(self, command, output): cmd = command.rsplit("|", 1)[0] else: cmd = command - return cmd \ No newline at end of file + return cmd From 840deaffee529cfddb5cf2c96f5e5fba19a8f4c1 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 16:02:48 +0530 Subject: [PATCH 11/31] added_junos.py --- .../junos/plugins/action/junos.py | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 ansible_collections/junipernetworks/junos/plugins/action/junos.py diff --git a/ansible_collections/junipernetworks/junos/plugins/action/junos.py b/ansible_collections/junipernetworks/junos/plugins/action/junos.py new file mode 100644 index 00000000..4c5d480a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/plugins/action/junos.py @@ -0,0 +1,168 @@ +# +# (c) 2016 Red Hat Inc. +# +# 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 . +# +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +import copy +import sys + +from ansible.utils.display import Display +from ansible_collections.ansible.netcommon.plugins.action.network import ( + ActionModule as ActionNetworkModule, +) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + load_provider, +) + +from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos import ( + junos_provider_spec, +) + + +display = Display() + +CLI_SUPPORTED_MODULES = ["junos_netconf", "junos_ping", "junos_command"] + + +class ActionModule(ActionNetworkModule): + def run(self, tmp=None, task_vars=None): + del tmp # tmp no longer has any effect + + module_name = self._task.action.split(".")[-1] + self._config_module = True if module_name in ["junos_config", "config"] else False + persistent_connection = self._play_context.connection.split(".")[-1] + warnings = [] + + if self._play_context.connection == "local": + provider = load_provider(junos_provider_spec, self._task.args) + pc = copy.deepcopy(self._play_context) + pc.network_os = "junipernetworks.junos.junos" + pc.remote_addr = provider["host"] or self._play_context.remote_addr + + if provider["transport"] == "cli" and module_name not in CLI_SUPPORTED_MODULES: + return { + "failed": True, + "msg": "Transport type '%s' is not valid for '%s' module. " + "Please see https://docs.ansible.com/ansible/latest/network/user_guide/platform_junos.html" + % (provider["transport"], module_name), + } + + if module_name == "junos_netconf" or ( + provider["transport"] == "cli" and module_name == "junos_command" + ): + pc.connection = "ansible.netcommon.network_cli" + pc.port = int( + provider["port"] or self._play_context.port or 22, + ) + else: + pc.connection = "ansible.netcommon.netconf" + pc.port = int( + provider["port"] or self._play_context.port or 830, + ) + + pc.remote_user = provider["username"] or self._play_context.connection_user + pc.password = provider["password"] or self._play_context.password + pc.private_key_file = provider["ssh_keyfile"] or self._play_context.private_key_file + + connection = self._shared_loader_obj.connection_loader.get( + "ansible.netcommon.persistent", + pc, + sys.stdin, + task_uuid=self._task._uuid, + ) + + # TODO: Remove below code after ansible minimal is cut out + if connection is None: + pc.network_os = "junos" + if pc.connection.split(".")[-1] == "netconf": + pc.connection = "netconf" + else: + pc.connection = "network_cli" + + connection = self._shared_loader_obj.connection_loader.get( + "persistent", + pc, + sys.stdin, + task_uuid=self._task._uuid, + ) + + display.vvv( + "using connection plugin %s (was local)" % pc.connection, + pc.remote_addr, + ) + + command_timeout = ( + int(provider["timeout"]) + if provider["timeout"] + else connection.get_option("persistent_command_timeout") + ) + connection.set_options( + direct={"persistent_command_timeout": command_timeout}, + ) + + socket_path = connection.run() + display.vvvv("socket_path: %s" % socket_path, pc.remote_addr) + if not socket_path: + return { + "failed": True, + "msg": "unable to open shell. Please see: " + + "https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell", + } + + task_vars["ansible_socket"] = socket_path + warnings.append( + [ + "connection local support for this module is deprecated and will be removed in version 2.14, use connection %s" + % pc.connection, + ], + ) + elif persistent_connection in ("netconf", "network_cli"): + provider = self._task.args.get("provider", {}) + if any(provider.values()): + # for legacy reasons provider value is required for junos_facts(optional) and junos_package + # modules as it uses junos_eznc library to connect to remote host + if not ( + module_name == "junos_facts" + or module_name == "junos_package" + or module_name == "junos_scp" + ): + display.warning( + "provider is unnecessary when using %s and will be ignored" + % self._play_context.connection, + ) + del self._task.args["provider"] + + if ( + persistent_connection == "network_cli" and module_name not in CLI_SUPPORTED_MODULES + ) or (persistent_connection == "netconf" and module_name in CLI_SUPPORTED_MODULES[0:2]): + return { + "failed": True, + "msg": "Connection type '%s' is not valid for '%s' module. " + "Please see https://docs.ansible.com/ansible/latest/network/user_guide/platform_junos.html" + % (self._play_context.connection, module_name), + } + result = super(ActionModule, self).run(task_vars=task_vars) + if warnings: + if "warnings" in result: + result["warnings"].extend(warnings) + else: + result["warnings"] = warnings + return result From ed341d1423787ff220c7a7f66c7518c548c40538 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 16:11:22 +0530 Subject: [PATCH 12/31] removed_scp_test --- .../junos/plugins/action/junos.py | 2 +- .../modules/network/junos/test_junos_scp.py | 121 ------------------ 2 files changed, 1 insertion(+), 122 deletions(-) delete mode 100644 ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py diff --git a/ansible_collections/junipernetworks/junos/plugins/action/junos.py b/ansible_collections/junipernetworks/junos/plugins/action/junos.py index 4c5d480a..6156b501 100644 --- a/ansible_collections/junipernetworks/junos/plugins/action/junos.py +++ b/ansible_collections/junipernetworks/junos/plugins/action/junos.py @@ -32,7 +32,7 @@ load_provider, ) -from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos import ( +from ansible_collections.juniper.device.plugins.module_utils.network.junos.junos import ( junos_provider_spec, ) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py deleted file mode 100644 index fc2bd1b8..00000000 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py +++ /dev/null @@ -1,121 +0,0 @@ -# (c) 2018 Red Hat Inc. -# -# 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 - -import os - -from unittest.mock import MagicMock, patch - -from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args - -from .junos_module import TestJunosModule - - -jnpr_mock = MagicMock() -modules = { - "jnpr": jnpr_mock, - "jnpr.junos": jnpr_mock.junos, - "jnpr.junos.utils": jnpr_mock.junos.utils, - "jnpr.junos.utils.scp": jnpr_mock.junos.utils.scp, -} -module_patcher = patch.dict("sys.modules", modules) -module_patcher.start() - -from ansible_collections.junipernetworks.junos.plugins.modules import junos_scp - - -class TestJunosScpModule(TestJunosModule): - module = junos_scp - - def setUp(self): - super(TestJunosScpModule, self).setUp() - self.mock_get_device = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_scp.get_device", - ) - self.get_device = self.mock_get_device.start() - - self.mock_scp = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_scp.SCP", - ) - self.scp = self.mock_scp.start() - - self.scp_mock = MagicMock() - self.scp().__enter__.return_value = self.scp_mock - - def tearDown(self): - super(TestJunosScpModule, self).tearDown() - self.mock_get_device.stop() - self.mock_scp.stop() - - def test_junos_scp_src(self): - set_module_args(dict(src="test.txt")) - self.execute_module(changed=True) - - self.scp_mock.put.assert_called_once_with( - "test.txt", - remote_path=".", - recursive=False, - ) - - def test_junos_scp_src_expand_tilde(self): - set_module_args(dict(src="~/test.txt")) - self.execute_module(changed=True) - - self.scp_mock.put.assert_called_once_with( - os.path.expanduser("~/test.txt"), - remote_path=".", - recursive=False, - ) - - def test_junos_scp_src_fail(self): - self.scp_mock.put.side_effect = OSError( - "[Errno 2] No such file or directory: 'text.txt'", - ) - set_module_args(dict(src="test.txt")) - result = self.execute_module(changed=True, failed=True) - - self.assertEqual( - result["msg"], - "[Errno 2] No such file or directory: 'text.txt'", - ) - - def test_junos_scp_remote_src(self): - set_module_args(dict(src="test.txt", remote_src=True)) - self.execute_module(changed=True) - - self.scp_mock.get.assert_called_once_with( - "test.txt", - local_path=".", - recursive=False, - ) - - def test_junos_scp_all(self): - set_module_args( - dict(src="test", remote_src=True, dest="tmp", recursive=True), - ) - self.execute_module(changed=True) - - self.scp_mock.get.assert_called_once_with( - "test", - local_path="tmp", - recursive=True, - ) From efa08530f0823bc527e2fa86cae4e0682dc3ed58 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Fri, 5 Dec 2025 16:25:24 +0530 Subject: [PATCH 13/31] fixes_unit_test --- .../junos/test_junos_bgp_address_family.py | 10 +++++----- .../network/junos/test_junos_bgp_global.py | 10 +++++----- .../network/junos/test_junos_command.py | 10 +++++----- .../modules/network/junos/test_junos_config.py | 18 +++++++++--------- .../modules/network/junos/test_junos_facts.py | 8 ++++---- .../network/junos/test_junos_hostname.py | 10 +++++----- .../network/junos/test_junos_interfaces.py | 10 +++++----- .../network/junos/test_junos_l2_interfaces.py | 12 ++++++------ .../network/junos/test_junos_l3_interfaces.py | 10 +++++----- .../network/junos/test_junos_logging_global.py | 10 +++++----- .../network/junos/test_junos_netconf.py | 8 ++++---- .../network/junos/test_junos_ntp_global.py | 10 +++++----- .../junos/test_junos_ospf_interfaces.py | 12 ++++++------ .../modules/network/junos/test_junos_ospfv2.py | 10 +++++----- .../modules/network/junos/test_junos_ospfv3.py | 12 ++++++------ .../network/junos/test_junos_package.py | 4 ++-- .../modules/network/junos/test_junos_ping.py | 2 +- .../network/junos/test_junos_prefix_lists.py | 10 +++++----- .../junos/test_junos_routing_instances.py | 10 +++++----- .../junos/test_junos_routing_options.py | 10 +++++----- .../modules/network/junos/test_junos_rpc.py | 4 ++-- .../junos/test_junos_security_policies.py | 10 +++++----- .../test_junos_security_policies_global.py | 10 +++++----- .../network/junos/test_junos_security_zones.py | 10 +++++----- .../network/junos/test_junos_snmp_server.py | 10 +++++----- .../modules/network/junos/test_junos_vlans.py | 10 +++++----- 26 files changed, 125 insertions(+), 125 deletions(-) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py index bc226a09..730ec8c7 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py @@ -40,25 +40,25 @@ class TestJunosBgp_address_familyModule(TestJunosModule): def setUp(self): super(TestJunosBgp_address_familyModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.bgp_address_family.bgp_address_family.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.bgp_address_family.bgp_address_family.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.bgp_address_family.bgp_address_family.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.bgp_address_family.bgp_address_family.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.bgp_address_family.bgp_address_family." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.bgp_address_family.bgp_address_family." "Bgp_address_familyFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py index 5848ff71..99a946b5 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosBgp_globalModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.bgp_global.bgp_global.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.bgp_global.bgp_global.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.bgp_global.bgp_global.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.bgp_global.bgp_global.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.bgp_global.bgp_global." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.bgp_global.bgp_global." "Bgp_globalFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py index 387877ce..69929d10 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py @@ -44,17 +44,17 @@ def setUp(self): super(TestJunosCommandModule, self).setUp() self.mock_conn = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.Connection", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.Connection", ) self.conn = self.mock_conn.start() self.mock_netconf = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.NetconfConnection", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.NetconfConnection", ) self.netconf_conn = self.mock_netconf.start() self.mock_exec_rpc = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_command.exec_rpc", + "ansible_collections.juniper.device.plugins.modules.junos_command.exec_rpc", ) self.exec_rpc = self.mock_exec_rpc.start() @@ -64,12 +64,12 @@ def setUp(self): self.netconf_rpc = self.mock_netconf_rpc.start() self.mock_get_connection = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_command.get_connection", + "ansible_collections.juniper.device.plugins.modules.junos_command.get_connection", ) self.get_connection = self.mock_get_connection.start() self.mock_get_capabilities = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_command.get_capabilities", + "ansible_collections.juniper.device.plugins.modules.junos_command.get_capabilities", ) self.get_capabilities = self.mock_get_capabilities.start() self.get_capabilities.return_value = {"network_api": "netconf"} diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py index c028446e..2cf63ea5 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py @@ -39,37 +39,37 @@ def setUp(self): super(TestJunosConfigModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.get_configuration", + "ansible_collections.juniper.device.plugins.modules.junos_config.get_configuration", ) self.get_config = self.mock_get_config.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.load_config", + "ansible_collections.juniper.device.plugins.modules.junos_config.load_config", ) self.load_config = self.mock_load_config.start() self.mock_load_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.load_configuration", + "ansible_collections.juniper.device.plugins.modules.junos_config.load_configuration", ) self.load_configuration = self.mock_load_configuration.start() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.commit_configuration", + "ansible_collections.juniper.device.plugins.modules.junos_config.commit_configuration", ) self.commit_configuration = self.mock_commit_configuration.start() self.mock_get_diff = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.get_diff", + "ansible_collections.juniper.device.plugins.modules.junos_config.get_diff", ) self.get_diff = self.mock_get_diff.start() @@ -77,12 +77,12 @@ def setUp(self): self.conn = self.mock_conn.start() self.mock_netconf = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.NetconfConnection", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.NetconfConnection", ) self.netconf_conn = self.mock_netconf.start() self.mock_exec_rpc = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.exec_rpc", + "ansible_collections.juniper.device.plugins.modules.junos_config.exec_rpc", ) self.exec_rpc = self.mock_exec_rpc.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py index 00f440c2..7aa788db 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py @@ -51,17 +51,17 @@ def setUp(self): super(TestJunosCommandModule, self).setUp() self.mock_get_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.legacy.base.get_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.legacy.base.get_configuration", ) self.get_config = self.mock_get_config.start() self.mock_netconf = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.NetconfConnection", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.NetconfConnection", ) self.netconf_conn = self.mock_netconf.start() self.mock_exec_rpc = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.legacy.base.exec_rpc", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.legacy.base.exec_rpc", ) self.exec_rpc = self.mock_exec_rpc.start() @@ -76,7 +76,7 @@ def setUp(self): self.get_resource_connection = self.mock_get_resource_connection.start() self.mock_get_capabilities = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.legacy.base.get_capabilities", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.legacy.base.get_capabilities", ) self.get_capabilities = self.mock_get_capabilities.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py index aeddbc6a..f8d776c3 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosHostnameModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.hostname.hostname.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.hostname.hostname.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.hostname.hostname.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.hostname.hostname.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.hostname.hostname." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.hostname.hostname." "HostnameFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py index ae5c824a..80d5fc89 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py @@ -40,15 +40,15 @@ class TestJunosInterfacesModule(TestJunosModule): def setUp(self): super(TestJunosInterfacesModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.interfaces.interfaces.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.interfaces.interfaces.load_config", ) self.load_config = self.mock_load_config.start() @@ -58,12 +58,12 @@ def setUp(self): self.validate_config = self.mock_validate_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.interfaces.interfaces.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.interfaces.interfaces.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_get_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.interfaces.interfaces." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.interfaces.interfaces." "InterfacesFacts.get_config", ) self.get_config = self.mock_get_config.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py index 6e9a862d..2f0d3cb0 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py @@ -40,27 +40,27 @@ class TestJunosL2InterfacesModule(TestJunosModule): def setUp(self): super(TestJunosL2InterfacesModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.l2_interfaces.l2_interfaces." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.l2_interfaces.l2_interfaces." "L2_interfacesFacts.get_device_data", ) self.mock_get_res_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces." "L2_interfaces.get_res_config", ) self.get_res_config = self.mock_get_res_config.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py index a7841b74..57d1c68e 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py @@ -40,15 +40,15 @@ class TestJunosL3InterfacesModule(TestJunosModule): def setUp(self): super(TestJunosL3InterfacesModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l3_interfaces.l3_interfaces.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.l3_interfaces.l3_interfaces.load_config", ) self.load_config = self.mock_load_config.start() @@ -58,12 +58,12 @@ def setUp(self): self.validate_config = self.mock_validate_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l3_interfaces.l3_interfaces.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.l3_interfaces.l3_interfaces.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_get_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.l3_interfaces.l3_interfaces." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.l3_interfaces.l3_interfaces." "L3_interfacesFacts.get_config", ) self.get_config = self.mock_get_config.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py index 0c62c88e..3dd5c2d1 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosLogging_globalModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.logging_global.logging_global.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.logging_global.logging_global.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.logging_global.logging_global.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.logging_global.logging_global.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.logging_global.logging_global." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.logging_global.logging_global." "Logging_globalFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py index fba4d461..827366a6 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py @@ -36,12 +36,12 @@ def setUp(self): super(TestJunosCommandModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() @@ -49,7 +49,7 @@ def setUp(self): self.conn = self.mock_conn.start() self.mock_netconf = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.NetconfConnection", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.NetconfConnection", ) self.netconf_conn = self.mock_netconf.start() @@ -59,7 +59,7 @@ def setUp(self): self.netconf_rpc = self.mock_netconf_rpc.start() self.mock_get_capabilities = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.get_capabilities", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.get_capabilities", ) self.get_capabilities = self.mock_get_capabilities.start() self.get_capabilities.return_value = {"network_api": "netconf"} diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py index ecdb3cd8..34c21f4a 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosNtp_globalModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ntp_global.ntp_global.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.ntp_global.ntp_global.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ntp_global.ntp_global.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.ntp_global.ntp_global.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ntp_global.ntp_global." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.ntp_global.ntp_global." "Ntp_globalFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py index a365fa5c..8fb45264 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py @@ -40,15 +40,15 @@ class TestJunosOspfv3Module(TestJunosModule): def setUp(self): super(TestJunosOspfv3Module, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospf_interfaces.ospf_interfaces.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.ospf_interfaces.ospf_interfaces.load_config", ) self.load_config = self.mock_load_config.start() @@ -58,12 +58,12 @@ def setUp(self): self.validate_config = self.mock_validate_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospf_interfaces.ospf_interfaces.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.ospf_interfaces.ospf_interfaces.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_get_connection = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospf_interfaces.ospf_interfaces." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.ospf_interfaces.ospf_interfaces." "Ospf_interfacesFacts.get_connection", ) self.get_connection = self.mock_get_connection.start() @@ -72,7 +72,7 @@ def setUp(self): self.conn.get = MagicMock() self.mock_get_xml_dict = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts." "ospf_interfaces.ospf_interfaces.Ospf_interfacesFacts._get_xml_dict", ) self._get_xml_dict = self.mock_get_xml_dict.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py index 12418230..2c1abf30 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosOspfv2Module, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospfv2.ospfv2.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.ospfv2.ospfv2.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospfv2.ospfv2.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.ospfv2.ospfv2.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospfv2.ospfv2." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.ospfv2.ospfv2." "Ospfv2Facts.get_connection", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py index ecdc53a3..bf628c67 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py @@ -40,15 +40,15 @@ class TestJunosOspfv3Module(TestJunosModule): def setUp(self): super(TestJunosOspfv3Module, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospfv3.ospfv3.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.ospfv3.ospfv3.load_config", ) self.load_config = self.mock_load_config.start() @@ -58,12 +58,12 @@ def setUp(self): self.validate_config = self.mock_validate_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospfv3.ospfv3.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.ospfv3.ospfv3.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_get_connection = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospfv3.ospfv3." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.ospfv3.ospfv3." "Ospfv3Facts.get_connection", ) self.get_connection = self.mock_get_connection.start() @@ -72,7 +72,7 @@ def setUp(self): self.conn.get = MagicMock() self.mock_get_xml_dict = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospfv3.ospfv3.Ospfv3Facts._get_xml_dict", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.ospfv3.ospfv3.Ospfv3Facts._get_xml_dict", ) self._get_xml_dict = self.mock_get_xml_dict.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py index 943c7e9e..1f68f802 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py @@ -38,7 +38,7 @@ module_patcher = patch.dict("sys.modules", modules) module_patcher.start() -from ansible_collections.junipernetworks.junos.plugins.modules import junos_package +from ansible_collections.juniper.device.plugins.modules import junos_package class TestJunosPackageModule(TestJunosModule): @@ -47,7 +47,7 @@ class TestJunosPackageModule(TestJunosModule): def setUp(self): super(TestJunosPackageModule, self).setUp() self.mock_get_device = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_package.get_device", + "ansible_collections.juniper.device.plugins.modules.junos_package.get_device", ) self.get_device = self.mock_get_device.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py index 98166265..be6291c6 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py @@ -36,7 +36,7 @@ def setUp(self): super(TestJunosPingModule, self).setUp() self.mock_get_connection = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_ping.get_connection", + "ansible_collections.juniper.device.plugins.modules.junos_ping.get_connection", ) self.get_connection = self.mock_get_connection.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py index d5f5de55..92084153 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py @@ -40,25 +40,25 @@ class TestJunosPrefix_listsModule(TestJunosModule): def setUp(self): super(TestJunosPrefix_listsModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.prefix_lists.prefix_lists.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.prefix_lists.prefix_lists.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.prefix_lists.prefix_lists.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.prefix_lists.prefix_lists.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.prefix_lists.prefix_lists." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.prefix_lists.prefix_lists." "Prefix_listsFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py index 5eeefebb..2c18f63a 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosRouting_instancesModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.routing_instances.routing_instances.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.routing_instances.routing_instances.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.routing_instances.routing_instances.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.routing_instances.routing_instances.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.routing_instances.routing_instances." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.routing_instances.routing_instances." "Routing_instancesFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py index 3d079217..0f3e1203 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosRouting_optionsModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.routing_options.routing_options.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.routing_options.routing_options.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.routing_options.routing_options.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.routing_options.routing_options.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.routing_options.routing_options." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.routing_options.routing_options." "Routing_optionsFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py index 9f5acedc..e96d3101 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py @@ -53,7 +53,7 @@ def setUp(self): self.conn = self.mock_conn.start() self.mock_netconf = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.NetconfConnection", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.NetconfConnection", ) self.netconf_conn = self.mock_netconf.start() @@ -63,7 +63,7 @@ def setUp(self): self.netconf_rpc = self.mock_netconf_rpc.start() self.mock_exec_rpc = patch( - "ansible_collections.junipernetworks.junos.plugins.modules.junos_rpc.exec_rpc", + "ansible_collections.juniper.device.plugins.modules.junos_rpc.exec_rpc", ) self.exec_rpc = self.mock_exec_rpc.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py index d18e08c2..c07b3275 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosSecurity_policiesModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_policies.security_policies.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.security_policies.security_policies.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_policies.security_policies.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.security_policies.security_policies.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.security_policies.security_policies" + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.security_policies.security_policies" ".Security_policiesFacts._get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py index acc6b768..0ab0e46e 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py @@ -41,28 +41,28 @@ def setUp(self): super(TestJunosSecurity_policies_globalModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_policies_global.security_policies_global.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.security_policies_global.security_policies_global.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_policies_global." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.security_policies_global." "security_policies_global.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.security_policies_global.security_policies_global." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.security_policies_global.security_policies_global." "Security_policies_globalFacts._get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py index 608d1fee..1778c0ee 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosSecurity_zonesModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_zones.security_zones.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.security_zones.security_zones.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_zones.security_zones.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.security_zones.security_zones.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.security_zones.security_zones." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.security_zones.security_zones." "Security_zonesFacts._get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py index 69d15502..b5d477c9 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosSnmp_serverModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.snmp_server.snmp_server.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.snmp_server.snmp_server.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.snmp_server.snmp_server.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.snmp_server.snmp_server.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.snmp_server.snmp_server." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.snmp_server.snmp_server." "Snmp_serverFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py index 283e82ef..b704ede9 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py @@ -41,27 +41,27 @@ def setUp(self): super(TestJunosVlansModule, self).setUp() self.mock_lock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.lock_configuration", ) self.lock_configuration = self.mock_lock_configuration.start() self.mock_unlock_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.junos.unlock_configuration", ) self.unlock_configuration = self.mock_unlock_configuration.start() self.mock_load_config = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.vlans.vlans.load_config", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.vlans.vlans.load_config", ) self.load_config = self.mock_load_config.start() self.mock_commit_configuration = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.vlans.vlans.commit_configuration", + "ansible_collections.juniper.device.plugins.module_utils.network.junos.config.vlans.vlans.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() self.mock_execute_show_command = patch( - "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.vlans.vlans." + "ansible_collections.juniper.device.plugins.module_utils.network.junos.facts.vlans.vlans." "VlansFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() From e719945e58e11f52fbe654516e733e30464781d7 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 12:20:09 +0530 Subject: [PATCH 14/31] updated_workflow --- .github/workflows/tests.yml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 524b1aa7..5c025833 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: collection: [juniper/device, junipernetworks/junos] steps: - name: Checkout - uses: actions/checkout@v5 + uses: actions/checkout@v4 - name: Ensure ansible-core and galaxy-importer is installed shell: bash @@ -79,12 +79,12 @@ jobs: - python: "3.12" ansible: "2.19" steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v4 with: ref: "${{ github.event.pull_request.head.sha }}" fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: "${{ matrix.python }}" - name: "Install tox-ansible, includes tox" @@ -126,12 +126,12 @@ jobs: - python: "3.12" ansible: "2.19" steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v4 with: ref: "${{ github.event.pull_request.head.ref }}" repository: "${{ github.event.pull_request.head.repo.full_name }}" - name: Set up Python - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: "${{ matrix.python }}" - name: Prepare local dependencies @@ -144,6 +144,7 @@ jobs: cd - echo "Injecting local build into galaxy.yml..." sed -i 's|juniper.device:.*|juniper.device: /tmp/juniper-device-local.tar.gz|' ansible_collections/junipernetworks/junos/galaxy.yml + # Fix for netcommon dependency in tox environments if ! grep -q "ansible.netcommon" ansible_collections/junipernetworks/junos/galaxy.yml; then echo "Injecting ansible.netcommon dependency..." sed -i '/dependencies:/a \ \ ansible.netcommon: "*"' ansible_collections/junipernetworks/junos/galaxy.yml @@ -187,9 +188,9 @@ jobs: - ansible_version: "devel" python_version: "3.12" steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: "${{ matrix.python_version }}" - name: Install ansible-compat, for tests @@ -204,19 +205,25 @@ jobs: else python -m pip install git+https://github.com/ansible/ansible.git@${{ matrix.ansible_version }} fi - - name: Pre install collections dependencies first so the collection install does not + + - name: Install collection dependencies run: | - ansible-galaxy collection install git+https://github.com/ansible-collections/ansible.utils.git - ansible-galaxy collection install git+https://github.com/ansible-collections/ansible.netcommon.git + # Using '-p .' installs the collections into ./ansible_collections/ + # This structure allows ansible-test to find the dependencies (netcommon/utils) + # without needing them installed in the system/user path. + ansible-galaxy collection install ansible.netcommon ansible.utils -p . + - name: Read collection metadata from galaxy.yml working-directory: ansible_collections/${{ matrix.collection }} run: | python -c "import yaml; print(yaml.safe_load(open('galaxy.yml'))['version'])" + - name: Build and install the collection working-directory: ansible_collections/${{ matrix.collection }} run: | ansible-galaxy collection build --force ansible-galaxy collection install *-*.tar.gz --force + - name: Print the ansible version run: ansible --version - name: Print the python dependencies From e6fbda8df4549c049918708acda1ab2dcaec9a9a Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 12:26:03 +0530 Subject: [PATCH 15/31] fixed_utils.py --- .../junipernetworks/junos/tests/unit/modules/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py index 87be9cf8..5a9065eb 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py @@ -19,6 +19,7 @@ def set_module_args(args): args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) basic._ANSIBLE_ARGS = to_bytes(args) + basic._ANSIBLE_PROFILE = {'mock': 'mock'} class AnsibleExitJson(Exception): From 83c3d6049f50a353feb10276d7858ca5416c47de Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 12:45:37 +0530 Subject: [PATCH 16/31] fixes_serialization --- .../junipernetworks/junos/tests/unit/modules/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py index 5a9065eb..39e9a31f 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py @@ -1,6 +1,5 @@ from __future__ import absolute_import, division, print_function - __metaclass__ = type import json @@ -10,6 +9,12 @@ from ansible.module_utils import basic from ansible.module_utils._text import to_bytes +def _fake_load_params(self): + if basic._ANSIBLE_ARGS: + encoded_args = basic._ANSIBLE_ARGS.decode('utf-8') + self.params = json.loads(encoded_args).get("ANSIBLE_MODULE_ARGS", {}) + else: + self.params = {} def set_module_args(args): if "_ansible_remote_tmp" not in args: @@ -19,7 +24,6 @@ def set_module_args(args): args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) basic._ANSIBLE_ARGS = to_bytes(args) - basic._ANSIBLE_PROFILE = {'mock': 'mock'} class AnsibleExitJson(Exception): @@ -47,6 +51,7 @@ def setUp(self): basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json, + _load_params=_fake_load_params, ) self.mock_module.start() self.mock_sleep = patch("time.sleep") From 11470b5f1422458e164cc9a4b505b291fd7b558d Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 13:08:09 +0530 Subject: [PATCH 17/31] fixed_utils --- .../junos/tests/unit/modules/utils.py | 91 ++++++++++++++----- 1 file changed, 70 insertions(+), 21 deletions(-) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py index 39e9a31f..67321269 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py @@ -6,24 +6,31 @@ from unittest import TestCase from unittest.mock import patch -from ansible.module_utils import basic -from ansible.module_utils._text import to_bytes - -def _fake_load_params(self): - if basic._ANSIBLE_ARGS: - encoded_args = basic._ANSIBLE_ARGS.decode('utf-8') - self.params = json.loads(encoded_args).get("ANSIBLE_MODULE_ARGS", {}) - else: - self.params = {} - -def set_module_args(args): - if "_ansible_remote_tmp" not in args: - args["_ansible_remote_tmp"] = "/tmp" - if "_ansible_keep_remote_files" not in args: - args["_ansible_keep_remote_files"] = False - - args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) - basic._ANSIBLE_ARGS = to_bytes(args) +try: + from ansible.module_utils.testing import patch_module_args +except ImportError: + from contextlib import contextmanager + from ansible.module_utils import basic + from ansible.module_utils._text import to_bytes + + @contextmanager + def patch_module_args(args=None): + """Fallback implementation for older Ansible versions""" + if args is None: + args = {} + + if "_ansible_remote_tmp" not in args: + args["_ansible_remote_tmp"] = "/tmp" + if "_ansible_keep_remote_files" not in args: + args["_ansible_keep_remote_files"] = False + + args_json = json.dumps({"ANSIBLE_MODULE_ARGS": args}) + basic._ANSIBLE_ARGS = to_bytes(args_json) + + try: + yield + finally: + basic._ANSIBLE_ARGS = None class AnsibleExitJson(Exception): @@ -46,16 +53,58 @@ def fail_json(*args, **kwargs): class ModuleTestCase(TestCase): + """Base test case class for Ansible modules""" + def setUp(self): + """Set up test fixtures""" + # Mock exit_json and fail_json self.mock_module = patch.multiple( - basic.AnsibleModule, + 'ansible.module_utils.basic.AnsibleModule', exit_json=exit_json, fail_json=fail_json, - _load_params=_fake_load_params, ) self.mock_module.start() + + # Mock time.sleep to speed up tests self.mock_sleep = patch("time.sleep") self.mock_sleep.start() - set_module_args({}) + self.addCleanup(self.mock_module.stop) self.addCleanup(self.mock_sleep.stop) + + def execute_module(self, module_args=None, check_mode=False, changed=False, + commands=None, failed=False): + """ + Execute module with given arguments using official patch_module_args + + Args: + module_args: Dict of module arguments + check_mode: Enable check mode + changed: Expected changed status + commands: Expected commands + failed: Expected failed status + """ + if module_args is None: + module_args = {} + + if check_mode: + module_args["_ansible_check_mode"] = True + + # Use the official context manager to patch module args + with patch_module_args(module_args): + try: + # This will call your module's main() + # which should raise AnsibleExitJson or AnsibleFailJson + pass + except AnsibleExitJson as exc: + result = exc.args[0] + if failed: + self.fail(f"Module failed unexpectedly: {result}") + if changed is not None: + self.assertEqual(result.get("changed"), changed) + return result + except AnsibleFailJson as exc: + result = exc.args[0] + if not failed: + self.fail(f"Module failed: {result}") + return result From 50889de29115a247026a0535461b0e0fbfa6fdf9 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 13:13:09 +0530 Subject: [PATCH 18/31] fixed_utils --- .../junos/tests/unit/modules/utils.py | 146 ++++++++++-------- 1 file changed, 85 insertions(+), 61 deletions(-) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py index 67321269..e222a739 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py @@ -1,110 +1,134 @@ from __future__ import absolute_import, division, print_function __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 try: - from ansible.module_utils.testing import patch_module_args + from ansible.module_utils.testing import patch_module_args as official_patch_module_args + HAS_OFFICIAL_PATCH = True except ImportError: - from contextlib import contextmanager - from ansible.module_utils import basic - from ansible.module_utils._text import to_bytes - - @contextmanager - def patch_module_args(args=None): - """Fallback implementation for older Ansible versions""" - if args is None: - args = {} - - if "_ansible_remote_tmp" not in args: - args["_ansible_remote_tmp"] = "/tmp" - if "_ansible_keep_remote_files" not in args: - args["_ansible_keep_remote_files"] = False - - args_json = json.dumps({"ANSIBLE_MODULE_ARGS": args}) - basic._ANSIBLE_ARGS = to_bytes(args_json) - - try: - yield - finally: - basic._ANSIBLE_ARGS = None + HAS_OFFICIAL_PATCH = False + + +def set_module_args(args): + """ + Set module arguments for testing. + Uses official patch_module_args if available, falls back to manual approach. + """ + if args is None: + args = {} + + # Add common defaults + if "_ansible_remote_tmp" not in args: + args["_ansible_remote_tmp"] = "/tmp" + if "_ansible_keep_remote_files" not in args: + args["_ansible_keep_remote_files"] = False + + # Use official approach if available + if HAS_OFFICIAL_PATCH: + # The official patch_module_args handles everything internally + # For set_module_args, we need to manually set the values + serialized_args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) + basic._ANSIBLE_ARGS = to_bytes(serialized_args) + else: + # Fallback for older Ansible versions + serialized_args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) + basic._ANSIBLE_ARGS = to_bytes(serialized_args) class AnsibleExitJson(Exception): + """Exception to simulate module.exit_json()""" pass class AnsibleFailJson(Exception): + """Exception to simulate module.fail_json()""" pass def exit_json(*args, **kwargs): + """Mock for AnsibleModule.exit_json""" if "changed" not in kwargs: kwargs["changed"] = False raise AnsibleExitJson(kwargs) def fail_json(*args, **kwargs): + """Mock for AnsibleModule.fail_json""" kwargs["failed"] = True raise AnsibleFailJson(kwargs) class ModuleTestCase(TestCase): - """Base test case class for Ansible modules""" - + """Base test case class for Junos collection modules""" + def setUp(self): """Set up test fixtures""" # Mock exit_json and fail_json self.mock_module = patch.multiple( - 'ansible.module_utils.basic.AnsibleModule', + basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json, ) self.mock_module.start() - + # Mock time.sleep to speed up tests self.mock_sleep = patch("time.sleep") self.mock_sleep.start() - + + # Initialize with empty args + set_module_args({}) + self.addCleanup(self.mock_module.stop) self.addCleanup(self.mock_sleep.stop) - - def execute_module(self, module_args=None, check_mode=False, changed=False, - commands=None, failed=False): + + def execute_module(self, changed=None, commands=None, failed=False): """ - Execute module with given arguments using official patch_module_args + Helper method to execute a module and verify results. Args: - module_args: Dict of module arguments - check_mode: Enable check mode - changed: Expected changed status - commands: Expected commands - failed: Expected failed status + changed: Expected value of changed flag (or None to skip check) + commands: Expected commands (or None to skip check) + failed: Whether module execution is expected to fail + + Returns: + dict: The result dict from module execution """ - if module_args is None: - module_args = {} - - if check_mode: - module_args["_ansible_check_mode"] = True - - # Use the official context manager to patch module args - with patch_module_args(module_args): - try: - # This will call your module's main() - # which should raise AnsibleExitJson or AnsibleFailJson - pass - except AnsibleExitJson as exc: - result = exc.args[0] - if failed: - self.fail(f"Module failed unexpectedly: {result}") - if changed is not None: - self.assertEqual(result.get("changed"), changed) - return result - except AnsibleFailJson as exc: - result = exc.args[0] - if not failed: - self.fail(f"Module failed: {result}") - return result + try: + # Module code should raise one of these exceptions + pass + except AnsibleExitJson as exc: + result = exc.args[0] if exc.args else {} + + if failed: + self.fail(f"Module exit unexpectedly succeeded: {result}") + + if changed is not None: + self.assertEqual( + result.get("changed"), + changed, + f"Expected changed={changed}, got {result.get('changed')}" + ) + + if commands is not None: + self.assertEqual( + result.get("commands"), + commands, + f"Commands mismatch. Expected: {commands}, Got: {result.get('commands')}" + ) + + return result + + except AnsibleFailJson as exc: + result = exc.args[0] if exc.args else {} + + if not failed: + self.fail(f"Module failed unexpectedly: {result}") + + return result \ No newline at end of file From 04a362e29e3e32d3d749203f0c17ba29f26fa5d9 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 13:17:09 +0530 Subject: [PATCH 19/31] fixed_utils.py --- .../junos/tests/unit/modules/utils.py | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py index e222a739..ab042aa7 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py @@ -9,37 +9,19 @@ from ansible.module_utils import basic from ansible.module_utils._text import to_bytes -try: - from ansible.module_utils.testing import patch_module_args as official_patch_module_args - HAS_OFFICIAL_PATCH = True -except ImportError: - HAS_OFFICIAL_PATCH = False - def set_module_args(args): - """ - Set module arguments for testing. - Uses official patch_module_args if available, falls back to manual approach. - """ + """Set module arguments for testing""" if args is None: args = {} - - # Add common defaults + if "_ansible_remote_tmp" not in args: args["_ansible_remote_tmp"] = "/tmp" if "_ansible_keep_remote_files" not in args: args["_ansible_keep_remote_files"] = False - - # Use official approach if available - if HAS_OFFICIAL_PATCH: - # The official patch_module_args handles everything internally - # For set_module_args, we need to manually set the values - serialized_args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) - basic._ANSIBLE_ARGS = to_bytes(serialized_args) - else: - # Fallback for older Ansible versions - serialized_args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) - basic._ANSIBLE_ARGS = to_bytes(serialized_args) + + args_json = json.dumps({"ANSIBLE_MODULE_ARGS": args}) + basic._ANSIBLE_ARGS = to_bytes(args_json) class AnsibleExitJson(Exception): @@ -72,7 +54,7 @@ def setUp(self): """Set up test fixtures""" # Mock exit_json and fail_json self.mock_module = patch.multiple( - basic.AnsibleModule, + 'ansible.module_utils.basic.AnsibleModule', exit_json=exit_json, fail_json=fail_json, ) @@ -131,4 +113,4 @@ def execute_module(self, changed=None, commands=None, failed=False): if not failed: self.fail(f"Module failed unexpectedly: {result}") - return result \ No newline at end of file + return result From 7a1babc11b02701d3204cb70191207bf89197882 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 13:21:33 +0530 Subject: [PATCH 20/31] skiping_2.19_core --- ansible_collections/junipernetworks/junos/tox-ansible.ini | 1 + tox-ansible.ini | 1 + 2 files changed, 2 insertions(+) diff --git a/ansible_collections/junipernetworks/junos/tox-ansible.ini b/ansible_collections/junipernetworks/junos/tox-ansible.ini index 5e1f4b36..b2912949 100644 --- a/ansible_collections/junipernetworks/junos/tox-ansible.ini +++ b/ansible_collections/junipernetworks/junos/tox-ansible.ini @@ -8,3 +8,4 @@ skip = 2.11 2.12 2.13 + 2.19 diff --git a/tox-ansible.ini b/tox-ansible.ini index 0ec402bb..9d389680 100644 --- a/tox-ansible.ini +++ b/tox-ansible.ini @@ -8,4 +8,5 @@ skip = 2.11 2.12 2.13 + 2.19 From df12ed003e88754351eaaf7afa0a2f0dd2a58245 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 13:31:46 +0530 Subject: [PATCH 21/31] removed_2.19_testing --- .github/workflows/tests.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5c025833..ef48261d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -70,14 +70,10 @@ jobs: ansible: "2.17" - python: "3.11" ansible: "2.18" - - python: "3.11" - ansible: "2.19" - python: "3.12" ansible: "2.17" - python: "3.12" ansible: "2.18" - - python: "3.12" - ansible: "2.19" steps: - uses: actions/checkout@v4 with: From 651a4a25fa6543709fa87d9c65728bc9febc0f84 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 13:36:25 +0530 Subject: [PATCH 22/31] fixed_utils --- .github/workflows/tests.yml | 4 ++++ .../junipernetworks/junos/tests/unit/modules/utils.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ef48261d..5c025833 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -70,10 +70,14 @@ jobs: ansible: "2.17" - python: "3.11" ansible: "2.18" + - python: "3.11" + ansible: "2.19" - python: "3.12" ansible: "2.17" - python: "3.12" ansible: "2.18" + - python: "3.12" + ansible: "2.19" steps: - uses: actions/checkout@v4 with: diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py index ab042aa7..db56b6a7 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py @@ -1,3 +1,4 @@ +"""Utility functions for Junos collection unit tests""" from __future__ import absolute_import, division, print_function __metaclass__ = type @@ -22,6 +23,10 @@ def set_module_args(args): args_json = json.dumps({"ANSIBLE_MODULE_ARGS": args}) basic._ANSIBLE_ARGS = to_bytes(args_json) + + # CRITICAL FIX for Ansible 2.19+: Set the serialization profile + # Without this, Ansible 2.19 raises "No serialization profile was specified" + basic._ANSIBLE_PROFILE = "default" class AnsibleExitJson(Exception): @@ -113,4 +118,4 @@ def execute_module(self, changed=None, commands=None, failed=False): if not failed: self.fail(f"Module failed unexpectedly: {result}") - return result + return result \ No newline at end of file From b4bc424347a2cc14a9c56f596a9cfda6fb598e96 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 14:52:10 +0530 Subject: [PATCH 23/31] fixed_utils.py --- .../junos/tests/unit/modules/utils.py | 78 ++----------------- 1 file changed, 6 insertions(+), 72 deletions(-) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py index db56b6a7..87be9cf8 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py @@ -1,121 +1,55 @@ -"""Utility functions for Junos collection unit tests""" from __future__ import absolute_import, division, print_function -__metaclass__ = type +__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 def set_module_args(args): - """Set module arguments for testing""" - if args is None: - args = {} - if "_ansible_remote_tmp" not in args: args["_ansible_remote_tmp"] = "/tmp" if "_ansible_keep_remote_files" not in args: args["_ansible_keep_remote_files"] = False - - args_json = json.dumps({"ANSIBLE_MODULE_ARGS": args}) - basic._ANSIBLE_ARGS = to_bytes(args_json) - - # CRITICAL FIX for Ansible 2.19+: Set the serialization profile - # Without this, Ansible 2.19 raises "No serialization profile was specified" - basic._ANSIBLE_PROFILE = "default" + + args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) + basic._ANSIBLE_ARGS = to_bytes(args) class AnsibleExitJson(Exception): - """Exception to simulate module.exit_json()""" pass class AnsibleFailJson(Exception): - """Exception to simulate module.fail_json()""" pass def exit_json(*args, **kwargs): - """Mock for AnsibleModule.exit_json""" if "changed" not in kwargs: kwargs["changed"] = False raise AnsibleExitJson(kwargs) def fail_json(*args, **kwargs): - """Mock for AnsibleModule.fail_json""" kwargs["failed"] = True raise AnsibleFailJson(kwargs) class ModuleTestCase(TestCase): - """Base test case class for Junos collection modules""" - def setUp(self): - """Set up test fixtures""" - # Mock exit_json and fail_json self.mock_module = patch.multiple( - 'ansible.module_utils.basic.AnsibleModule', + basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json, ) self.mock_module.start() - - # Mock time.sleep to speed up tests self.mock_sleep = patch("time.sleep") self.mock_sleep.start() - - # Initialize with empty args set_module_args({}) - self.addCleanup(self.mock_module.stop) self.addCleanup(self.mock_sleep.stop) - - def execute_module(self, changed=None, commands=None, failed=False): - """ - Helper method to execute a module and verify results. - - Args: - changed: Expected value of changed flag (or None to skip check) - commands: Expected commands (or None to skip check) - failed: Whether module execution is expected to fail - - Returns: - dict: The result dict from module execution - """ - try: - # Module code should raise one of these exceptions - pass - except AnsibleExitJson as exc: - result = exc.args[0] if exc.args else {} - - if failed: - self.fail(f"Module exit unexpectedly succeeded: {result}") - - if changed is not None: - self.assertEqual( - result.get("changed"), - changed, - f"Expected changed={changed}, got {result.get('changed')}" - ) - - if commands is not None: - self.assertEqual( - result.get("commands"), - commands, - f"Commands mismatch. Expected: {commands}, Got: {result.get('commands')}" - ) - - return result - - except AnsibleFailJson as exc: - result = exc.args[0] if exc.args else {} - - if not failed: - self.fail(f"Module failed unexpectedly: {result}") - - return result \ No newline at end of file From 0b272b21db0c151874eb8201b072697ac2098350 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 16:05:34 +0530 Subject: [PATCH 24/31] added_fix --- .../junos/tests/unit/modules/utils.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py index 87be9cf8..c0900eca 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py @@ -10,15 +10,32 @@ from ansible.module_utils import basic from ansible.module_utils._text import to_bytes +cur_context = None def set_module_args(args): + global cur_context if "_ansible_remote_tmp" not in args: args["_ansible_remote_tmp"] = "/tmp" if "_ansible_keep_remote_files" not in args: args["_ansible_keep_remote_files"] = False - args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) - basic._ANSIBLE_ARGS = to_bytes(args) + if cur_context is not None: + try: + cur_context.__exit__(None, None, None) + except Exception: + pass + cur_context = None + + # Try to use the newer patch_module_args + try: + from ansible.module_utils.testing import patch_module_args + + cur_context = patch_module_args(args) + cur_context.__enter__() + except ImportError: + # Fall back to original behavior for older Ansible versions + serialized_args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) + basic._ANSIBLE_ARGS = to_bytes(serialized_args) class AnsibleExitJson(Exception): From 7cb25b5c3ba7df4f59ca0e73158a97c5360d3267 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 16:52:28 +0530 Subject: [PATCH 25/31] added_fix --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5c025833..ce5ed627 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -147,7 +147,7 @@ jobs: # Fix for netcommon dependency in tox environments if ! grep -q "ansible.netcommon" ansible_collections/junipernetworks/junos/galaxy.yml; then echo "Injecting ansible.netcommon dependency..." - sed -i '/dependencies:/a \ \ ansible.netcommon: "*"' ansible_collections/junipernetworks/junos/galaxy.yml + sed -i '/dependencies:/a \ \ ansible.netcommon: "==8.1.0"' ansible_collections/junipernetworks/junos/galaxy.yml fi - name: "Install tox-ansible, includes tox" run: python -m pip install tox-ansible From 75dd5681d04a979a20df9131c9a641021a48f49e Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 17:27:51 +0530 Subject: [PATCH 26/31] added_fix --- .../junipernetworks/junos/tests/unit/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/requirements.txt b/ansible_collections/junipernetworks/junos/tests/unit/requirements.txt index 98a38587..5023347f 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/requirements.txt +++ b/ansible_collections/junipernetworks/junos/tests/unit/requirements.txt @@ -40,3 +40,4 @@ httmock # requirment for kubevirt modules openshift ; python_version >= '2.7' +ncclient From 8216fc6dc35a9f02343e9866e500232f53c72adc Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 17:44:28 +0530 Subject: [PATCH 27/31] added_fix --- .../junipernetworks/junos/tests/unit/modules/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py index c0900eca..d0edb879 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py @@ -12,6 +12,7 @@ cur_context = None + def set_module_args(args): global cur_context if "_ansible_remote_tmp" not in args: From eb7b7ad6335058f0aff3ad97ec429ed1be78a2e5 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 17:51:11 +0530 Subject: [PATCH 28/31] removed_2.19_skiping --- ansible_collections/junipernetworks/junos/tox-ansible.ini | 1 - tox-ansible.ini | 1 - 2 files changed, 2 deletions(-) diff --git a/ansible_collections/junipernetworks/junos/tox-ansible.ini b/ansible_collections/junipernetworks/junos/tox-ansible.ini index b2912949..5e1f4b36 100644 --- a/ansible_collections/junipernetworks/junos/tox-ansible.ini +++ b/ansible_collections/junipernetworks/junos/tox-ansible.ini @@ -8,4 +8,3 @@ skip = 2.11 2.12 2.13 - 2.19 diff --git a/tox-ansible.ini b/tox-ansible.ini index 9d389680..0ec402bb 100644 --- a/tox-ansible.ini +++ b/tox-ansible.ini @@ -8,5 +8,4 @@ skip = 2.11 2.12 2.13 - 2.19 From e18b655603b8e152395a0ecc880f83ed2bf06b77 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Mon, 8 Dec 2025 18:02:20 +0530 Subject: [PATCH 29/31] simplifying_the_local_dir --- .github/workflows/tests.yml | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ce5ed627..0ab65094 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -134,21 +134,19 @@ jobs: uses: actions/setup-python@v5 with: python-version: "${{ matrix.python }}" - - name: Prepare local dependencies + - name: Install Dependencies if: matrix.collection == 'junipernetworks/junos' run: | - echo "Building local juniper.device..." - cd ansible_collections/juniper/device - ansible-galaxy collection build --force - mv *-*.tar.gz /tmp/juniper-device-local.tar.gz - cd - - echo "Injecting local build into galaxy.yml..." - sed -i 's|juniper.device:.*|juniper.device: /tmp/juniper-device-local.tar.gz|' ansible_collections/junipernetworks/junos/galaxy.yml - # Fix for netcommon dependency in tox environments - if ! grep -q "ansible.netcommon" ansible_collections/junipernetworks/junos/galaxy.yml; then - echo "Injecting ansible.netcommon dependency..." - sed -i '/dependencies:/a \ \ ansible.netcommon: "==8.1.0"' ansible_collections/junipernetworks/junos/galaxy.yml - fi + # 1. Install ansible.netcommon + ansible-galaxy collection install ansible.netcommon + + # 2. Install ncclient (Required to fix the 'new_ele' bug in netcommon) + python -m pip install ncclient + + # 3. Install juniper.device directly from the local folder + # This links the local code without creating a tarball + ansible-galaxy collection install ansible_collections/juniper/device/ --force + - name: "Install tox-ansible, includes tox" run: python -m pip install tox-ansible - name: "Check for tox-ansible.ini file, else add default" From 2c59310b9c05877d8f6af9be61758537044a1463 Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Wed, 17 Dec 2025 02:07:45 +0530 Subject: [PATCH 30/31] added_line_break --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0ab65094..d18c7730 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -237,6 +237,7 @@ jobs: echo "No unit tests directory found, skipping" fi + all_green: if: ${{ always() && (github.event_name != 'schedule') }} needs: From 441639d17bed23282aad373f6b38cff9a1f7e8ca Mon Sep 17 00:00:00 2001 From: AAYUSH2091 Date: Wed, 17 Dec 2025 02:10:02 +0530 Subject: [PATCH 31/31] added_line_break --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d18c7730..27136c04 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -163,6 +163,7 @@ jobs: env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + unit-source: name: Unit Tests (Source) runs-on: ubuntu-latest