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

Add Network Integration Action #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
164 changes: 164 additions & 0 deletions .github/workflows/network_integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: Integration tests
on:
workflow_call:
inputs:
collection_pre_install:
required: false
type: string
default: ""
lab_title:
required: false
type: string
default: ${{ github.event.repository.name }}
cml_lab:
default: tests/integration/labs/single.yaml
required: false
type: string
integration_test_path:
default: tests/integration/targets
required: false
type: string
network_os:
required: true
type: string
pytest_addopts:
default: ""
required: false
type: string

secrets:
cml_ssh_password:
required: true
virl_password:
required: true
virl_host:
required: true

jobs:
integration:
env:
PY_COLORS: "1"
source_directory: "./source"
dependency_directory: "./dependency"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ansible-version:
- stable-2.16
# - stable-2.15
# - milestone
# - devel
python-version:
- "3.11"
dependency-source:
- github

name: "py${{ matrix.python-version }} / ${{ matrix.ansible-version }} / ${{ matrix.dependency-source }}"
steps:
- name: Checkout the collection repository
uses: ansible-network/github_actions/.github/actions/checkout_dependency@main
with:
path: ${{ env.source_directory }}
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: "0"

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install wheel now for faster builds
run: python3 -m pip install wheel --upgrade

- name: Install ansible-core (${{ matrix.ansible-version }})
run: python3 -m pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check

- name: Pre install collections dependencies first so the collection install does not
run: ansible-galaxy collection install --pre ${{ inputs.collection_pre_install }} -p /home/runner/collections
if: inputs.collection_pre_install != ''

- name: Read collection metadata from galaxy.yml
id: identify
uses: ansible-network/github_actions/.github/actions/identify_collection@main
with:
source_path: ${{ env.source_directory }}

- name: Build and install the collection
uses: ansible-network/github_actions/.github/actions/build_install_collection@main
with:
install_python_dependencies: true
source_path: ${{ env.source_directory }}
collection_path: ${{ steps.identify.outputs.collection_path }}
tar_file: ${{ steps.identify.outputs.tar_file }}
ansible_version: ${{ matrix.ansible-version }}

- name: Print the ansible version
run: ansible --version

- name: Install the integration test dependency
run: python3 -m pip install git+https://github.com/ansible-network/pytest-ansible-network-integration.git

- name: Install the rest of the dependencies
run: python3 -m pip install cmlutils pytest-xdist virl2_client==2.7.1

- name: Clear current lab id if any
run: "cml clear"
continue-on-error: true
env:
CML_VERIFY_CERT: false
VIRL_HOST: ${{ secrets.virl_host }}
VIRL_PASSWORD: ${{ secrets.virl_password }}
VIRL_USERNAME: admin

- name: Create the lab title
run: |
if [[ "${{ github.event_name }}" == 'pull_request_target' ]]; then
echo "CLABTITLE=${{ inputs.lab_title }}_PR${{ github.event.pull_request.number }}" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
shashort=$(git rev-parse --short HEAD)
uuidval=$(uuidgen | cut -c 1-8)
echo "CLABTITLE=${{ inputs.lab_title }}_${shashort}_${uuidval}" >> $GITHUB_ENV
fi

- name: Print the lab title
run: echo ${{ env.CLABTITLE }}

- name: Add Lab Title to the lab file
run: >-
sed -i "s/title: ${{ inputs.network_os }}/title: ${{ env.CLABTITLE }}/" ${{ inputs.cml_lab }}
working-directory: ${{ steps.identify.outputs.collection_path }}

- name: Run integration tests
run: >-
python3 -m pytest tests/integration
--integration-tests-path ${{ inputs.integration_test_path }}
--cml-lab ${{ inputs.cml_lab }}
${{ inputs.pytest_addopts }}
env:
ANSIBLE_FORCE_COLOR: "1"
ANSIBLE_NETWORK_OS: ${{ inputs.network_os }}
CML_SSH_PASSWORD: ${{ secrets.cml_ssh_password }}
CML_SSH_PORT: 1122
CML_SSH_USER: sysadmin
VIRL_HOST: ${{ secrets.virl_host }}
VIRL_PASSWORD: ${{ secrets.virl_password }}
VIRL_USERNAME: admin
working-directory: ${{ steps.identify.outputs.collection_path }}

- name: Attempt to remove any labs in case the workflow was cancelled
if: cancelled()
run: echo ${{ env.CML_LABS }} | tr -d '\n' | xargs -d ',' -i sh -c 'cml use --id {} && cml rm --force --no-confirm'
continue-on-error: true
env:
CML_VERIFY_CERT: false
VIRL_HOST: ${{ secrets.virl_host }}
VIRL_PASSWORD: ${{ secrets.virl_password }}
VIRL_USERNAME: admin

- name: Upload logs
if: always()
uses: actions/upload-artifact@v3
with:
name: logs
path: /home/runner/test_logs/