Add unified linters check

Since now linters check are provided by openstack-ansible-tests repo
which we're trying to get rid of, this patch implements new job template
openstack-ansible-linters-jobs which aims to cover linters checks, that
will be runned by gate-check-commit script. It provides next checks:
- ansible-lint
- ansible syntax-check
- bashate
- flake8

Role for the check will be selected based on the zuul.project.short_name
and passed as a scenario, while provided action is linters.

We can't use this check for openstack-ansible repo itself, since we have
a lot of linters debt, so we need to fix things inside roles first.

Depends-On: https://review.opendev.org/679238
Depends-On: https://review.opendev.org/679105
Change-Id: I24880ab92f89ca02f6b09a63da9f03dd5b230083
This commit is contained in:
Dmitriy Rabotyagov 2019-08-28 19:55:56 +03:00 committed by Dmitriy Rabotyagov (noonedeadpunk)
parent c390f13eab
commit 94e8518f68
5 changed files with 85 additions and 9 deletions

View File

@ -40,7 +40,7 @@ export ANSIBLE_LOG_DIR="/openstack/log/ansible-logging"
export SCENARIO=${1:-"aio_lxc"}
# Set the action base on the second CLI parameter
# Actions available: [ 'deploy', 'upgrade' ]
# Actions available: [ 'deploy', 'upgrade', 'varstest', 'linters' ]
export ACTION=${2:-"deploy"}
# Set the installation method for the OpenStack services
@ -103,6 +103,49 @@ if [[ "${ACTION}" == "varstest" ]]; then
pushd "${OSA_CLONE_DIR}/tests"
openstack-ansible test-vars-overrides.yml
popd
elif [[ "${ACTION}" == "linters" ]]; then
pushd "${OSA_CLONE_DIR}/playbooks"
# Install linter tools
${PIP_COMMAND} install --isolated ${PIP_OPTS} -r ${OSA_CLONE_DIR}/test-requirements.txt
# Disable Ansible color output
export ANSIBLE_NOCOLOR=1
# Create ansible logging directory
mkdir -p ${ANSIBLE_LOG_DIR}
# Prepare the hosts
export ANSIBLE_LOG_PATH="${ANSIBLE_LOG_DIR}/ansible-syntax-check.log"
# defining working directories
VENV_BIN_DIR=$(dirname ${PIP_COMMAND})
ROLE_DIR="/etc/ansible/roles/${SCENARIO}"
ANSIBLE_LINT_EXCLUDES="204,metadata"
# Check if we have test playbook and running checks
if [[ -f "${ROLE_DIR}/examples/playbook.yml" ]]; then
${VENV_BIN_DIR}/ansible-lint ${ROLE_DIR}/examples/playbook.yml -x ${ANSIBLE_LINT_EXCLUDES}
${VENV_BIN_DIR}/ansible-playbook --syntax-check --list-tasks ${ROLE_DIR}/examples/playbook.yml
else
${VENV_BIN_DIR}/ansible-lint ${ROLE_DIR} -x ${ANSIBLE_LINT_EXCLUDES}
${VENV_BIN_DIR}/ansible-playbook --syntax-check --list-tasks setup-everything.yml
fi
# Run bashate
grep --recursive --binary-files=without-match \
--files-with-match '^.!.*\(ba\)\?sh$' \
--exclude-dir .tox \
--exclude-dir .git \
"${ROLE_DIR}" | xargs -r -n1 ${VENV_BIN_DIR}/bashate --error . --verbose --ignore=E003,E006,E040
# Run pep8 check
grep --recursive --binary-files=without-match \
--files-with-match '^.!.*python$' \
--exclude-dir .eggs \
--exclude-dir .git \
--exclude-dir .tox \
--exclude-dir *.egg-info \
--exclude-dir doc \
"${ROLE_DIR}" | xargs -r ${VENV_BIN_DIR}/flake8 --verbose
popd
else
pushd "${OSA_CLONE_DIR}/playbooks"
# Disable Ansible color output

View File

@ -8,3 +8,9 @@ bashate>=0.5.1 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
mock>=2.0.0 # BSD
virtualenv>=14.0.6 # MIT
# TODO(noonedeadpunk) Upgrade linters versions and drop pycodestyle
# once we stop doing linters check for the integrated repo with
# openstack-ansible-tests/test-ansible-lint.sh
flake8<2.6.0,>=2.5.4 # MIT
ansible-lint==3.4.21 # MIT
pycodestyle>=2.5.0,<2.6.0

View File

@ -98,6 +98,12 @@
parent: openstack-ansible-deploy-aio
nodeset: ubuntu-bionic
# Running linters check
- job:
name: openstack-ansible-linters-ubuntu-bionic
parent: openstack-ansible-deploy-aio
nodeset: ubuntu-bionic
# Experimental job for checking our AIO can deploy with
# a different ansible version
- job:

View File

@ -36,18 +36,29 @@
regex_replace('^openstack-ansible-deploy-([^-]+)-.*$', '\\1')).split('_')
)
%}
{% endif %}
{# If testing a role, add the role service name to the scenario list #}
{% if zuul.project.short_name is match('^openstack-ansible-os_(.*)$') %}
{% set role_service_name = zuul.project.short_name |
{# If testing a role, add the role service name to the scenario list #}
{% if zuul.project.short_name is match('^openstack-ansible-os_(.*)$') %}
{% set role_service_name = zuul.project.short_name |
regex_replace('^openstack-ansible-os_(.*)$', '\\1')
%}
{% set _ = _scenario.append(role_service_name) %}
{# Add special scenarios based on the project name #}
{% if role_service_name in scenario_map %}
{% set _ = _scenario.append(scenario_map[role_service_name]) %}
{% set _ = _scenario.append(role_service_name) %}
{# Add special scenarios based on the project name #}
{% if role_service_name in scenario_map %}
{% set _ = _scenario.append(scenario_map[role_service_name]) %}
{% endif %}
{% endif %}
{% endif %}
{# If running linters we need to provide name of the role as a scenario w/o splitting #}
{% if zuul.job is match('^openstack-ansible-linters-.*$') %}
{% for prefix in ['openstack-ansible', 'ansible-role'] %}
{% if zuul.project.short_name is match('^' ~ prefix ~ '-([^-]+)$') %}
{% set _ = _scenario.append(
zuul.project.short_name | regex_replace('^' ~ prefix ~'-([^-]+)$', '\\1')
)
%}
{% endif%}
{% endfor %}
{% endif %}
{{ _scenario | join('_') }}
when:
- scenario is not defined
@ -78,6 +89,7 @@
Scenario: {{ scenario }}
Action: {{ action }}
Install Method: {{ install_method }}
Zuul project name: {{ zuul.project.short_name }}
# Other playbooks can consume this vars file as shown in run.yml
# This file is stored in work/osa-gate-scenario.yml on the Zuul executor

View File

@ -152,3 +152,12 @@
experimental:
jobs:
- openstack-ansible-deploy-aio_distro_ceph-opensuse-150
- project-template:
name: openstack-ansible-linters-jobs
check:
jobs:
- openstack-ansible-linters-ubuntu-bionic
gate:
jobs:
- openstack-ansible-linters-ubuntu-bionic