From 353c9dbfe45145f7f0e78dfdc1402238e35d5ac3 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Tue, 24 Jul 2018 16:35:00 -0400 Subject: [PATCH] Add basic jobs in Zuul Layout and .gitreview Based on other TripleO Ansible roles. Also add in basic plumbing required to enable the jobs and fix for various linting issues. Co-Authored-By: Alex Schultz Change-Id: Ia42b6f736605bdff46030706b19363143b04a7c0 --- .gitreview | 4 +++ ansible-requirements.txt | 6 ++++ ci-scripts/ansible-lint.sh | 21 ++++++++++++ library/docker_facts.py | 4 ++- library/service_map_facts.py | 2 +- requirements.txt | 2 ++ setup.cfg | 38 ++++++++++++++++++++++ setup.py | 19 +++++++++++ test-requirements.txt | 1 + tox.ini | 62 ++++++++++++++++++++++++++++++++++++ zuul.d/layout.yaml | 12 +++++++ 11 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 .gitreview create mode 100644 ansible-requirements.txt create mode 100755 ci-scripts/ansible-lint.sh create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 test-requirements.txt create mode 100644 tox.ini create mode 100644 zuul.d/layout.yaml diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..8e18188 --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=review.openstack.org +port=29418 +project=openstack/ansible-role-openstack-operations.git diff --git a/ansible-requirements.txt b/ansible-requirements.txt new file mode 100644 index 0000000..a1b6838 --- /dev/null +++ b/ansible-requirements.txt @@ -0,0 +1,6 @@ +# These are required here because ansible can't be in global-requirements due +# to licensing conflicts. But we sill need to be able to pull them in for +# lint checks and want to document these as ansible specific things that may +# be required for this repository. +ansible +ansible-lint diff --git a/ci-scripts/ansible-lint.sh b/ci-scripts/ansible-lint.sh new file mode 100755 index 0000000..65e2245 --- /dev/null +++ b/ci-scripts/ansible-lint.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# ANSIBLE0006: Using command rather than module +# we have a few use cases where we need to use curl and rsync +# ANSIBLE0007: Using command rather than an argument to e.g file +# we have a lot of 'rm' command and we should use file module instead +# ANSIBLE0010: Package installs should not use latest. +# Sometimes we need to update some packages. +# ANSIBLE0012: Commands should not change things if nothing needs doing +# ANSIBLE0013: Use Shell only when shell functionality is required +# ANSIBLE0016: Tasks that run when changed should likely be handlers +# this requires refactoring roles, skipping for now +SKIPLIST="ANSIBLE0006,ANSIBLE0007,ANSIBLE0010,ANSIBLE0012,ANSIBLE0013,ANSIBLE0016" + +# Lin the role. +ansible-lint -vvv -x $SKIPLIST ./ || lint_error=1 + +# exit with 1 if we had a least an error or warning. +if [[ -n "$lint_error" ]]; then + exit 1; +fi diff --git a/library/docker_facts.py b/library/docker_facts.py index e8c1702..aa4b2fc 100644 --- a/library/docker_facts.py +++ b/library/docker_facts.py @@ -4,7 +4,9 @@ # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import absolute_import, division, print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function __metaclass__ = type diff --git a/library/service_map_facts.py b/library/service_map_facts.py index 6156bf1..de2a02c 100644 --- a/library/service_map_facts.py +++ b/library/service_map_facts.py @@ -2,8 +2,8 @@ import docker -from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_native +from ansible.module_utils.basic import AnsibleModule ANSIBLE_METADATA = { diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..885c2cb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pbr>=1.6 +ansible diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..4c73c8c --- /dev/null +++ b/setup.cfg @@ -0,0 +1,38 @@ +[metadata] +name = ansible-role-openstack-operations +summary = ansible-openstack-operations - Ansible role to perform some OpenStack Day 2 Operations +description-file = + README.md +author = TripleO Team +author-email = openstack-dev@lists.openstack.org +home-page = https://git.openstack.org/cgit/openstack/ansible-role-openstack-operations +classifier = + License :: OSI Approved :: Apache Software License + Development Status :: 4 - Beta + Intended Audience :: Developers + Intended Audience :: System Administrators + Intended Audience :: Information Technology + Topic :: Utilities + +[global] +setup-hooks = + pbr.hooks.setup_hook + +[files] +data_files = + share/ansible/roles/openstack-operations/defaults = defaults/* + share/ansible/roles/openstack-operations/handlers = handlers/* + share/ansible/roles/openstack-operations/meta = meta/* + share/ansible/roles/openstack-operations/tasks = tasks/* + share/ansible/roles/openstack-operations/templates = templates/* + share/ansible/roles/openstack-operations/tests = tests/* + share/ansible/roles/openstack-operations/vars = vars/* + share/ansible/roles/openstack-operations/files = files/* + +[wheel] +universal = 1 + +[pbr] +skip_authors = True +skip_changelog = True + 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/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..c3ed418 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..60aad53 --- /dev/null +++ b/tox.ini @@ -0,0 +1,62 @@ +[tox] +minversion = 1.6 +envlist = docs, linters +skipdist = True + +[testenv] +usedevelop = True +install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} +setenv = VIRTUAL_ENV={envdir} +deps = -r{toxinidir}/test-requirements.txt +whitelist_externals = bash + +[testenv:bindep] +# Do not install any requirements. We want this to be fast and work even if +# system dependencies are missing, since it's used to tell you what system +# dependencies are missing! This also means that bindep must be installed +# separately, outside of the requirements files. +deps = bindep +commands = bindep test + +[testenv:pep8] +commands = + # Run hacking/flake8 check for all python files + bash -c "git ls-files | grep -v releasenotes | xargs grep --binary-files=without-match \ + --files-with-match '^.!.*python$' \ + --exclude-dir .tox \ + --exclude-dir .git \ + --exclude-dir .eggs \ + --exclude-dir *.egg-info \ + --exclude-dir dist \ + --exclude-dir *lib/python* \ + --exclude-dir doc \ + | xargs flake8 --verbose" + +[testenv:ansible-lint] +basepython=python2 +commands = + bash ci-scripts/ansible-lint.sh + +[testenv:linters] +deps = + -r{toxinidir}/test-requirements.txt + -r{toxinidir}/ansible-requirements.txt +commands = + {[testenv:pep8]commands} + {[testenv:ansible-lint]commands} + +[testenv:releasenotes] +whitelist_externals = bash +commands = bash -c ci-scripts/releasenotes_tox.sh + +[testenv:venv] +commands = {posargs} + +[flake8] +# E123, E125 skipped as they are invalid PEP-8. +# E265 deals withs paces inside of comments +# FIXME(aschultz): not sure how to fix this for ansible libraries: +# H236 Python 3.x incompatible __metaclass__, use six.add_metaclass() +show-source = True +ignore = E123,E125,E265,H236 +builtins = _ diff --git a/zuul.d/layout.yaml b/zuul.d/layout.yaml new file mode 100644 index 0000000..579395d --- /dev/null +++ b/zuul.d/layout.yaml @@ -0,0 +1,12 @@ +- project: + templates: + - publish-to-pypi + check: + jobs: + - openstack-tox-linters + gate: + jobs: + - openstack-tox-linters + post: + jobs: + - publish-openstack-python-branch-tarball