diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..a1152f8 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,9 @@ +--- +parseable: true +skip_list: + # Add skips here only as last resort, like: + # https://github.com/ansible/ansible-lint/issues/557 + - 302 # [E302] mkdir used in place of argument state=directory to file module + - 303 # [E303] ... used in place of ... module + - 208 # [E208] + - 106 # [E106] diff --git a/.gitignore b/.gitignore index f9da32b..eca0caa 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,75 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +sdist/ +var/ +container_registry.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec +!infrared_plugin/plugin.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +doc/build/ + +# PyBuilder +target/ + +# virtualenv +.venv/ + +# jenkins config +jenkins/config.ini +playbooks/debug.yml + +# Files created by releasenotes build +releasenotes/build + +# Editors +.*.sw[klmnop] + +# ansible retry files +*.retry + +# ansible roles diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c2016e1 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,44 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending + - id: check-byte-order-marker + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: debug-statements + - id: flake8 + - id: check-yaml + files: .*\.(yaml|yml)$ + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.18.0 + hooks: + - id: yamllint + files: \.(yaml|yml)$ + types: [file, yaml] + entry: yamllint --strict -f parsable + - repo: https://github.com/ansible/ansible-lint.git + rev: 9da220ae3a11c10c10ee43284ad6cad6d8ba52b7 + hooks: + - id: ansible-lint + always_run: true + # do not add file filters here as ansible-lint does not give reliable + # results when called with individual files. + # https://github.com/ansible/ansible-lint/issues/611 + verbose: true + entry: env ANSIBLE_LIBRARY=./library ansible-lint --force-color -v . + - repo: https://github.com/openstack-dev/bashate.git + rev: 0.6.0 + hooks: + - id: bashate + entry: bashate --error . --verbose --ignore=E006,E040 + # Run bashate check for all bash scripts + # Ignores the following rules: + # E006: Line longer than 79 columns (as many scripts use jinja + # templating, this is very difficult) + # E040: Syntax error determined using `bash -n` (as many scripts + # use jinja templating, this will often fail and the syntax + # error will be discovered in execution anyway) diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..689b7b5 --- /dev/null +++ b/.yamllint @@ -0,0 +1,7 @@ +--- +extends: default + +rules: + line-length: + # matches hardcoded 160 value from ansible-lint + max: 160 diff --git a/.zuul.yaml b/.zuul.yaml index e7c200a..7ccbd0a 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -1,3 +1,8 @@ +--- - project: - templates: - - noop-jobs + check: + jobs: + - openstack-tox-linters + gate: + jobs: + - openstack-tox-linters diff --git a/LICENSE b/LICENSE index 261eeb9..dd5b3a5 100644 --- a/LICENSE +++ b/LICENSE @@ -172,30 +172,3 @@ defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/README.md b/README.md index 7bec7f9..e4b680c 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ deployment is working by passing refstack tests. | guideline | False | 2020.06 | String | Specific guideline | | private_key_path_src * | False | None | String | If defined, the key defined by the param is copied to the targeted machine to private_key_path location.| | refstack_client_source | False | ~/.refstack-client | String | Destination where refstack-client will be cloned. | +| refstack_client_version | False | HEAD | String | Version of refstack-client cloned from git. | | server | False | https://refstack.openstack.org/api | String | Server url where results will be uploaded. | | tempest_config_path | False | None | String | Destination of tempest configuration file to be used for running refstack tests. | | tempest_tag | False | refstack-client's default | String | Tempest will be cloned and checkouted to this specific tag. | diff --git a/defaults/main.yaml b/defaults/main.yaml index d9f8409..6ea18cd 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -1,10 +1,13 @@ +--- server: "https://refstack.openstack.org/api" refstack_client_source: "~/.refstack-client" -upload_results: True -download_artifacts: True +upload_results: true +download_artifacts: true url_cirros_image: "http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img" # Local directory where the files will be stored dest_dir: "{{ lookup('env', 'PWD') }}" # the latest guideline by default guideline: "2020.06" +# default refstack version used is the HEAD +refstack_client_version: "HEAD" diff --git a/infrared_plugin/main.yml b/infrared_plugin/main.yml index 766a9f7..d309e6b 100644 --- a/infrared_plugin/main.yml +++ b/infrared_plugin/main.yml @@ -12,4 +12,3 @@ - name: ansible-role-refstack-client include_role: name: ansible-role-refstack-client - diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1545424 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pbr>=1.6 +ansible>=2.5,<2.10 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..c60ccfc --- /dev/null +++ b/setup.cfg @@ -0,0 +1,43 @@ +[metadata] +name = ansible-role-refstack-client +summary = ansible-role-refstack-client - An Ansible role to manage refstack-client. +description-file = + README.md +author = author = OpenStack +author-email = openstack-discuss@lists.openstack.org +home-page = https://refstack.openstack.org +classifier = + Environment :: OpenStack + Intended Audience :: Developers + Intended Audience :: Information Technology + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + +[global] +setup-hooks = + pbr.hooks.setup_hook + +[files] +data_files = + usr/local/share/ansible/roles/ansible-role-refstack-client/defaults = defaults/* + usr/local/share/ansible/roles/ansible-role-refstack-client/tasks = tasks/* + +[wheel] +universal = 1 + +[pbr] +skip_authors = True +skip_changelog = True + +[flake8] +# E123, E125 skipped as they are invalid PEP-8. +# E265 deals with spaces inside of comments +show-source = True +ignore = E123,E125,E265 +builtins = _ diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6a931a6 --- /dev/null +++ b/setup.py @@ -0,0 +1,19 @@ +# Copyright Red Hat, Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import setuptools + +setuptools.setup( + setup_requires=['pbr'], + pbr=True) diff --git a/tasks/generate-accounts.yaml b/tasks/generate-accounts.yaml index 1dd3759..71c04e1 100644 --- a/tasks/generate-accounts.yaml +++ b/tasks/generate-accounts.yaml @@ -45,6 +45,7 @@ args: executable: /bin/bash chdir: "{{ refstack_client_source }}" + changed_when: accounts_path is not defined - name: Cat generated accounts.yaml file shell: | @@ -52,3 +53,4 @@ args: executable: /bin/bash chdir: "{{ refstack_client_source }}" + changed_when: false diff --git a/tasks/install-packages.yaml b/tasks/install-packages.yaml index 2bb31ab..51ddace 100644 --- a/tasks/install-packages.yaml +++ b/tasks/install-packages.yaml @@ -6,18 +6,18 @@ changed_when: false - name: Install git - become: yes + become: true package: name: git - name: Install virtualenv - become: yes + become: true package: name: python-virtualenv when: python_is_available.rc == 0 - name: Install virtualenv - become: yes + become: true package: name: python3-virtualenv when: python_is_available.rc != 0 @@ -42,7 +42,7 @@ get_url: url=https://bootstrap.pypa.io/get-pip.py dest=/tmp - name: install pip - become: yes + become: true command: "python /tmp/get-pip.py" - name: delete get-pip.py diff --git a/tasks/main.yaml b/tasks/main.yaml index 40928d0..f7b4bb1 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -6,10 +6,11 @@ git: repo: 'https://github.com/openstack/refstack-client.git' dest: "{{ refstack_client_source }}" + version: "{{ refstack_client_version }}" - name: Look for python3 command: "python3 --version" - ignore_errors: yes + ignore_errors: true register: python3_is_available changed_when: false @@ -80,6 +81,7 @@ args: chdir: "{{ refstack_client_source }}" executable: /bin/bash + changed_when: false - name: Run tests with the defined test list shell: | @@ -95,7 +97,7 @@ chdir: "{{ refstack_client_source }}" executable: /bin/bash register: refstack_result - ignore_errors: yes + ignore_errors: true when: test_list is defined - name: Run tests with the default test list @@ -112,22 +114,24 @@ chdir: "{{ refstack_client_source }}" executable: /bin/bash register: refstack_result - ignore_errors: yes + ignore_errors: true when: test_list is not defined - name: Find the test result json file shell: | - set -ex + set -o pipefail -ex ls | grep "\.json" | tail -1 register: ls_out args: chdir: "{{ refstack_client_source }}/.tempest/.stestr" executable: /bin/bash + changed_when: false - name: Copy private key copy: src: "{{ private_key_path_src }}" dest: "{{ private_key_path }}" + mode: '0600' when: - upload_results | bool - private_key_path is defined @@ -135,7 +139,7 @@ - name: Upload results with signature shell: | - set -ex + set -o pipefail -ex source .venv/bin/activate yes | refstack-client upload ".tempest/.stestr/{{ ls_out.stdout }}" \ --url {{ server }} \ @@ -148,44 +152,45 @@ - upload_results | bool - private_key_path is defined -- block: - - name: Download results file in .json - fetch: - src: "{{ refstack_client_source }}/.tempest/.stestr/{{ ls_out.stdout }}" - dest: "{{ dest_dir }}/test_results.json" - flat: yes +- when: download_artifacts | bool + block: + - name: Download results file in .json + fetch: + src: "{{ refstack_client_source }}/.tempest/.stestr/{{ ls_out.stdout }}" + dest: "{{ dest_dir }}/test_results.json" + flat: true - - name: Download results file in subunit - fetch: - src: "{{ refstack_client_source }}/.tempest/.stestr/{{ ls_out.stdout | splitext | first }}" - dest: "{{ dest_dir }}/test_results_subunit" - flat: yes + - name: Download results file in subunit + fetch: + src: "{{ refstack_client_source }}/.tempest/.stestr/{{ ls_out.stdout | splitext | first }}" + dest: "{{ dest_dir }}/test_results_subunit" + flat: true - - debug: - msg: "{{ upload_out.stdout }}" + - debug: + msg: "{{ upload_out.stdout }}" - - name: Dump output of upload command - copy: - content: "{{ upload_out.stdout }}" - dest: "{{ dest_dir }}/upload_output.txt" - delegate_to: localhost + - name: Dump output of upload command + copy: + content: "{{ upload_out.stdout }}" + dest: "{{ dest_dir }}/upload_output.txt" + mode: '0644' + delegate_to: localhost - - name: Download tempest.conf file - fetch: - src: "{{ path_to_tempest_config }}" - dest: "{{ dest_dir }}/tempest.conf" - flat: yes - args: - chdir: "{{ refstack_client_source }}" + - name: Download tempest.conf file + fetch: + src: "{{ path_to_tempest_config }}" + dest: "{{ dest_dir }}/tempest.conf" + flat: true + args: + chdir: "{{ refstack_client_source }}" - - name: Download accounts.yaml file - fetch: - src: "{{ path_to_accounts_file }}" - dest: "{{ dest_dir }}/accounts.yaml" - flat: yes - args: - chdir: "{{ refstack_client_source }}" - when: download_artifacts | bool + - name: Download accounts.yaml file + fetch: + src: "{{ path_to_accounts_file }}" + dest: "{{ dest_dir }}/accounts.yaml" + flat: true + args: + chdir: "{{ refstack_client_source }}" - name: Check if we passed refstack tests fail: diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..34e064e --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,5 @@ +mock +pre-commit>=1.20.0 # MIT +pytest +pytest-mock +pyyaml diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..d6add64 --- /dev/null +++ b/tox.ini @@ -0,0 +1,32 @@ +[tox] +minversion = 3.4.0 +envlist = docs, linters +skipsdist = True + +[testenv] +usedevelop = True +install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/openstack/requirements/raw/branch/master/upper-constraints.txt} {opts} {packages} +passenv = + ANSIBLE_* + CURL_CA_BUNDLE + DOCKER_* + HOME + REQUESTS_CA_BUNDLE + SSH_AUTH_SOCK + SSL_CERT_FILE + TERM +setenv = VIRTUAL_ENV={envdir} +deps = -r{toxinidir}/test-requirements.txt +whitelist_externals = bash + +[testenv:linters] +basepython = python3 +setenv = + ANSIBLE_LIBRARY=./library +commands = + # check only modified files: + python -m pre_commit run -a + +[testenv:venv] +basepython = python3 +commands = {posargs}