From a91160daa282ed8f77e260aef4dca7ed4cf75899 Mon Sep 17 00:00:00 2001 From: Don Penney Date: Mon, 24 Dec 2018 10:06:37 -0600 Subject: [PATCH] Add puppet-lint support This update adds the tox and zuul configuration to run puppet-lint against the puppet manifests. The initial update ignores all existing errors, which will be cleaned up later. Change-Id: I293abc2eac6bc6216cbbf6d939c1ba3474fb9384 Story: 2004515 Task: 28665 Signed-off-by: Don Penney --- .zuul.yaml | 28 ++++++++ playbooks/tox-puppet-lint/pre.yaml | 110 +++++++++++++++++++++++++++++ puppet-manifests/tox.ini | 49 +++++++++++++ puppet-modules-wrs/tox.ini | 42 +++++++++++ tox.ini | 4 ++ 5 files changed, 233 insertions(+) create mode 100644 playbooks/tox-puppet-lint/pre.yaml create mode 100644 puppet-manifests/tox.ini create mode 100644 puppet-modules-wrs/tox.ini diff --git a/.zuul.yaml b/.zuul.yaml index e85fd53e04..689a326cbe 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -19,6 +19,8 @@ - cgtsclient-tox-py27 - cgtsclient-tox-pep8 - cgtsclient-tox-pylint + - puppet-manifests-lint + - puppet-modules-wrs-lint gate: jobs: - build-openstack-api-ref @@ -34,6 +36,8 @@ - cgtsclient-tox-py27 - cgtsclient-tox-pep8 - cgtsclient-tox-pylint + - puppet-manifests-lint + - puppet-modules-wrs-lint post: jobs: - publish-stx-api-ref @@ -198,3 +202,27 @@ vars: tox_envlist: pylint tox_extra_args: -c sysinv/cgts-client/cgts-client/tox.ini + +- job: + name: puppet-manifests-lint + parent: tox + description: | + Run puppetlint test for puppet-manifests + files: + - puppet-manifests/* + pre-run: playbooks/tox-puppet-lint/pre.yaml + vars: + tox_envlist: puppetlint + tox_extra_args: -c puppet-manifests/tox.ini + +- job: + name: puppet-modules-wrs-lint + parent: tox + description: | + Run puppetlint test for puppet-modules-wrs + files: + - puppet-modules-wrs/* + pre-run: playbooks/tox-puppet-lint/pre.yaml + vars: + tox_envlist: puppetlint + tox_extra_args: -c puppet-modules-wrs/tox.ini diff --git a/playbooks/tox-puppet-lint/pre.yaml b/playbooks/tox-puppet-lint/pre.yaml new file mode 100644 index 0000000000..7328afba9f --- /dev/null +++ b/playbooks/tox-puppet-lint/pre.yaml @@ -0,0 +1,110 @@ +# Job cloned from: +# https://github.com/openstack-infra/openstack-zuul-jobs/blob/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 + CLONEMAP=`mktemp` + function cleanup { + # In cases where zuul-cloner is aborted during a git + # clone operation, git will remove the git work tree in + # its cleanup. The work tree in these jobs is the + # workspace directory, which means that subsequent + # jenkins post-build actions can not run because the + # workspace has been removed. + # To reduce the likelihood of this having an impact, + # recreate the workspace directory if needed + mkdir -p $WORKSPACE + rm -f $CLONEMAP + } + trap cleanup EXIT + cat > $CLONEMAP << EOF + clonemap: + - name: $ZUUL_PROJECT + dest: . + EOF + /usr/zuul-env/bin/zuul-cloner -m $CLONEMAP --cache-dir /opt/git \ + git://git.openstack.org $ZUUL_PROJECT + executable: /bin/bash + chdir: '{{ ansible_user_dir }}/workspace' + environment: '{{ zuul | zuul_legacy_vars }}' + + - 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 + $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 new file mode 100644 index 0000000000..c076554425 --- /dev/null +++ b/puppet-manifests/tox.ini @@ -0,0 +1,49 @@ +# +# Copyright (c) 2018 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-manifests +envlist = puppetlint +skipsdist = True + +[testenv] +recreate = True + +[testenv:puppetlint] +deps = +whitelist_externals = + gem + bash +setenv = + GEM_HOME = {envdir} + GEM_PATH = {envdir} +skip_tests = \ + --no-140chars \ + --no-2sp_soft_tabs \ + --no-arrow_alignment \ + --no-arrow_on_right_operand_line-check \ + --no-autoloader_layout-check \ + --no-case_without_default \ + --no-documentation-check \ + --no-double_quoted_strings-check \ + --no-ensure_first_param \ + --no-hard_tabs \ + --no-inherits_across_namespaces \ + --no-only_variable_string \ + --no-parameter_order \ + --no-quoted_booleans \ + --no-single_quote_string_with_variables \ + --no-trailing_whitespace \ + --no-variable_is_lowercase-check \ + --no-variables_not_enclosed +commands = + gem install --no-document puppet-lint + bash -c "find {toxinidir} -name \*.pp -print0 | xargs -0 puppet-lint {[testenv:puppetlint]skip_tests}" + diff --git a/puppet-modules-wrs/tox.ini b/puppet-modules-wrs/tox.ini new file mode 100644 index 0000000000..5ac070ca46 --- /dev/null +++ b/puppet-modules-wrs/tox.ini @@ -0,0 +1,42 @@ +# +# Copyright (c) 2018 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-wrs +envlist = puppetlint +skipsdist = True + +[testenv] +recreate = True + +[testenv:puppetlint] +deps = +whitelist_externals = + gem + bash +setenv = + GEM_HOME = {envdir} + GEM_PATH = {envdir} +skip_tests = \ + --no-2sp_soft_tabs \ + --no-arrow_alignment \ + --no-arrow_on_right_operand_line-check \ + --no-documentation-check \ + --no-double_quoted_strings-check \ + --no-hard_tabs \ + --no-parameter_order \ + --no-star_comments \ + --no-trailing_whitespace \ + --no-variable_scope \ + --no-variables_not_enclosed +commands = + gem install --no-document puppet-lint + bash -c "find {toxinidir} -name \*.pp -print0 | xargs -0 puppet-lint {[testenv:puppetlint]skip_tests}" + diff --git a/tox.ini b/tox.ini index 6bb7a2cf50..be7f2a57c3 100644 --- a/tox.ini +++ b/tox.ini @@ -57,6 +57,10 @@ description = Dummy environment to allow flake8 to be run in subdir tox basepython = python3 description = Dummy environment to allow pylint to be run in subdir tox +[testenv:puppetlint] +basepython = python3 +description = Dummy environment to allow puppetlint to be run in subdir tox + [testenv:api-ref] basepython = python3 install_command = pip install -U {opts} {packages}