diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 00000000..34e5461b --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,39 @@ +--- +name: Integration +on: + pull_request_target: + branches: [main] + types: + - labeled + - opened + - reopened + - synchronize + paths: + - "plugins/**" + - "tests/integration/**" + workflow_dispatch: + +jobs: + safe-to-test: + if: >- + github.event.label.name == 'safe to test' || + github.event.action != 'labeled' + uses: ansible-network/github_actions/.github/workflows/safe-to-test.yml@main + secrets: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + integration: + uses: ansible/ansible-content-actions/.github/workflows/network_integration.yaml@main + needs: + - safe-to-test + with: + lab_title: cisco_iosxr + network_os: cisco.iosxr.iosxr + pytest_addopts: "--color=yes -n 2 --log-level WARNING -vvv" + collection_pre_install: >- + git+https://github.com/ansible-collections/ansible.utils.git + git+https://github.com/ansible-collections/ansible.netcommon.git + secrets: + cml_ssh_password: ${{ secrets.CML_SSH_PASSWORD }} + virl_host: ${{ secrets.VIRL_HOST }} + virl_password: ${{ secrets.VIRL_PASSWORD }} diff --git a/.gitignore b/.gitignore index d9fe27b7..bda80280 100644 --- a/.gitignore +++ b/.gitignore @@ -89,3 +89,7 @@ tests/units/.coverage.* /SYMLINK_CACHE.json changelogs/.plugin-cache.yaml .ansible-test-timeout.json +.env +.pytest_cache +.virl +pytest-network.log diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/labs/single.yaml b/tests/integration/labs/single.yaml new file mode 100644 index 00000000..b4833681 --- /dev/null +++ b/tests/integration/labs/single.yaml @@ -0,0 +1,119 @@ +--- +lab: + description: "" + notes: "" + title: cisco.iosxr.iosxr + version: 0.2.2 +links: + - id: l0 + n1: n0 + n2: n1 + i1: i0 + i2: i1 + conditioning: {} + label: ext-conn-0-port<->xr9kv-0-MgmtEth0/RP0/CPU0/0 +annotations: [] +nodes: + - boot_disk_size: null + configuration: [] + cpu_limit: null + cpus: null + data_volume: null + hide_links: false + id: n0 + image_definition: null + label: ext-conn-0 + node_definition: external_connector + parameters: {} + ram: null + tags: [] + x: -440 + y: 0 + interfaces: + - id: i0 + label: port + slot: 0 + type: physical + - boot_disk_size: null + configuration: |2- + hostname iosxr + domain name ansible.com + username ansible + group root-lr + group cisco-support + secret 10 $6$9Px5C0KzVXTs6C0.$gB3T3oClVgZZ/4yp.QL1cFDGk8pSxyKMkf.JtuTr0R9QKxmkLkWG2jfAEd3k6QF8kWpOCDlZ.ybarYdXAMnxL/ + ! + aaa authentication login default local + cdp + line default + login authentication default + transport input ssh + ! + call-home + service active + contact smart-licensing + profile CiscoTAC-1 + active + destination transport-method email disable + destination transport-method http + ! + ! + control-plane + management-plane + inband + interface all + allow all + allow SSH + ! + ! + ! + ! + interface MgmtEth0/RP0/CPU0/0 + ipv4 address dhcp + no shutdown + ! + interface GigabitEthernet0/0/0/0 + shutdown + ! + router static + address-family ipv4 unicast + 0.0.0.0/0 192.168.255.1 + ! + ! + ssh timeout 60 + ssh server v2 + commit + end + cpu_limit: null + cpus: null + data_volume: null + hide_links: false + id: n1 + image_definition: null + label: xr9kv-0 + node_definition: iosxrv9000 + parameters: {} + ram: null + tags: [] + x: -160 + y: 0 + interfaces: + - id: i0 + label: Loopback0 + type: loopback + - id: i1 + label: MgmtEth0/RP0/CPU0/0 + slot: 0 + type: physical + - id: i2 + label: donotuse1 + slot: 1 + type: physical + - id: i3 + label: donotuse2 + slot: 2 + type: physical + - id: i4 + label: GigabitEthernet0/0/0/0 + slot: 3 + type: physical diff --git a/tests/integration/network-integration.cfg b/tests/integration/network-integration.cfg new file mode 100644 index 00000000..d12c1efe --- /dev/null +++ b/tests/integration/network-integration.cfg @@ -0,0 +1,4 @@ +[persistent_connection] +command_timeout = 100 +connect_timeout = 100 +connect_retry_timeout = 100 diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py new file mode 100644 index 00000000..eeda0eed --- /dev/null +++ b/tests/integration/test_integration.py @@ -0,0 +1,41 @@ +import subprocess + +import pytest + + +def run(ansible_project, environment): + __tracebackhide__ = True + args = [ + "ansible-navigator", + "run", + str(ansible_project.playbook), + "-i", + str(ansible_project.inventory), + "--ee", + "false", + "--mode", + "stdout", + "--pas", + str(ansible_project.playbook_artifact), + "--ll", + "debug", + "--lf", + str(ansible_project.log_file), + ] + process = subprocess.run( + args=args, + env=environment, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + check=False, + shell=False, + ) + if process.returncode: + print(process.stdout.decode("utf-8")) + print(process.stderr.decode("utf-8")) + + pytest.fail(reason=f"Integration test failed: {ansible_project.role}") + + +def test_integration(ansible_project, environment): + run(ansible_project, environment)