Browse Source

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 <don.penney@windriver.com>
Don Penney 4 months ago
parent
commit
a91160daa2
5 changed files with 233 additions and 0 deletions
  1. 28
    0
      .zuul.yaml
  2. 110
    0
      playbooks/tox-puppet-lint/pre.yaml
  3. 49
    0
      puppet-manifests/tox.ini
  4. 42
    0
      puppet-modules-wrs/tox.ini
  5. 4
    0
      tox.ini

+ 28
- 0
.zuul.yaml View File

@@ -19,6 +19,8 @@
19 19
         - cgtsclient-tox-py27
20 20
         - cgtsclient-tox-pep8
21 21
         - cgtsclient-tox-pylint
22
+        - puppet-manifests-lint
23
+        - puppet-modules-wrs-lint
22 24
     gate:
23 25
       jobs:
24 26
         - build-openstack-api-ref
@@ -34,6 +36,8 @@
34 36
         - cgtsclient-tox-py27
35 37
         - cgtsclient-tox-pep8
36 38
         - cgtsclient-tox-pylint
39
+        - puppet-manifests-lint
40
+        - puppet-modules-wrs-lint
37 41
     post:
38 42
       jobs:
39 43
         - publish-stx-api-ref
@@ -198,3 +202,27 @@
198 202
     vars:
199 203
       tox_envlist: pylint
200 204
       tox_extra_args: -c sysinv/cgts-client/cgts-client/tox.ini
205
+
206
+- job:
207
+    name: puppet-manifests-lint
208
+    parent: tox
209
+    description: |
210
+      Run puppetlint test for puppet-manifests
211
+    files:
212
+      - puppet-manifests/*
213
+    pre-run: playbooks/tox-puppet-lint/pre.yaml
214
+    vars:
215
+      tox_envlist: puppetlint
216
+      tox_extra_args: -c puppet-manifests/tox.ini
217
+
218
+- job:
219
+    name: puppet-modules-wrs-lint
220
+    parent: tox
221
+    description: |
222
+      Run puppetlint test for puppet-modules-wrs
223
+    files:
224
+      - puppet-modules-wrs/*
225
+    pre-run: playbooks/tox-puppet-lint/pre.yaml
226
+    vars:
227
+      tox_envlist: puppetlint
228
+      tox_extra_args: -c puppet-modules-wrs/tox.ini

+ 110
- 0
playbooks/tox-puppet-lint/pre.yaml View File

@@ -0,0 +1,110 @@
1
+# Job cloned from:
2
+# https://github.com/openstack-infra/openstack-zuul-jobs/blob/master/playbooks/legacy/puppet-lint/run.yaml
3
+# to install gem and puppet-lint in Zuul operating enviroment,
4
+# before running puppet-lint within the tox.ini file. The only
5
+# modification to this job is to not run puppet-lint here.
6
+# Rather, it's left to the tox.ini to control what files are
7
+# checked and what options are used (ie. to skip certain checks)
8
+#
9
+- hosts: all
10
+  name: Setup gem and puppet-lint for availability within tox
11
+  roles:
12
+    - bindep
13
+
14
+  tasks:
15
+
16
+    - name: Ensure legacy workspace directory
17
+      file:
18
+        path: '{{ ansible_user_dir }}/workspace'
19
+        state: directory
20
+
21
+    - shell:
22
+        cmd: |
23
+          set -e
24
+          set -x
25
+          CLONEMAP=`mktemp`
26
+          function cleanup {
27
+              # In cases where zuul-cloner is aborted during a git
28
+              # clone operation, git will remove the git work tree in
29
+              # its cleanup. The work tree in these jobs is the
30
+              # workspace directory, which means that subsequent
31
+              # jenkins post-build actions can not run because the
32
+              # workspace has been removed.
33
+              # To reduce the likelihood of this having an impact,
34
+              # recreate the workspace directory if needed
35
+              mkdir -p $WORKSPACE
36
+              rm -f $CLONEMAP
37
+          }
38
+          trap cleanup EXIT
39
+          cat > $CLONEMAP << EOF
40
+          clonemap:
41
+            - name: $ZUUL_PROJECT
42
+              dest: .
43
+          EOF
44
+          /usr/zuul-env/bin/zuul-cloner -m $CLONEMAP --cache-dir /opt/git \
45
+              git://git.openstack.org $ZUUL_PROJECT
46
+        executable: /bin/bash
47
+        chdir: '{{ ansible_user_dir }}/workspace'
48
+      environment: '{{ zuul | zuul_legacy_vars }}'
49
+
50
+    - shell:
51
+        cmd: |
52
+          set -e
53
+          set -x
54
+          if [ -f /usr/bin/yum ]; then
55
+              sudo yum -y remove rdo-release "centos-release-openstack-*" "centos-release-ceph-*"
56
+              sudo yum -y install libxml2-devel libxslt-devel ruby-devel zlib-devel
57
+              sudo yum -y groupinstall "Development Tools"
58
+              # Uninstall python-requests from pip, since we install it in
59
+              # system-config/install_puppet.sh
60
+              sudo pip uninstall requests -y || true
61
+          elif [ -f /usr/bin/apt-get ]; then
62
+              sudo apt-get update
63
+              sudo apt-get install -y libxml2-dev libxslt-dev ruby-dev zlib1g-dev
64
+          fi
65
+        executable: /bin/bash
66
+        chdir: '{{ ansible_user_dir }}/workspace'
67
+      environment: '{{ zuul | zuul_legacy_vars }}'
68
+
69
+    - shell:
70
+        cmd: |
71
+          set -x
72
+          sudo rm -f /etc/sudoers.d/zuul
73
+          # Prove that general sudo access is actually revoked
74
+          ! sudo -n true
75
+        executable: /bin/bash
76
+        chdir: '{{ ansible_user_dir }}/workspace'
77
+      environment: '{{ zuul | zuul_legacy_vars }}'
78
+
79
+    - shell:
80
+        cmd: |
81
+          if [ -f Modulefile -o -f metadata.json ]; then
82
+            if [ -f Modulefile ]; then
83
+              MODULE=$(awk '/^name/ {print $NF}' Modulefile |tr -d \"\')
84
+            elif [ -f metadata.json ]; then
85
+              MODULE=$(python -c 'import json;print json.load(open("metadata.json"))["name"]')
86
+            fi
87
+            if [ -z "$MODULE" ]; then
88
+              echo "Module name not defined in Modulefile or metadata.json"
89
+            else
90
+              mkdir -p "$MODULE"
91
+              rsync -a --exclude="$MODULE" --exclude ".*" . "$MODULE"
92
+              cd "$MODULE"
93
+            fi
94
+          fi
95
+          mkdir .bundled_gems
96
+          export GEM_HOME=`pwd`/.bundled_gems
97
+          if [ -f Gemfile ]; then
98
+            gem install bundler --no-rdoc --no-ri --verbose
99
+            $GEM_HOME/bin/bundle install --without system_tests
100
+            # We'll run puppet-lint from tox
101
+            #$GEM_HOME/bin/bundle exec rake lint 2>&1
102
+          else
103
+            gem install rake -n ./.bundled_gems/
104
+            gem install puppet-lint
105
+            gem install puppetlabs_spec_helper
106
+            # We'll run puppet-lint from tox
107
+            #./.bundled_gems/rake lint 2>&1
108
+          fi
109
+        chdir: '{{ ansible_user_dir }}/workspace'
110
+      environment: '{{ zuul | zuul_legacy_vars }}'

+ 49
- 0
puppet-manifests/tox.ini View File

@@ -0,0 +1,49 @@
1
+#
2
+# Copyright (c) 2018 Wind River Systems, Inc.
3
+#
4
+# SPDX-License-Identifier: Apache-2.0
5
+#
6
+
7
+# Tox (http://tox.testrun.org/) is a tool for running tests
8
+# in multiple virtualenvs. This configuration file will run the
9
+# test suite on all supported python versions. To use it, "pip install tox"
10
+# and then run "tox" from this directory.
11
+[tox]
12
+toxworkdir = /tmp/{env:USER}_puppet-manifests
13
+envlist = puppetlint
14
+skipsdist = True
15
+
16
+[testenv]
17
+recreate = True
18
+
19
+[testenv:puppetlint]
20
+deps =
21
+whitelist_externals =
22
+    gem
23
+    bash
24
+setenv =
25
+    GEM_HOME = {envdir}
26
+    GEM_PATH = {envdir}
27
+skip_tests = \
28
+    --no-140chars \
29
+    --no-2sp_soft_tabs \
30
+    --no-arrow_alignment \
31
+    --no-arrow_on_right_operand_line-check \
32
+    --no-autoloader_layout-check \
33
+    --no-case_without_default \
34
+    --no-documentation-check \
35
+    --no-double_quoted_strings-check \
36
+    --no-ensure_first_param \
37
+    --no-hard_tabs \
38
+    --no-inherits_across_namespaces \
39
+    --no-only_variable_string \
40
+    --no-parameter_order \
41
+    --no-quoted_booleans \
42
+    --no-single_quote_string_with_variables \
43
+    --no-trailing_whitespace \
44
+    --no-variable_is_lowercase-check \
45
+    --no-variables_not_enclosed
46
+commands =
47
+    gem install --no-document puppet-lint
48
+    bash -c "find {toxinidir} -name \*.pp -print0 | xargs -0 puppet-lint {[testenv:puppetlint]skip_tests}"
49
+

+ 42
- 0
puppet-modules-wrs/tox.ini View File

@@ -0,0 +1,42 @@
1
+#
2
+# Copyright (c) 2018 Wind River Systems, Inc.
3
+#
4
+# SPDX-License-Identifier: Apache-2.0
5
+#
6
+
7
+# Tox (http://tox.testrun.org/) is a tool for running tests
8
+# in multiple virtualenvs. This configuration file will run the
9
+# test suite on all supported python versions. To use it, "pip install tox"
10
+# and then run "tox" from this directory.
11
+[tox]
12
+toxworkdir = /tmp/{env:USER}_puppet-modules-wrs
13
+envlist = puppetlint
14
+skipsdist = True
15
+
16
+[testenv]
17
+recreate = True
18
+
19
+[testenv:puppetlint]
20
+deps =
21
+whitelist_externals =
22
+    gem
23
+    bash
24
+setenv =
25
+    GEM_HOME = {envdir}
26
+    GEM_PATH = {envdir}
27
+skip_tests = \
28
+    --no-2sp_soft_tabs \
29
+    --no-arrow_alignment \
30
+    --no-arrow_on_right_operand_line-check \
31
+    --no-documentation-check \
32
+    --no-double_quoted_strings-check \
33
+    --no-hard_tabs \
34
+    --no-parameter_order \
35
+    --no-star_comments \
36
+    --no-trailing_whitespace \
37
+    --no-variable_scope \
38
+    --no-variables_not_enclosed
39
+commands =
40
+    gem install --no-document puppet-lint
41
+    bash -c "find {toxinidir} -name \*.pp -print0 | xargs -0 puppet-lint {[testenv:puppetlint]skip_tests}"
42
+

+ 4
- 0
tox.ini View File

@@ -57,6 +57,10 @@ description = Dummy environment to allow flake8 to be run in subdir tox
57 57
 basepython = python3
58 58
 description = Dummy environment to allow pylint to be run in subdir tox
59 59
 
60
+[testenv:puppetlint]
61
+basepython = python3
62
+description = Dummy environment to allow puppetlint to be run in subdir tox
63
+
60 64
 [testenv:api-ref]
61 65
 basepython = python3
62 66
 install_command = pip install -U {opts} {packages}

Loading…
Cancel
Save