Skip to content

Test: Fix v1 molecule tests #1242

Test: Fix v1 molecule tests

Test: Fix v1 molecule tests #1242

---
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@v3
- 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/fact_tools.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/image_tools.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/tag_tools.py'
- 'ansible_collections/arista/cvp/plugins/module_utils/validate_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/*'
requirements:
- 'development/requirements-dev.txt'
- 'development/requirements.txt'
- 'ansible_collections/arista/cvp/requirements-dev.txt'
- 'ansible_collections/arista/cvp/requirements.txt'
- '.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/action@v2.0.2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3
uses: actions/setup-python@v4
with:
python-version: '3.10'
- 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','3.10','3.11']
steps:
- name: 'set environment variables'
run: |
echo "PY_COLORS=1" >> $GITHUB_ENV
echo "ANSIBLE_FORCE_COLOR=1" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Set up Python 3
uses: actions/setup-python@v4
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' || needs.file-changes.outputs.requirements == 'true'
strategy:
fail-fast: true
matrix:
python_version: ['3.9','3.10','3.11','3.12']
steps:
- name: 'set environment variables'
run: |
echo "PY_COLORS=1" >> $GITHUB_ENV
echo "ANSIBLE_FORCE_COLOR=1" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Set up Python 3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
- name: Install requirements
# Removing ansible-lint in requirement-dev-3.9 to allow requirements installation for Python 3.9.
run: |
pip install -r ansible_collections/arista/cvp/requirements-dev-pytest.txt
pip install -r ansible_collections/arista/cvp/requirements.txt
- name: 'Execute pytest validation'
run: |
cd tests/
make unit-tests
- 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@v3
- name: Run molecule action
uses: arista-netdevops-community/action-molecule-avd@v1.1
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']
# XXX:
ansible_version: ['ansible-core==2.15.0', 'ansible-core>=2.17.0']
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@v3
- name: Run molecule action
uses: arista-netdevops-community/action-molecule-avd@v1.1
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'
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: 'start docker-compose stack'
run: |
docker-compose -f development/docker-compose.yml up -d webdoc_cvp
docker-compose -f development/docker-compose.yml ps
- name: 'test connectivity to mkdoc server'
run: |
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' 127.0.0.1:8000)" != "200" ]]; do sleep 5; 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 development/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.10']
steps:
- name: 'set environment variables'
run: |
echo "PY_COLORS=1" >> $GITHUB_ENV
echo "ANSIBLE_FORCE_COLOR=1" >> $GITHUB_ENV
- uses: actions/checkout@v3
- name: Set up Python 3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
- name: 'Install Python requirements'
run: make install-requirements
- name: 'ansible-test linting'
run: |
cd ansible_collections/arista/cvp/
ansible-test sanity -v --requirements --docker --python ${{ matrix.python_version }}
ansible_lint:
name: Run ansible-lint test case
runs-on: ubuntu-latest
needs: [ file-changes ]
steps:
- name: 'Set environment variables'
run: |
echo "PY_COLORS=1" >> $GITHUB_ENV
- uses: actions/checkout@v4
- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: |
3.10
- name: 'Install Python & Ansible requirements'
run: |
pip install -r ansible_collections/arista/cvp/requirements.txt -r ansible_collections/arista/cvp/requirements-dev.txt --upgrade
- name: 'Run ansible-test integration test cases'
run: |
cd ansible_collections/arista/cvp/
ansible-lint --force-color --strict -v