diff --git a/.zuul.yaml b/.zuul.yaml index 7ccbd0a60..b704a6565 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -2,7 +2,15 @@ - project: check: jobs: - - openstack-tox-linters + - stx-puppet-linters gate: jobs: - - openstack-tox-linters + - stx-puppet-linters + +- job: + name: stx-puppet-linters + parent: openstack-tox-linters + description: | + Run linters for stx-puppet + pre-run: playbooks/tox-puppet-lint/pre.yaml + diff --git a/modules/tox.ini b/modules/tox.ini new file mode 100644 index 000000000..8ea7ccd06 --- /dev/null +++ b/modules/tox.ini @@ -0,0 +1,34 @@ +# +# Copyright (c) 2018-2019 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# Tox (http://tox.testrun.org/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. +[tox] +toxworkdir = /tmp/{env:USER}_puppet-modules +envlist = puppetlint +skipsdist = True + +[testenv] +recreate = True + +[testenv:puppetlint] +# Note: centos developer env requires ruby-devel +# Ubuntu developer env requires ruby-dev +deps = +whitelist_externals = + gem + bash +setenv = + GEM_HOME = {envdir} + GEM_PATH = {envdir} +skip_tests = \ + --no-documentation-check +commands = + gem install --no-document json puppet-lint + bash -c "find {toxinidir} -name \*.pp -print0 | xargs -0 puppet-lint --fail-on-warnings {[testenv:puppetlint]skip_tests}" + diff --git a/playbooks/tox-puppet-lint/pre.yaml b/playbooks/tox-puppet-lint/pre.yaml new file mode 100644 index 000000000..1681dc7e9 --- /dev/null +++ b/playbooks/tox-puppet-lint/pre.yaml @@ -0,0 +1,81 @@ +# Job cloned from: +# https://opendev.org/openstack/openstack-zuul-jobs/src/branch/master/playbooks/legacy/puppet-lint/run.yaml +# to install gem and puppet-lint in Zuul operating enviroment, +# before running puppet-lint within the tox.ini file. The only +# modification to this job is to not run puppet-lint here. +# Rather, it's left to the tox.ini to control what files are +# checked and what options are used (ie. to skip certain checks) +# +- hosts: all + name: Setup gem and puppet-lint for availability within tox + roles: + - bindep + + tasks: + + - name: Ensure legacy workspace directory + file: + path: '{{ ansible_user_dir }}/workspace' + state: directory + + - shell: + cmd: | + set -e + set -x + if [ -f /usr/bin/yum ]; then + sudo yum -y remove rdo-release "centos-release-openstack-*" "centos-release-ceph-*" + sudo yum -y install libxml2-devel libxslt-devel ruby-devel zlib-devel + sudo yum -y groupinstall "Development Tools" + # Uninstall python-requests from pip, since we install it in + # system-config/install_puppet.sh + sudo pip uninstall requests -y || true + elif [ -f /usr/bin/apt-get ]; then + sudo apt-get update + sudo apt-get install -y libxml2-dev libxslt-dev ruby-dev zlib1g-dev + fi + executable: /bin/bash + chdir: '{{ ansible_user_dir }}/workspace' + environment: '{{ zuul | zuul_legacy_vars }}' + + - shell: + cmd: | + set -x + sudo rm -f /etc/sudoers.d/zuul + # Prove that general sudo access is actually revoked + ! sudo -n true + executable: /bin/bash + chdir: '{{ ansible_user_dir }}/workspace' + environment: '{{ zuul | zuul_legacy_vars }}' + + - shell: + cmd: | + if [ -f Modulefile -o -f metadata.json ]; then + if [ -f Modulefile ]; then + MODULE=$(awk '/^name/ {print $NF}' Modulefile |tr -d \"\') + elif [ -f metadata.json ]; then + MODULE=$(python -c 'import json;print json.load(open("metadata.json"))["name"]') + fi + if [ -z "$MODULE" ]; then + echo "Module name not defined in Modulefile or metadata.json" + else + mkdir -p "$MODULE" + rsync -a --exclude="$MODULE" --exclude ".*" . "$MODULE" + cd "$MODULE" + fi + fi + mkdir .bundled_gems + export GEM_HOME=`pwd`/.bundled_gems + if [ -f Gemfile ]; then + gem install bundler --no-rdoc --no-ri --verbose --version '<2.0.0' + $GEM_HOME/bin/bundle install --without system_tests + # We'll run puppet-lint from tox + #$GEM_HOME/bin/bundle exec rake lint 2>&1 + else + gem install rake -n ./.bundled_gems/ + gem install puppet-lint + gem install puppetlabs_spec_helper + # We'll run puppet-lint from tox + #./.bundled_gems/rake lint 2>&1 + fi + chdir: '{{ ansible_user_dir }}/workspace' + environment: '{{ zuul | zuul_legacy_vars }}' diff --git a/puppet-manifests/tox.ini b/puppet-manifests/tox.ini index a9a8e59da..e97ffe0c9 100644 --- a/puppet-manifests/tox.ini +++ b/puppet-manifests/tox.ini @@ -1,5 +1,5 @@ # -# Copyright (c) 2018 Wind River Systems, Inc. +# Copyright (c) 2018-2019 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # diff --git a/tox.ini b/tox.ini index 5944b009e..0616439c3 100644 --- a/tox.ini +++ b/tox.ini @@ -34,5 +34,21 @@ commands = -e 'E*'" [testenv:linters] +# Note: centos developer env requires ruby-devel +# Ubuntu developer env requires ruby-dev +whitelist_externals = + gem + bash +setenv = + GEM_HOME = {envdir} + GEM_PATH = {envdir} +skip_tests = \ + --no-autoloader_layout-check \ + --no-documentation-check commands = + gem install --no-document json puppet-lint + bash -c "find {toxinidir}/puppet-manifests {toxinidir}/modules \ + -name \*.pp -print0 \ + | xargs -0 puppet-lint --fail-on-warnings {[testenv:linters]skip_tests}" {[testenv:bashate]commands} +