From 75beb02bf3a230f578d4ef98af76f11d0df273e0 Mon Sep 17 00:00:00 2001 From: Girish5tri Date: Mon, 28 Oct 2024 06:12:38 +0530 Subject: [PATCH 1/7] cml work --- .github/workflows/integration.yml | 38 ++++ pyproject.toml | 6 +- test-requirements.txt | 3 + tests/.gitignore | 1 + tests/integration/labs/single.yaml | 251 ++++++++++++++++++++++++++ tests/integration/test_integration.py | 43 +++++ 6 files changed, 340 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/integration.yml create mode 100644 tests/integration/labs/single.yaml create mode 100644 tests/integration/test_integration.py diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 000000000..a808cb5ea --- /dev/null +++ b/.github/workflows/integration.yml @@ -0,0 +1,38 @@ +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-network/github_actions/.github/workflows/integration.yml@main + needs: + - safe-to-test + with: + lab_title: cisco_ios + network_os: cisco.ios.ios + pytest_addopts: "--color=yes -n 2 --log-level WARNING -vvv --role-excludes=snmp_server" + 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 }} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index fa4225f3e..18428c38c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,8 @@ line-length = 100 [tool.pytest.ini_options] -addopts = ["-vvv", "-n", "2", "--log-level", "WARNING", "--color", "yes"] testpaths = ["tests"] -filterwarnings = ['ignore:AnsibleCollectionFinder has already been configured'] +filterwarnings = [ + 'ignore:AnsibleCollectionFinder has already been configured', + 'ignore:_AnsibleCollectionFinder.find_spec().*', +] \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt index 5a90586f2..4ab5dbdba 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,6 +3,9 @@ black==23.3.0 flake8 yamllint +# For CML +virl2-client==2.6.1 + # Unit test runner pytest-ansible pytest-xdist diff --git a/tests/.gitignore b/tests/.gitignore index ea1472ec1..89aaa51d1 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1 +1,2 @@ output/ +.env \ No newline at end of file diff --git a/tests/integration/labs/single.yaml b/tests/integration/labs/single.yaml new file mode 100644 index 000000000..47435813f --- /dev/null +++ b/tests/integration/labs/single.yaml @@ -0,0 +1,251 @@ +lab: + description: "Cisco IOS Integration Testing Lab" + notes: "" + title: "ios test" + version: 0.2.2 + +links: + - id: l0 + n1: n0 + n2: n1 + i1: i1 + i2: i0 + label: cat8000v-0-GigabitEthernet1<->ext-conn-0-port + +nodes: + - boot_disk_size: null + configuration: |2- + + !Command: show running-config + !Running configuration last done at: Mon Feb 12 07:11:33 2024 + !Time: Mon Feb 12 07:11:33 2024 + + version 17.11 + service timestamps debug datetime msec + service timestamps log datetime msec + no service password-encryption + ! + hostname Router1 + ! + boot-start-marker + boot-end-marker + ! + ! + no aaa new-model + ! + ! + no ip domain lookup + ip domain name test.example + ! + ! + login on-success log + ! + ! + no ip dhcp conflict logging + ! + ! + ! + crypto key generate rsa modulus 2048 + ! + ! + ! + username admin privilege 15 secret admin + ! + ! + ! + ! + ! + interface GigabitEthernet1 + ip address dhcp + no shutdown + ! + interface GigabitEthernet2 + no ip address + shutdown + ! + interface GigabitEthernet3 + no ip address + shutdown + ! + interface GigabitEthernet4 + no ip address + shutdown + ! + ! + no ip http server + no ip http secure-server + ! + ! + ! + ! + ! + control-plane + ! + ! + line con 0 + stopbits 1 + line vty 0 4 + login local + transport input ssh + ! + ! + ! + ! + ! + no logging console + end + cpu_limit: null + cpus: null + data_volume: null + hide_links: false + id: n0 + image_definition: null + label: cat8000v-0 + node_definition: cat8000v + ram: null + tags: [] + x: -200 + y: 0 + interfaces: + - id: i0 + label: Loopback0 + type: loopback + - id: i1 + label: GigabitEthernet1 + slot: 0 + type: physical + - id: i2 + label: GigabitEthernet2 + slot: 1 + type: physical + - id: i3 + label: GigabitEthernet3 + slot: 2 + type: physical + - id: i4 + label: GigabitEthernet4 + slot: 3 + type: physical + + - boot_disk_size: null + configuration: virbr0 + cpu_limit: null + cpus: null + data_volume: null + hide_links: false + id: n1 + image_definition: null + label: ext-conn-0 + node_definition: external_connector + ram: null + tags: [] + x: 160 + y: 0 + interfaces: + - id: i0 + label: port + slot: 0 + type: physical + +annotations: [] + + + + + + + + + + + + + +# annotations: [] +# nodes: +# - boot_disk_size: null +# configuration: | +# hostname Router1 +# ! +# username admin privilege 15 secret admin +# ! +# interface GigabitEthernet1 +# ip address dhcp +# no shutdown +# ! +# ip domain-name test.example +# crypto key generate rsa modulus 2048 +# ! +# line vty 0 4 +# login local +# transport input ssh +# ! +# no logging console +# cpu_limit: null +# cpus: null +# data_volume: null +# hide_links: false +# id: n0 +# image_definition: null +# label: cat8000v-0 +# node_definition: cat8000v +# parameters: {} +# ram: null +# tags: [] +# x: -200 +# y: 0 +# interfaces: +# - id: i0 +# label: Loopback0 +# type: loopback +# - id: i1 +# label: GigabitEthernet1 +# slot: 0 +# type: physical +# - id: i2 +# label: GigabitEthernet2 +# slot: 1 +# type: physical +# - id: i3 +# label: GigabitEthernet3 +# slot: 2 +# type: physical +# - id: i4 +# label: GigabitEthernet4 +# slot: 3 +# type: physical + +# - boot_disk_size: null +# configuration: virbr0 +# cpu_limit: null +# cpus: null +# data_volume: null +# hide_links: false +# id: n1 +# image_definition: null +# label: ext-conn-0 +# node_definition: external_connector +# parameters: {} +# ram: null +# tags: [] +# x: 160 +# y: 0 +# interfaces: +# - id: i0 +# label: port +# slot: 0 +# type: physical + +# links: +# - id: l0 +# n1: n0 +# n2: n1 +# i1: i1 +# i2: i0 +# label: cat8000v-0-GigabitEthernet1<->ext-conn-0-port + +# lab: +# description: "Cisco IOS Integration Testing Lab" +# notes: "" +# title: "ios test" +# version: 0.2.2 \ No newline at end of file diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py new file mode 100644 index 000000000..097dd0e84 --- /dev/null +++ b/tests/integration/test_integration.py @@ -0,0 +1,43 @@ +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), + "--skip-tags", + "local,nxapi", + ] + 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) \ No newline at end of file From f75863c0448b6fb3d7afdcdb7fdcb93a69dac56e Mon Sep 17 00:00:00 2001 From: Girish5tri <136325447+Girish5tri@users.noreply.github.com> Date: Mon, 28 Oct 2024 06:23:48 +0530 Subject: [PATCH 2/7] Create integrationone.yml --- .github/workflows/integrationone.yml | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/integrationone.yml diff --git a/.github/workflows/integrationone.yml b/.github/workflows/integrationone.yml new file mode 100644 index 000000000..f85bf2536 --- /dev/null +++ b/.github/workflows/integrationone.yml @@ -0,0 +1,38 @@ +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-network/github_actions/.github/workflows/integration.yml@main + needs: + - safe-to-test + with: + lab_title: cisco_ios + network_os: cisco.ios.ios + pytest_addopts: "--color=yes -n 2 --log-level WARNING -vvv --role-excludes=snmp_server" + 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 }} From 6e6d7e9c94e03f1f95350e7e2bf67063ee612c18 Mon Sep 17 00:00:00 2001 From: Girish5tri Date: Mon, 28 Oct 2024 06:49:08 +0530 Subject: [PATCH 3/7] updated --- .github/workflows/integrationone.yml | 38 ----- tests/integration/labs/single.yaml | 236 +++++---------------------- 2 files changed, 37 insertions(+), 237 deletions(-) delete mode 100644 .github/workflows/integrationone.yml diff --git a/.github/workflows/integrationone.yml b/.github/workflows/integrationone.yml deleted file mode 100644 index f85bf2536..000000000 --- a/.github/workflows/integrationone.yml +++ /dev/null @@ -1,38 +0,0 @@ -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-network/github_actions/.github/workflows/integration.yml@main - needs: - - safe-to-test - with: - lab_title: cisco_ios - network_os: cisco.ios.ios - pytest_addopts: "--color=yes -n 2 --log-level WARNING -vvv --role-excludes=snmp_server" - 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/tests/integration/labs/single.yaml b/tests/integration/labs/single.yaml index 47435813f..e2cbf31d5 100644 --- a/tests/integration/labs/single.yaml +++ b/tests/integration/labs/single.yaml @@ -1,99 +1,24 @@ -lab: - description: "Cisco IOS Integration Testing Lab" - notes: "" - title: "ios test" - version: 0.2.2 - -links: - - id: l0 - n1: n0 - n2: n1 - i1: i1 - i2: i0 - label: cat8000v-0-GigabitEthernet1<->ext-conn-0-port - +annotations: [] nodes: - boot_disk_size: null - configuration: |2- - - !Command: show running-config - !Running configuration last done at: Mon Feb 12 07:11:33 2024 - !Time: Mon Feb 12 07:11:33 2024 - - version 17.11 - service timestamps debug datetime msec - service timestamps log datetime msec - no service password-encryption - ! - hostname Router1 - ! - boot-start-marker - boot-end-marker - ! - ! - no aaa new-model - ! - ! - no ip domain lookup - ip domain name test.example - ! - ! - login on-success log - ! - ! - no ip dhcp conflict logging - ! - ! - ! - crypto key generate rsa modulus 2048 - ! - ! - ! - username admin privilege 15 secret admin - ! - ! - ! - ! - ! - interface GigabitEthernet1 - ip address dhcp - no shutdown - ! - interface GigabitEthernet2 - no ip address - shutdown - ! - interface GigabitEthernet3 - no ip address - shutdown - ! - interface GigabitEthernet4 - no ip address - shutdown - ! - ! - no ip http server - no ip http secure-server - ! - ! - ! - ! - ! - control-plane - ! - ! - line con 0 - stopbits 1 - line vty 0 4 - login local - transport input ssh - ! - ! - ! - ! - ! - no logging console - end + configuration: + - name: iosxe_config.txt + content: |- + hostname Router1 + ! + username admin privilege 15 secret admin + ! + interface GigabitEthernet1 + ip address dhcp + no shutdown + ! + ip domain-name test.example + crypto key generate rsa modulus 2048 + ! + line vty 0 4 + login local + transport input ssh + ! cpu_limit: null cpus: null data_volume: null @@ -102,6 +27,7 @@ nodes: image_definition: null label: cat8000v-0 node_definition: cat8000v + parameters: {} ram: null tags: [] x: -200 @@ -126,9 +52,10 @@ nodes: label: GigabitEthernet4 slot: 3 type: physical - - boot_disk_size: null - configuration: virbr0 + configuration: + - name: default + content: NAT cpu_limit: null cpus: null data_volume: null @@ -137,6 +64,7 @@ nodes: image_definition: null label: ext-conn-0 node_definition: external_connector + parameters: {} ram: null tags: [] x: 160 @@ -146,106 +74,16 @@ nodes: label: port slot: 0 type: physical - -annotations: [] - - - - - - - - - - - - - -# annotations: [] -# nodes: -# - boot_disk_size: null -# configuration: | -# hostname Router1 -# ! -# username admin privilege 15 secret admin -# ! -# interface GigabitEthernet1 -# ip address dhcp -# no shutdown -# ! -# ip domain-name test.example -# crypto key generate rsa modulus 2048 -# ! -# line vty 0 4 -# login local -# transport input ssh -# ! -# no logging console -# cpu_limit: null -# cpus: null -# data_volume: null -# hide_links: false -# id: n0 -# image_definition: null -# label: cat8000v-0 -# node_definition: cat8000v -# parameters: {} -# ram: null -# tags: [] -# x: -200 -# y: 0 -# interfaces: -# - id: i0 -# label: Loopback0 -# type: loopback -# - id: i1 -# label: GigabitEthernet1 -# slot: 0 -# type: physical -# - id: i2 -# label: GigabitEthernet2 -# slot: 1 -# type: physical -# - id: i3 -# label: GigabitEthernet3 -# slot: 2 -# type: physical -# - id: i4 -# label: GigabitEthernet4 -# slot: 3 -# type: physical - -# - boot_disk_size: null -# configuration: virbr0 -# cpu_limit: null -# cpus: null -# data_volume: null -# hide_links: false -# id: n1 -# image_definition: null -# label: ext-conn-0 -# node_definition: external_connector -# parameters: {} -# ram: null -# tags: [] -# x: 160 -# y: 0 -# interfaces: -# - id: i0 -# label: port -# slot: 0 -# type: physical - -# links: -# - id: l0 -# n1: n0 -# n2: n1 -# i1: i1 -# i2: i0 -# label: cat8000v-0-GigabitEthernet1<->ext-conn-0-port - -# lab: -# description: "Cisco IOS Integration Testing Lab" -# notes: "" -# title: "ios test" -# version: 0.2.2 \ No newline at end of file +links: + - id: l0 + n1: n0 + n2: n1 + i1: i1 + i2: i0 + conditioning: {} + label: cat8000v-0-GigabitEthernet1<->ext-conn-0-port +lab: + description: Cisco IOS Integration Testing Lab + notes: '' + title: ios test + version: 0.2.2 \ No newline at end of file From 090d5cb477e29472073e23e665ad5772ca9365d8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 01:20:28 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/integration.yml | 2 +- pyproject.toml | 2 +- tests/.gitignore | 2 +- tests/integration/labs/single.yaml | 4 ++-- tests/integration/test_integration.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index a808cb5ea..f85bf2536 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -35,4 +35,4 @@ jobs: secrets: cml_ssh_password: ${{ secrets.CML_SSH_PASSWORD }} virl_host: ${{ secrets.VIRL_HOST }} - virl_password: ${{ secrets.VIRL_PASSWORD }} \ No newline at end of file + virl_password: ${{ secrets.VIRL_PASSWORD }} diff --git a/pyproject.toml b/pyproject.toml index 18428c38c..66aa89b87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,4 +6,4 @@ testpaths = ["tests"] filterwarnings = [ 'ignore:AnsibleCollectionFinder has already been configured', 'ignore:_AnsibleCollectionFinder.find_spec().*', -] \ No newline at end of file +] diff --git a/tests/.gitignore b/tests/.gitignore index 89aaa51d1..2132813f2 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,2 +1,2 @@ output/ -.env \ No newline at end of file +.env diff --git a/tests/integration/labs/single.yaml b/tests/integration/labs/single.yaml index e2cbf31d5..526403d02 100644 --- a/tests/integration/labs/single.yaml +++ b/tests/integration/labs/single.yaml @@ -84,6 +84,6 @@ links: label: cat8000v-0-GigabitEthernet1<->ext-conn-0-port lab: description: Cisco IOS Integration Testing Lab - notes: '' + notes: "" title: ios test - version: 0.2.2 \ No newline at end of file + version: 0.2.2 diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 097dd0e84..aed5c0548 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -40,4 +40,4 @@ def run(ansible_project, environment): def test_integration(ansible_project, environment): - run(ansible_project, environment) \ No newline at end of file + run(ansible_project, environment) From e5fc2c8172de5c0340a5a359f08663b3d451a134 Mon Sep 17 00:00:00 2001 From: Girish5tri Date: Mon, 28 Oct 2024 07:02:15 +0530 Subject: [PATCH 5/7] init file --- tests/integration/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/integration/__init__.py diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 000000000..e69de29bb From 69242549ece21a6e97e799109247e1dc40609dc9 Mon Sep 17 00:00:00 2001 From: Girish5tri Date: Mon, 28 Oct 2024 07:36:05 +0530 Subject: [PATCH 6/7] lint --- .github/workflows/integration.yml | 1 + tests/integration/labs/single.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index f85bf2536..b0c357e44 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -1,3 +1,4 @@ +--- name: Integration on: pull_request_target: diff --git a/tests/integration/labs/single.yaml b/tests/integration/labs/single.yaml index 526403d02..f50687590 100644 --- a/tests/integration/labs/single.yaml +++ b/tests/integration/labs/single.yaml @@ -1,3 +1,4 @@ +--- annotations: [] nodes: - boot_disk_size: null From c04c58d30a4efe123ed29ac66258d7a45a871e6b Mon Sep 17 00:00:00 2001 From: Girish5tri <136325447+Girish5tri@users.noreply.github.com> Date: Wed, 30 Oct 2024 06:55:48 +0530 Subject: [PATCH 7/7] Updated integration.yml using ansible content actions --- .github/workflows/integration.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index b0c357e44..0f60a1d32 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -8,9 +8,6 @@ on: - opened - reopened - synchronize - paths: - - "plugins/**" - - "tests/integration/**" workflow_dispatch: jobs: @@ -23,13 +20,11 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} integration: - uses: ansible-network/github_actions/.github/workflows/integration.yml@main + uses: ansible-content-actions/.github/workflows/integration.yml@main needs: - safe-to-test with: - lab_title: cisco_ios network_os: cisco.ios.ios - pytest_addopts: "--color=yes -n 2 --log-level WARNING -vvv --role-excludes=snmp_server" collection_pre_install: >- git+https://github.com/ansible-collections/ansible.utils.git git+https://github.com/ansible-collections/ansible.netcommon.git