From 33461bbecc44d493463e8ad1e6cbec0661530692 Mon Sep 17 00:00:00 2001
From: Sorin Sbarnea <ssbarnea@redhat.com>
Date: Sun, 3 May 2020 11:48:31 +0100
Subject: [PATCH] Enable yamllint

Adds yamllint to the linters with a minimal configuration, some
rules are disabled to allow us to fix them in follow-ups, if
we agree on them.

Fixes invalid YAML file containing characters inside block.

Fixes few minor linting issues.

Change-Id: I936fe2c997597972d884c5fc62655d28e8aaf8c5
---
 .yamllint                                     | 20 +++++++++++++++++++
 roles/ensure-go/tasks/install-go.yaml         |  1 -
 roles/fetch-sphinx-tarball/tasks/pdf.yaml     |  1 -
 roles/packer/tasks/main.yaml                  |  2 +-
 .../tasks/promote-cleanup.yaml                |  2 +-
 .../tasks/promote-retag-inner.yaml            |  2 +-
 .../test-cases/pylint_output_colored.yaml     | 14 ++++++-------
 roles/validate-host/defaults/main.yaml        |  2 +-
 .../base-roles/fetch-subunit-output.yaml      |  1 -
 test-playbooks/ensure-pip.yaml                | 10 +++++-----
 test-requirements.txt                         |  1 +
 tox.ini                                       |  1 +
 zuul.d/python-jobs.yaml                       |  1 -
 13 files changed, 38 insertions(+), 20 deletions(-)
 create mode 100644 .yamllint

diff --git a/.yamllint b/.yamllint
new file mode 100644
index 000000000..1a2efd9ea
--- /dev/null
+++ b/.yamllint
@@ -0,0 +1,20 @@
+extends: default
+ignore: |
+  .tox
+
+rules:
+  braces:
+    max-spaces-inside: 1
+    level: error
+  brackets:
+    max-spaces-inside: 1
+    level: error
+  comments-indentation: disable
+  document-start: disable
+  empty-lines:
+    max: 1
+    max-end: 2
+  indentation: disable
+  new-line-at-end-of-file: disable
+  line-length: disable
+  truthy: false
diff --git a/roles/ensure-go/tasks/install-go.yaml b/roles/ensure-go/tasks/install-go.yaml
index 5a8a906d2..393bc9039 100644
--- a/roles/ensure-go/tasks/install-go.yaml
+++ b/roles/ensure-go/tasks/install-go.yaml
@@ -9,7 +9,6 @@
     return_content: true
   register: go_archive_checksum
 
-
 - name: Download go archive
   get_url:
     url: "https://dl.google.com/go/go{{ go_version }}.{{ go_os }}-{{ go_arch }}.tar.gz"
diff --git a/roles/fetch-sphinx-tarball/tasks/pdf.yaml b/roles/fetch-sphinx-tarball/tasks/pdf.yaml
index 345b7187c..2860fe624 100644
--- a/roles/fetch-sphinx-tarball/tasks/pdf.yaml
+++ b/roles/fetch-sphinx-tarball/tasks/pdf.yaml
@@ -48,7 +48,6 @@
         loop_var: zj_pdf
       when: zj_pdf.stat.exists
 
-
     - name: Return PDF artifact to Zuul
       zuul_return:
         data:
diff --git a/roles/packer/tasks/main.yaml b/roles/packer/tasks/main.yaml
index 242369208..f0835f6e7 100644
--- a/roles/packer/tasks/main.yaml
+++ b/roles/packer/tasks/main.yaml
@@ -14,7 +14,7 @@
       {{ packer_variables | to_json }}
     dest: "{{ packer_variable_tempfile.path }}"
   when: packer_variables is defined
-  no_log: true # We don't want to log this since credentials could be passed this way
+  no_log: true  # We don't want to log this since credentials could be passed this way
 
 - block:
     - name: Run packer
diff --git a/roles/promote-docker-image/tasks/promote-cleanup.yaml b/roles/promote-docker-image/tasks/promote-cleanup.yaml
index 79b1066f1..e0affc2a6 100644
--- a/roles/promote-docker-image/tasks/promote-cleanup.yaml
+++ b/roles/promote-docker-image/tasks/promote-cleanup.yaml
@@ -15,6 +15,6 @@
   uri:
     url: "https://hub.docker.com/v2/repositories/{{ zj_image.repository }}/tags/{{ zj_docker_tag.name }}/"
     method: DELETE
-    status_code: [200,204]
+    status_code: [200, 204]
     headers:
       Authorization: "JWT {{ jwt_token.json.token }}"
diff --git a/roles/promote-docker-image/tasks/promote-retag-inner.yaml b/roles/promote-docker-image/tasks/promote-retag-inner.yaml
index 4701ee42e..61433b83b 100644
--- a/roles/promote-docker-image/tasks/promote-retag-inner.yaml
+++ b/roles/promote-docker-image/tasks/promote-retag-inner.yaml
@@ -23,6 +23,6 @@
   uri:
     url: "https://hub.docker.com/v2/repositories/{{ zj_image.repository }}/tags/change_{{ zuul.change }}_{{ image_tag }}/"
     method: DELETE
-    status_code: [200,204]
+    status_code: [200, 204]
     headers:
       Authorization: "JWT {{ jwt_token.json.token }}"
diff --git a/roles/tox/library/test-cases/pylint_output_colored.yaml b/roles/tox/library/test-cases/pylint_output_colored.yaml
index 087255cf0..4a824c1af 100644
--- a/roles/tox/library/test-cases/pylint_output_colored.yaml
+++ b/roles/tox/library/test-cases/pylint_output_colored.yaml
@@ -1,11 +1,12 @@
 ---
 workdir: .
-output: |
-  tests/__init__.py:2808:8: E1120: No value for argument 'get_storage_profile_id' in method call (no-value-for-parameter)
-  tests/__init__.py:2808:8: E1120: No value for argument 'select_ds_for_volume' in method call (no-value-for-parameter)
-  tests/__init__.py:2812:8: E1120: No value for argument 'get_adapter_type' in method call (no-value-for-parameter)
-  tests/__init__.py:2812:8: E1120: No value for argument 'get_disk_type' in method call (no-value-for-parameter)
-  tests/__init__.py:2812:8: E1120: No value for argument 'vops' in method call (no-value-for-parameter)
+output: "\
+  tests/__init__.py:2808:8: E1120: \e[1;31mNo value for argument 'get_storage_profile_id' in method call\e[0m (\e[1;31mno-value-for-parameter\e[0m)\n\
+  tests/__init__.py:2808:8: E1120: \e[1;31mNo value for argument 'select_ds_for_volume' in method call\e[0m (\e[1;31mno-value-for-parameter\e[0m)\n\
+  tests/__init__.py:2812:8: E1120: \e[1;31mNo value for argument 'get_adapter_type' in method call\e[0m (\e[1;31mno-value-for-parameter\e[0m)\n\
+  tests/__init__.py:2812:8: E1120: \e[1;31mNo value for argument 'get_disk_type' in method call\e[0m (\e[1;31mno-value-for-parameter\e[0m)\n\
+  tests/__init__.py:2812:8: E1120: \e[1;31mNo value for argument 'vops' in method call\e[0m (\e[1;31mno-value-for-parameter\e[0m)\n\
+  "
 comments:
   tests/__init__.py:
     - line: 2808
@@ -18,4 +19,3 @@ comments:
       message: "E1120: No value for argument 'get_disk_type' in method call (no-value-for-parameter)"
     - line: 2812
       message: "E1120: No value for argument 'vops' in method call (no-value-for-parameter)"
-
diff --git a/roles/validate-host/defaults/main.yaml b/roles/validate-host/defaults/main.yaml
index 5a89d2e53..adab79ae3 100644
--- a/roles/validate-host/defaults/main.yaml
+++ b/roles/validate-host/defaults/main.yaml
@@ -1,4 +1,4 @@
 zuul_site_image_manifest_files:
   - /etc/dib-builddate.txt
   - /etc/image-hostname.txt
-validate_host_hostname:  "{{ inventory_hostname }}"
+validate_host_hostname: "{{ inventory_hostname }}"
diff --git a/test-playbooks/base-roles/fetch-subunit-output.yaml b/test-playbooks/base-roles/fetch-subunit-output.yaml
index 8abdf4155..26fea931a 100644
--- a/test-playbooks/base-roles/fetch-subunit-output.yaml
+++ b/test-playbooks/base-roles/fetch-subunit-output.yaml
@@ -84,7 +84,6 @@
         fi
         exit $GLOBAL_RESULT
 
-
 # The following test(s) require(s) the previous playbook
 - name: Run the fetch-subunit-output role with multiple subunits
   hosts: all
diff --git a/test-playbooks/ensure-pip.yaml b/test-playbooks/ensure-pip.yaml
index 498dbe4ab..2a3482878 100644
--- a/test-playbooks/ensure-pip.yaml
+++ b/test-playbooks/ensure-pip.yaml
@@ -42,9 +42,9 @@
 # has already installed from source.  We might be able to test this
 # once it's gone...
 
-#- hosts: all
-#  roles:
-#    - role: ensure-pip
-#      vars:
-#        ensure_pip_from_upstream: True
+# - hosts: all
+#   roles:
+#     - role: ensure-pip
+#       vars:
+#         ensure_pip_from_upstream: True
 
diff --git a/test-requirements.txt b/test-requirements.txt
index 3296de718..43b846eb1 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -2,6 +2,7 @@
 # of appearance. Changing the order has an impact on the overall integration
 # process, which may cause wedges in the gate later.
 flake8
+yamllint>=1.23.0
 
 # We need to pin the ansible version directly here; per the
 # deprecation policy it should trail the version used by Zuul by 4
diff --git a/tox.ini b/tox.ini
index ef78d7e69..1bbbd9dc1 100644
--- a/tox.ini
+++ b/tox.ini
@@ -39,6 +39,7 @@ setenv =
 whitelist_externals = bash
 commands =
   flake8 {posargs}
+  yamllint -s -f parsable .
   bash -c "find playbooks -type f -regex '.*.ya?ml' ! -regex '.*vars\/.*' -print0 | \
     xargs -t -0 ansible-lint"
   bash -c 'find roles -maxdepth 1 -mindepth 1 -type d | \
diff --git a/zuul.d/python-jobs.yaml b/zuul.d/python-jobs.yaml
index 0aff8395a..c868fe524 100644
--- a/zuul.d/python-jobs.yaml
+++ b/zuul.d/python-jobs.yaml
@@ -230,7 +230,6 @@
 
          The version of Node to use.
 
-
       .. zuul:jobvar:: javascript_content_dir
          :default: dist