From d2741460ff45a81df2a08b1d12e98053bf2fa22d Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Fri, 13 Dec 2019 11:27:11 +0100 Subject: [PATCH] Add ansible playbooks linters job - Execute ansible linters on ansible files - Join all linters verifications in one single job - Fixes Ansible roles and playbook to pass verification - Leave pep8 stand alone verification because of legacy OpenStack standard testing interface (required by openstack-tox-py* zuul project templates) This is intended to reduce the amount of CI jobs required to check and gate this project while adding verification for ansible playbooks and roles Change-Id: I44e03ffc8af21e798f8c7f709728a318764b328f --- ...quirements.txt => linters-requirements.txt | 1 + playbooks/tobiko-devstack-pre-run.yaml | 6 +++- roles/tobiko/tasks/pre-run/config.yaml | 2 +- roles/tobiko/tasks/pre-run/output.yaml | 2 +- roles/tobiko/tasks/pre-run/tools.yaml | 6 ++-- tox.ini | 34 +++++++++---------- zuul.d/mypy.yaml | 7 ---- zuul.d/project.yaml | 10 ++---- 8 files changed, 30 insertions(+), 38 deletions(-) rename pep8-requirements.txt => linters-requirements.txt (83%) delete mode 100644 zuul.d/mypy.yaml diff --git a/pep8-requirements.txt b/linters-requirements.txt similarity index 83% rename from pep8-requirements.txt rename to linters-requirements.txt index db2e90a2f..877d40a45 100644 --- a/pep8-requirements.txt +++ b/linters-requirements.txt @@ -1,5 +1,6 @@ # pep8 and flake8 requirements +ansible-lint < 4 # MIT flake8==2.5.5 # MIT flake8-import-order==0.12 # LGPLv3 mypy>=0.740 # MIT diff --git a/playbooks/tobiko-devstack-pre-run.yaml b/playbooks/tobiko-devstack-pre-run.yaml index e2b2fbcb9..6c7f7b00c 100644 --- a/playbooks/tobiko-devstack-pre-run.yaml +++ b/playbooks/tobiko-devstack-pre-run.yaml @@ -15,7 +15,11 @@ register: found_repos - name: Copy Zuul repos into devstack working directory - command: rsync -a {{ item.path }} /opt/stack + synchronize: + src: "{{ item.path }}" + dest: /opt/stack + use_ssh_args: true + recursive: true with_items: '{{ found_repos.files }}' become: yes diff --git a/roles/tobiko/tasks/pre-run/config.yaml b/roles/tobiko/tasks/pre-run/config.yaml index c36ec93df..74a40c7f7 100644 --- a/roles/tobiko/tasks/pre-run/config.yaml +++ b/roles/tobiko/tasks/pre-run/config.yaml @@ -11,5 +11,5 @@ option: '{{ item.option }}' value: '{{ item.value }}' owner: root - mode: '644' + mode: '0644' loop: "{{ tobiko_conf_options }}" diff --git a/roles/tobiko/tasks/pre-run/output.yaml b/roles/tobiko/tasks/pre-run/output.yaml index c1dd02924..0b8497331 100644 --- a/roles/tobiko/tasks/pre-run/output.yaml +++ b/roles/tobiko/tasks/pre-run/output.yaml @@ -9,5 +9,5 @@ path: "{{ item | realpath }}" state: directory owner: '{{ tobiko_user }}' - mode: '755' + mode: '0755' loop: "{{ tobiko_output_dirs | unique }}" diff --git a/roles/tobiko/tasks/pre-run/tools.yaml b/roles/tobiko/tasks/pre-run/tools.yaml index 6a1a084f2..f6a21d25c 100644 --- a/roles/tobiko/tasks/pre-run/tools.yaml +++ b/roles/tobiko/tasks/pre-run/tools.yaml @@ -1,16 +1,16 @@ --- - name: "Check Python command '{{ python_command }}'" - shell: "{{ python_command }} --version" + command: "{{ python_command }} --version" - name: "Check Python command version is '{{ python_version }}'" - shell: | + command: | {{ python_command }} '{{ tobiko_dir }}/tools/ci/python_version' \ --check-prefix - name: "Check Tox command: '{{ tox_command }}'" - shell: + command: chdir: "{{ tox_dir }}" cmd: "{{ tox_command }} --version" diff --git a/tox.ini b/tox.ini index 54e335dc0..f4618bd53 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] -envlist = pep8,pylint,py37,py27,docs +envlist = linters,py37,docs minversion = 2.3.2 @@ -58,23 +58,29 @@ whitelist_externals = # --- static analisys environments ------------------------------------------- -[testenv:pep8] -commands = flake8 --max-complexity 10 +[testenv:pep8] deps = {[testenv]deps} - -r{toxinidir}/pep8-requirements.txt - - -[testenv:pylint] - -envdir = {toxworkdir}/pep8 -deps = {[testenv:pep8]deps} + -r{toxinidir}/linters-requirements.txt commands = + flake8 --max-complexity 10 + + +[testenv:linters] +whitelist_externals = bash +deps = {[testenv:pep8]deps} +envdir = {toxworkdir}/pep8 +commands = + {[testenv:pep8]commands} + mypy --py2 --ignore-missing-imports tobiko/ + bash -c 'find roles -maxdepth 1 -mindepth 1 -type d | \ + xargs -t -n1 ansible-lint -xANSIBLE0012' + bash -c 'find playbooks -maxdepth 1 -mindepth 1 -type f -name '*.yaml' | \ + xargs -t -n1 ansible-lint -xANSIBLE0012' pylint -j0 --max-line-length=80 -E -e W,E \ -d unused-import,broad-except,fixme tobiko - [flake8] # H106: Don't put vim configuration in source files # H203: Use assertIs(Not)None to check for None @@ -88,12 +94,6 @@ exclude = ./.*,*lib/python*,build,dist,doc,*egg*,releasenotes,.venv import-order-style = pep8 -[testenv:mypy] -deps = {[testenv:pep8]deps} -commands = - mypy --py2 --ignore-missing-imports tobiko/ - - # --- integration test environments ------------------------------------------ [openstack] diff --git a/zuul.d/mypy.yaml b/zuul.d/mypy.yaml deleted file mode 100644 index d5e6b825b..000000000 --- a/zuul.d/mypy.yaml +++ /dev/null @@ -1,7 +0,0 @@ -- job: - name: tobiko-tox-mypy - parent: openstack-tox - description: | - Run static mypy type checker for Tobiko project. - vars: - tox_envlist: mypy diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml index 8f1e5b8cc..b9e8715e6 100644 --- a/zuul.d/project.yaml +++ b/zuul.d/project.yaml @@ -1,5 +1,6 @@ - project: templates: + - ansible-role-jobs - build-openstack-docs-pti - docs-on-readthedocs - openstack-cover-jobs @@ -7,6 +8,7 @@ - openstack-python35-jobs - openstack-python36-jobs - openstack-python37-jobs + - openstack-python-jobs - publish-to-pypi - build-release-notes-jobs-python3 vars: @@ -14,9 +16,6 @@ check: jobs: - - openstack-tox-pylint - - tobiko-tox-mypy - - tobiko-devstack-functional - tobiko-devstack-scenario - tobiko-devstack-faults-centos-7 @@ -30,8 +29,3 @@ - tobiko-devstack-ovn-faults-centos-7 - tobiko-devstack-ovn-faults-centos-7-queens - tobiko-devstack-ovn-faults-ubuntu-bionic - - gate: - jobs: - - openstack-tox-pylint - - tobiko-tox-mypy