From baf8392455f94e0fb67dd61fe8daaf64b946096a Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 14 Nov 2018 16:56:01 +0000 Subject: [PATCH] Harden yaml linting on modified files Allows us to slowly adopt yamllint by having to fix only the files we would be touching. Once we lower the amount of differences we can switch it to run on all files. In addition to having a more consistent code-style this solves *recurring* bugs like duplicate dictionary keys, like the one fixes in this change. Only few weeks ago we had to fix a similar bug. Change-Id: I2ef275700b420a0f700613568e43576079cd4d03 --- .pre-commit-config.yaml | 20 +++++++++++++++++++ .yamllint | 6 ++++++ config/environments/rdocloud.yml | 4 ++-- .../single_nic_vlans_ipv4.yml | 3 ++- roles/validate-tempest/defaults/main.yml | 13 ++++++++---- roles/validate-ui/.travis.yml | 4 ++-- tox.ini | 5 ++++- 7 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 .yamllint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c6c053b7e..92274bb93 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,25 @@ --- repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v1.4.0 + hooks: + - id: trailing-whitespace + - id: mixed-line-ending + - id: check-byte-order-marker + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: debug-statements + - id: check-yaml + files: .*\.(yaml|yml)$ + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.12.1 + hooks: + - id: yamllint + files: \.(yaml|yml)$ + types: [file, yaml] + # uncommend once a new yamllint release is made: + # entry: yamllint --strict + - repo: https://github.com/openstack-dev/bashate.git rev: 0.6.0 hooks: diff --git a/.yamllint b/.yamllint new file mode 100644 index 000000000..69b4b4159 --- /dev/null +++ b/.yamllint @@ -0,0 +1,6 @@ +--- +extends: default + +rules: + line-length: + max: 180 diff --git a/config/environments/rdocloud.yml b/config/environments/rdocloud.yml index bdd02e1ef..971b90635 100644 --- a/config/environments/rdocloud.yml +++ b/config/environments/rdocloud.yml @@ -1,3 +1,4 @@ +--- os_username: "{{ lookup('env','OS_USERNAME') }}" os_password: "{{ lookup('env','OS_PASSWORD') }}" os_tenant_name: "{{ lookup('env','OS_TENANT_NAME') }}" @@ -39,9 +40,8 @@ mtu_interface: undercloud_local_mtu: "{{ mtu }}" overcloud_neutron_global_physnet_mtu: "{{ mtu }}" -run_tripleo_validations: True +run_tripleo_validations: true # Browbeat settings -cloud_name: rdocloud elastic_host: browbeat.test.com grafana_host: browbeat.test.com diff --git a/roles/overcloud-deploy/files/hardware_environments/virt/network_configs/single_nic_vlans_ipv4/single_nic_vlans_ipv4.yml b/roles/overcloud-deploy/files/hardware_environments/virt/network_configs/single_nic_vlans_ipv4/single_nic_vlans_ipv4.yml index 42f019bd2..6ecebe949 100644 --- a/roles/overcloud-deploy/files/hardware_environments/virt/network_configs/single_nic_vlans_ipv4/single_nic_vlans_ipv4.yml +++ b/roles/overcloud-deploy/files/hardware_environments/virt/network_configs/single_nic_vlans_ipv4/single_nic_vlans_ipv4.yml @@ -1,3 +1,4 @@ +--- # note the EC2MetadataIp: value should match the value in # /home/stack/undercloud.conf for key local_ip # # EC2MetadataIp: "local_ip" @@ -19,4 +20,4 @@ parameter_defaults: ControlPlaneSubnetCidr: "24" ControlPlaneDefaultRoute: 192.0.2.1 EC2MetadataIp: 192.0.2.1 - DnsServers: ["192.168.23.1", "8.8.8.8",] + DnsServers: ["192.168.23.1", "8.8.8.8"] diff --git a/roles/validate-tempest/defaults/main.yml b/roles/validate-tempest/defaults/main.yml index 1d3be9675..5470aadd7 100644 --- a/roles/validate-tempest/defaults/main.yml +++ b/roles/validate-tempest/defaults/main.yml @@ -4,7 +4,6 @@ floating_ip_cidr: "{{ undercloud_network_cidr }}" public_net_pool_start: "{{ floating_ip_cidr|nthhost(100) }}" public_net_pool_end: "{{ floating_ip_cidr|nthhost(120) }}" public_net_gateway: "{{ floating_ip_cidr|nthhost(1) }}" -tempest_log_file: 'tempest_output.log' test_white_regex: "{{ test_regex|default('smoke') }}" test_black_regex: [] check_tempest_bugs: false @@ -22,7 +21,7 @@ tempest_config: true tempest_overcloud: true run_tempest: false post_tempest: true -tempest_format: packages # venv or packages or container +tempest_format: packages # venv or packages or container tempest_container_registry: >- {% if (undercloud_enable_tempest is defined) and undercloud_enable_tempest|bool -%} {{ local_docker_registry_host }}:8787/{{ docker_registry_namespace }} @@ -60,14 +59,20 @@ tempest_plugins: >- [ "python-keystone-tests", "python-neutron-tests" ] {%- endif -%} -tempest_extra_config: {}# A dict containing values which needs to be overridden in tempest.conf +tempest_extra_config: {} # A dict containing values which needs to be overridden in tempest.conf skip_file_src: "skip_file.j2" skip_file: skip_file tempest_until_failure: false tempest_exit_on_failure: true # Set tempest_version for different release # For forked-tempest, we have branched name in synced with releases. -tempest_version_dict: { 'newton': 'newton', 'ocata': '16.1.0', 'pike': '17.1.0', 'queens': '17.2.0', 'rocky': '19.0.0', 'master': 'master'} +tempest_version_dict: + newton: 'newton' + ocata: '16.1.0' + pike: '17.1.0' + queens: '17.2.0' + rocky: '19.0.0' + master: 'master' tempest_version: "{{ tempest_version_dict[release] }}" tempest_conf_version_dict: {'ocata': '1.1.3', 'pike': '1.1.3', 'queens': '1.1.4', 'rocky': 'master', 'master': 'master'} tempest_conf_version: "{{ tempest_conf_version_dict[release] }}" diff --git a/roles/validate-ui/.travis.yml b/roles/validate-ui/.travis.yml index 36bbf6208..121cc4993 100644 --- a/roles/validate-ui/.travis.yml +++ b/roles/validate-ui/.travis.yml @@ -9,7 +9,7 @@ sudo: false addons: apt: packages: - - python-pip + - python-pip install: # Install ansible @@ -26,4 +26,4 @@ script: - ansible-playbook tests/test.yml -i tests/inventory --syntax-check notifications: - webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/tox.ini b/tox.ini index 747da8e09..728707aaa 100644 --- a/tox.ini +++ b/tox.ini @@ -50,7 +50,10 @@ commands = bash -c ci-scripts/releasenotes_tox.sh [testenv:linters] commands = - {[testenv:bashate]commands} + # check only modified files: + python -m pre_commit run --source HEAD^ --origin HEAD + # in the future we may want to check entire repository: + # python -m pre_commit run yamllint --all-files {[testenv:pep8]commands} {[testenv:ansible-lint]commands} {[testenv:validate-jinja]commands}