Skip to content

Test: Adding integration tests for cv_device_v3 #1011

Test: Adding integration tests for cv_device_v3

Test: Adding integration tests for cv_device_v3 #1011

---
name: "Collection code testing"
on:
pull_request:
branches-ignore:
- releases/**
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
jobs:
file-changes:
runs-on: ubuntu-latest
outputs:
code_v1: ${{ steps.filter.outputs.code_v1 }}
code_v3: ${{ steps.filter.outputs.code_v3 }}
dhcp_module: ${{ steps.filter.outputs.dhcp_module }}
docs: ${{ steps.filter.outputs.docs }}
python: ${{ steps.filter.outputs.python }}
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
code_v1:
- 'ansible_collections/arista/cvp/plugins/module_utils/schema_v1.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/tools_inventory.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/tools_tree.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/tools.py'
- 'ansible_collections/arista/cvp/plugins/modules/cv_facts.py'
- 'ansible_collections/arista/cvp/plugins/modules/cv_configlet.py'
- 'ansible_collections/arista/cvp/plugins/modules/cv_container.py'
- 'ansible_collections/arista/cvp/plugins/modules/cv_device.py'
- 'ansible_collections/arista/cvp/plugins/modules/cv_task.py'
- '.github/workflows/*'
- 'ansible_collections/arista/cvp/molecule/*'
- 'ansible_collections/arista/cvp/molecule/**/*'
- '!ansible_collections/arista/cvp/galaxy.yml'
code_v3:
- 'ansible_collections/arista/cvp/plugins/module_utils/configlet_tools.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/container_tools.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/device_tools.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/task_tools.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/response.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/generic_tools.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/schema_v3.py'
- 'ansible_collections/arista/cvp/plugins/modules/*_v3.py'
- '.github/workflows/*'
- 'tests/**/*'
- 'tests/*'
dhcp_module:
- 'ansible_collections/arista/cvp/roles/dhcp_configuration/*'
- 'ansible_collections/arista/cvp/roles/dhcp_configuration/**/*'
- '.github/workflows/*'
docs:
- 'mkdocs.yml'
- 'ansible_collections/arista/cvp/docs/**'
- 'ansible_collections/arista/cvp/roles/**/README.md'
- '.github/workflows/*'
python:
- 'ansible_collections/arista/cvp/plugins/**/*.py'
- '.github/workflows/*'
pre_commit:
name: Run pre-commit validation hooks
runs-on: ubuntu-latest
needs: file-changes
if: needs.file-changes.outputs.dhcp_module == 'true' || needs.file-changes.outputs.code_v3 == 'true' || needs.file-changes.outputs.code_v1 == 'true'
steps:
# Removed as gh action is marked as deprecated
# - uses: pre-commit/[email protected]
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install requirements
run: |
pip install -r ansible_collections/arista/cvp/requirements-dev.txt --upgrade
pip install -r ansible_collections/arista/cvp/requirements.txt --upgrade
- name: Run pre-commit
run: |
pre-commit run --color always --from-ref origin/devel --to-ref HEAD
python_version_support:
name: Validate code compatibility
runs-on: ubuntu-latest
needs: [file-changes, pre_commit]
if: needs.file-changes.outputs.code_v3 == 'true'
strategy:
fail-fast: true
matrix:
python_version: [ 3.9 ]
steps:
- name: 'set environment variables'
run: |
echo "PY_COLORS=1" >> $GITHUB_ENV
echo "ANSIBLE_FORCE_COLOR=1" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python_version }}
- name: Test code compatibility
run: |
cd ansible_collections/arista/cvp/plugins
python3 -m compileall -q module_utils
python3 -m compileall -q modules
pytest:
name: Validate code V3 with Pytest
runs-on: ubuntu-latest
needs: [python_version_support]
if: needs.file-changes.outputs.code_v3 == 'true'
strategy:
fail-fast: true
matrix:
python_version: [ 3.9 ]
steps:
- name: 'set environment variables'
run: |
echo "PY_COLORS=1" >> $GITHUB_ENV
echo "ANSIBLE_FORCE_COLOR=1" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python_version }}
- name: Install requirements
run: |
pip install -r ansible_collections/arista/cvp/requirements-dev.txt
pip install -r ansible_collections/arista/cvp/requirements.txt
- name: 'Execute pytest validation'
run: |
cd tests/
make test
- uses: actions/upload-artifact@v2
with:
name: pytest-report
path: |
./tests/report.html
./tests/htmlcov
molecule_cv_modules:
name: Validate code V1 with Molecule
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
ansible_version: ['ansible-core==2.11.3', 'ansible-core>=2.11.3']
avd_scenario:
- cv_configlet_loose
- cv_configlet_strict
- cv_device
needs: [ file-changes, pre_commit ]
if: needs.file-changes.outputs.code_v1 == 'true'
steps:
- name: 'set environment variables'
run: |
echo "PY_COLORS=1" >> $GITHUB_ENV
echo "ANSIBLE_FORCE_COLOR=1" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Run molecule action
uses: arista-netdevops-community/[email protected]
with:
molecule_parentdir: 'ansible_collections/arista/cvp'
molecule_command: 'test'
molecule_args: '--scenario-name ${{ matrix.avd_scenario }}'
pip_file: ansible_collections/arista/cvp/requirements.txt
ansible: "${{ matrix.ansible_version }}"
check_git: true
check_git_enforced: false
- uses: actions/upload-artifact@v2
with:
name: molecule-${{ matrix.avd_scenario }}-artifacts
path: ansible_collections/arista/cvp/molecule/${{ matrix.avd_scenario }}
molecule_dhcp:
name: Validate Roles for DHCP management
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
ansible_version: ['ansible-core==2.11.3', 'ansible-core>=2.11.3']
avd_scenario:
- dhcp_management_mac
- dhcp_management_offline
- dhcp_system_mac
needs: [ file-changes, pre_commit ]
if: needs.file-changes.outputs.dhcp_module == 'true'
steps:
- name: 'set environment variables'
run: |
echo "PY_COLORS=1" >> $GITHUB_ENV
echo "ANSIBLE_FORCE_COLOR=1" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Run molecule action
uses: arista-netdevops-community/[email protected]
with:
molecule_parentdir: 'ansible_collections/arista/cvp'
molecule_command: 'test'
molecule_args: '--scenario-name ${{ matrix.avd_scenario }}'
pip_file: ansible_collections/arista/cvp/requirements.txt
ansible: "${{ matrix.ansible_version }}"
check_git: true
check_git_enforced: false
offline_link_check:
name: 'Validate mkdoc links'
runs-on: ubuntu-latest
needs: [ file-changes ]
if: needs.file-changes.outputs.docs == 'true'
steps:
- uses: actions/checkout@v2
- name: 'start docker-compose stack'
run: |
cp development/docker-compose.yml .
sed -i 's/cd\sansible-cvp\/\s\&\&//g' docker-compose.yml
docker-compose -f docker-compose.yml up -d webdoc_cvp
docker-compose -f docker-compose.yml ps
- name: 'test connectivity to mkdoc server'
run: |
sleep 30
until docker exec webdoc_cvp curl -s -I http://localhost:8000/ ; do sleep 2; done
- name: check links for 404
run: |
docker run --network container:webdoc_cvp raviqqe/muffet:2.6.1 http://127.0.0.1:8000 \
-e ".*fonts.googleapis.com.*" \
-e ".*fonts.gstatic.com.*" \
-e ".*edit.*" \
-e ".*aristanetworks.force.com.*" \
-e ".*https://s3.amazonaws.com/onelogin-sourcemaps/.*" \
-e "twitter.com" \
-f --buffer-size=8192 \
--color=always \
--skip-tls-verification \
--timeout=30
- name: 'stop docker-compose stack'
run: |
docker-compose -f docker-compose.yml down
ansible_test:
name: Run ansible-test validation
runs-on: ubuntu-latest
needs: [ molecule_dhcp, molecule_cv_modules, pytest]
if: always()
env:
PY_COLORS: 1 # allows molecule colors to be passed to GitHub Actions
ANSIBLE_FORCE_COLOR: 1 # allows ansible colors to be passed to GitHub Actions
strategy:
fail-fast: true
matrix:
python_version: [ 3.9 ]
steps:
- name: 'set environment variables'
run: |
echo "PY_COLORS=1" >> $GITHUB_ENV
echo "ANSIBLE_FORCE_COLOR=1" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python_version }}
- name: 'Install Python requirements'
run: make install-requirements
- name: 'ansible-test linting'
run: |
cd ansible_collections/arista/cvp/
rm -rf molecule/
ansible-test sanity -v --requirements --docker --python ${{ matrix.python_version }}
rm -rf tests/output/