Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cml work #1127

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: Integration
on:
pull_request_target:
branches: [main]
types:
- labeled
- opened
- reopened
- synchronize
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-content-actions/.github/workflows/integration.yml@main
needs:
- safe-to-test
with:
network_os: cisco.ios.ios
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 }}
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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().*',
]
3 changes: 3 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ black==23.3.0
flake8
yamllint

# For CML
virl2-client==2.6.1

# Unit test runner
pytest-ansible
pytest-xdist
Expand Down
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
output/
.env
Empty file added tests/integration/__init__.py
Empty file.
90 changes: 90 additions & 0 deletions tests/integration/labs/single.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
annotations: []
nodes:
- boot_disk_size: null
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
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:
- name: default
content: NAT
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
conditioning: {}
label: cat8000v-0-GigabitEthernet1<->ext-conn-0-port
lab:
description: Cisco IOS Integration Testing Lab
notes: ""
title: ios test
version: 0.2.2
43 changes: 43 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
@@ -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)
Loading