Merge pull request #222 from myii/refactor/use-top-level-values-in-map-jinja-dumps

refactor(map): use top-level `values:` key in `map.jinja` dumps
This commit is contained in:
Imran Iqbal 2020-12-23 18:47:13 +00:00 committed by GitHub
commit 9ae4fab85a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 3795 additions and 3747 deletions

View File

@ -17,6 +17,14 @@ repos:
stages: [manual]
additional_dependencies: ['@commitlint/config-conventional@8.3.4']
always_run: true
- repo: https://github.com/adithyabsk/mirrors-rubocop
rev: v0.91.0
hooks:
- id: rubocop
name: Check Ruby files with rubocop
args: [--debug]
always_run: true
pass_filenames: false
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.3
hooks:

View File

@ -36,17 +36,14 @@ stages:
# - name: 'release'
# if: 'branch = master AND type != pull_request'
jobs:
allow_failures:
- env: Lint_rubocop
fast_finish: true
include:
## Define the test stage that runs the linters (and testing matrix, if applicable)
# Run all of the linters in a single job (except `rubocop`)
# Run all of the linters in a single job
- language: 'node_js'
node_js: 'lts/*'
env: 'Lint'
name: 'Lint: salt-lint, yamllint, shellcheck & commitlint'
name: 'Lint: salt-lint, yamllint, rubocop, shellcheck & commitlint'
before_install: 'skip'
script:
# Install and run `salt-lint`
@ -57,6 +54,9 @@ jobs:
# Need at least `v1.17.0` for the `yaml-files` setting
- pip install --user yamllint>=1.17.0
- yamllint -s .
# Install and run `rubocop`
- gem install rubocop
- rubocop -d
# Run `shellcheck` (already pre-installed in Travis)
- shellcheck --version
- git ls-files -- '*.sh' '*.bash' '*.ksh'
@ -65,17 +65,6 @@ jobs:
- npm i -D @commitlint/config-conventional
@commitlint/travis-cli
- commitlint-travis
# Run the `rubocop` linter in a separate job that is allowed to fail
# Once these lint errors are fixed, this can be merged into a single job
- language: node_js
node_js: lts/*
env: Lint_rubocop
name: 'Lint: rubocop'
before_install: skip
script:
# Install and run `rubocop`
- gem install rubocop
- rubocop -d
# Run `pre-commit` linters in a single job
- language: 'python'

View File

@ -1,9 +1,9 @@
# yamllint disable rule:indentation rule:line-length
# {{ grains.get('osfinger', grains.os) }}
# {{ grains.get("osfinger", grains.os) }}
---
{#- use salt.slsutil.serialize to avoid encoding errors on some platforms #}
{{ salt['slsutil.serialize'](
'yaml',
{{ salt["slsutil.serialize"](
"yaml",
map,
default_flow_style=False,
allow_unicode=True,

View File

@ -2,13 +2,18 @@
# vim: ft=sls
---
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import php as mapdata with context %}
{%- set tplroot = tpldir.split("/")[0] %}
{%- from tplroot ~ "/map.jinja" import php with context %}
{%- do salt['log.debug']('### MAP.JINJA DUMP ###\n' ~ mapdata | yaml(False)) %}
{%- set _mapdata = {
"values": {
"php": php,
}
} %}
{%- do salt["log.debug"]("### MAP.JINJA DUMP ###\n" ~ _mapdata | yaml(False)) %}
{%- set output_dir = '/temp' if grains.os_family == 'Windows' else '/tmp' %}
{%- set output_file = output_dir ~ '/salt_mapdata_dump.yaml' %}
{%- set output_dir = "/temp" if grains.os_family == "Windows" else "/tmp" %}
{%- set output_file = output_dir ~ "/salt_mapdata_dump.yaml" %}
{{ tplroot }}-mapdata-dump:
file.managed:
@ -16,4 +21,4 @@
- source: salt://{{ tplroot }}/_mapdata/_mapdata.jinja
- template: jinja
- context:
map: {{ mapdata | yaml }}
map: {{ _mapdata | yaml }}

View File

@ -5,19 +5,43 @@ require 'yaml'
control '`map.jinja` YAML dump' do
title 'should match the comparison file'
### Method
# The steps below for each file appear convoluted but they are both required
# and similar in nature:
# 1. The earliest method was to simply compare the files textually but this often
# led to false positives due to inconsistencies (e.g. spacing, ordering)
# 2. The next method was to load the files back into YAML structures and then
# compare but InSpec provided block diffs this way, unusable by end users
# 3. The final step was to dump the YAML structures back into a string to use
# for the comparison; this both worked and provided human-friendly diffs
### Comparison file for the specific platform
### Static, adjusted as part of code contributions, as map data is changed
# Strip the `platform[:finger]` version number down to the "OS major release"
mapdata_file = "_mapdata/#{system.platform[:finger].split('.').first}.yaml"
platform_finger = system.platform[:finger].split('.').first.to_s
# Use that to set the path to the file (relative to the InSpec suite directory)
mapdata_file_path = "_mapdata/#{platform_finger}.yaml"
# Load the mapdata from profile, into a YAML structure
# https://docs.chef.io/inspec/profiles/#profile-files
mapdata_file_yaml = YAML.safe_load(inspec.profile.file(mapdata_file_path))
# Dump the YAML back into a string for comparison
mapdata_file_dump = YAML.dump(mapdata_file_yaml)
# Load the mapdata from profile https://docs.chef.io/inspec/profiles/#profile-files
mapdata_dump = YAML.safe_load(inspec.profile.file(mapdata_file))
# Derive the location of the dumped mapdata
### Output file produced by running the `_mapdata` state
### Dynamic, generated during Kitchen's `converge` phase
# Derive the location of the dumped mapdata (differs for Windows)
output_dir = platform[:family] == 'windows' ? '/temp' : '/tmp'
output_file = "#{output_dir}/salt_mapdata_dump.yaml"
# Use that to set the path to the file (absolute path, i.e. within the container)
output_file_path = "#{output_dir}/salt_mapdata_dump.yaml"
# Load the output into a YAML structure using InSpec's `yaml` resource
# https://github.com/inspec/inspec/blob/49b7d10/lib/inspec/resources/yaml.rb#L29
output_file_yaml = yaml(output_file_path).params
# Dump the YAML back into a string for comparison
output_file_dump = YAML.dump(output_file_yaml)
describe 'File content' do
it 'should match profile map data exactly' do
expect(yaml(output_file).params).to eq(mapdata_dump)
expect(output_file_dump).to eq(mapdata_file_dump)
end
end
end

View File

@ -1,15 +1,17 @@
# yamllint disable rule:indentation rule:line-length
# Amazon Linux AMI-2018
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings: {}
fpm:
fpm:
config:
conf:
opts: {}
@ -24,7 +26,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -35,7 +37,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -196,7 +198,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
cli:
ini: /etc/php.ini
fpm:
@ -284,7 +286,7 @@ lookup:
zip: php
xcache:
ini: /etc/php.d/xcache.ini
xcache:
xcache:
ini:
defaults:
xcache:

View File

@ -1,15 +1,17 @@
# yamllint disable rule:indentation rule:line-length
# Amazon Linux-2
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings: {}
fpm:
fpm:
config:
conf:
opts: {}
@ -24,7 +26,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -35,7 +37,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -196,7 +198,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
cli:
ini: /etc/php.ini
fpm:
@ -284,7 +286,7 @@ lookup:
zip: php
xcache:
ini: /etc/php.d/xcache.ini
xcache:
xcache:
ini:
defaults:
xcache:

View File

@ -1,15 +1,17 @@
# yamllint disable rule:indentation rule:line-length
# CentOS Linux-7
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings: {}
fpm:
fpm:
config:
conf:
opts: {}
@ -24,7 +26,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -35,7 +37,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -196,7 +198,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
cli:
ini: /etc/php.ini
fpm:
@ -284,7 +286,7 @@ lookup:
zip: php
xcache:
ini: /etc/php.d/xcache.ini
xcache:
xcache:
ini:
defaults:
xcache:

View File

@ -1,15 +1,17 @@
# yamllint disable rule:indentation rule:line-length
# CentOS Linux-8
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings: {}
fpm:
fpm:
config:
conf:
opts: {}
@ -24,7 +26,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -35,7 +37,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -196,7 +198,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
cli:
ini: /etc/php.ini
fpm:
@ -284,7 +286,7 @@ lookup:
zip: php
xcache:
ini: /etc/php.d/xcache.ini
xcache:
xcache:
ini:
defaults:
xcache:

View File

@ -1,11 +1,13 @@
# yamllint disable rule:indentation rule:line-length
# Debian-10
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings:
@ -15,7 +17,7 @@ cli:
date.timezone: Europe/Paris
PHP:
default_charset: UTF-8
fpm:
fpm:
config:
conf:
opts: {}
@ -69,7 +71,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -80,7 +82,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -241,7 +243,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
apache2:
ini: /etc/php/5.6/apache2/php.ini
cli:
@ -365,26 +367,26 @@ lookup:
- php5.6-xmlrpc
xsl: php5.6-xsl
zip: php5.6-zip
modules:
- bz2
- cli
- curl
- gd
- imagick
- imap
- intl
- mbstring
- mysql
- readline
- redis
- xdebug
- xml
- zip
repo:
modules:
- bz2
- cli
- curl
- gd
- imagick
- imap
- intl
- mbstring
- mysql
- readline
- redis
- xdebug
- xml
- zip
repo:
file: /etc/apt/sources.list.d/php-sury.list
humanname: php-sury repo
key_url: https://packages.sury.org/php/apt.gpg
name: deb https://packages.sury.org/php/ buster main
version:
- '5.6'
- '7.3'
version:
- '5.6'
- '7.3'

View File

@ -1,11 +1,13 @@
# yamllint disable rule:indentation rule:line-length
# Debian-9
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings:
@ -15,7 +17,7 @@ cli:
date.timezone: Europe/Paris
PHP:
default_charset: UTF-8
fpm:
fpm:
config:
conf:
opts: {}
@ -69,7 +71,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -80,7 +82,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -241,7 +243,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
apache2:
ini: /etc/php/5.6/apache2/php.ini
cli:
@ -365,26 +367,26 @@ lookup:
- php5.6-xmlrpc
xsl: php5.6-xsl
zip: php5.6-zip
modules:
- bz2
- cli
- curl
- gd
- imagick
- imap
- intl
- mbstring
- mysql
- readline
- redis
- xdebug
- xml
- zip
repo:
modules:
- bz2
- cli
- curl
- gd
- imagick
- imap
- intl
- mbstring
- mysql
- readline
- redis
- xdebug
- xml
- zip
repo:
file: /etc/apt/sources.list.d/php-sury.list
humanname: php-sury repo
key_url: https://packages.sury.org/php/apt.gpg
name: deb https://packages.sury.org/php/ stretch main
version:
- '5.6'
- '7.3'
version:
- '5.6'
- '7.3'

View File

@ -1,15 +1,17 @@
# yamllint disable rule:indentation rule:line-length
# Fedora-30
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings: {}
fpm:
fpm:
config:
conf:
opts: {}
@ -24,7 +26,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -35,7 +37,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -196,7 +198,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
cli:
ini: /etc/php.ini
fpm:
@ -284,7 +286,7 @@ lookup:
zip: php
xcache:
ini: /etc/php.d/xcache.ini
xcache:
xcache:
ini:
defaults:
xcache:

View File

@ -1,15 +1,17 @@
# yamllint disable rule:indentation rule:line-length
# Fedora-31
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings: {}
fpm:
fpm:
config:
conf:
opts: {}
@ -24,7 +26,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -35,7 +37,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -196,7 +198,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
cli:
ini: /etc/php.ini
fpm:
@ -284,7 +286,7 @@ lookup:
zip: php
xcache:
ini: /etc/php.d/xcache.ini
xcache:
xcache:
ini:
defaults:
xcache:

View File

@ -1,15 +1,17 @@
# yamllint disable rule:indentation rule:line-length
# Leap-15
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings: {}
fpm:
fpm:
config:
conf:
opts: {}
@ -24,7 +26,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -35,7 +37,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -196,7 +198,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
cli:
ini: /etc/php.ini
fpm:
@ -238,7 +240,7 @@ lookup:
- php5-xmlwriter
- php5-xmlrpc
zip: php5-zip
xcache:
xcache:
ini:
defaults:
xcache:

View File

@ -1,11 +1,13 @@
# yamllint disable rule:indentation rule:line-length
# Ubuntu-16.04
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings:
@ -15,7 +17,7 @@ cli:
date.timezone: Europe/Paris
PHP:
default_charset: UTF-8
fpm:
fpm:
config:
conf:
opts: {}
@ -69,7 +71,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -80,7 +82,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -241,7 +243,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
apache2:
ini: /etc/php/5.6/apache2/php.ini
cli:
@ -363,27 +365,27 @@ lookup:
- php5.6-xmlrpc
xsl: php5.6-xsl
zip: php5.6-zip
modules:
- bz2
- cli
- curl
- gd
- imagick
- imap
- intl
- mbstring
- mysql
- readline
- redis
- xdebug
- xml
- zip
repo:
modules:
- bz2
- cli
- curl
- gd
- imagick
- imap
- intl
- mbstring
- mysql
- readline
- redis
- xdebug
- xml
- zip
repo:
file: /etc/apt/sources.list.d/php-sury.list
humanname: php-sury ppa
key_url: https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c
name: deb http://ppa.launchpad.net/ondrej/php/ubuntu xenial main
use_external_repo: true
version:
- '5.6'
- '7.3'
use_external_repo: true
version:
- '5.6'
- '7.3'

View File

@ -1,11 +1,13 @@
# yamllint disable rule:indentation rule:line-length
# Ubuntu-18.04
---
apache2:
values:
php:
apache2:
ini:
opts: {}
settings: {}
cli:
cli:
ini:
opts: {}
settings:
@ -15,7 +17,7 @@ cli:
date.timezone: Europe/Paris
PHP:
default_charset: UTF-8
fpm:
fpm:
config:
conf:
opts: {}
@ -69,7 +71,7 @@ fpm:
service:
enabled: true
opts: {}
hhvm:
hhvm:
config:
php:
opts: {}
@ -80,7 +82,7 @@ hhvm:
service:
enabled: true
opts: {}
ini:
ini:
defaults:
CLI Server:
cli_server.color: 'On'
@ -241,7 +243,7 @@ ini:
soap.wsdl_cache_enabled: 1
soap.wsdl_cache_limit: 5
soap.wsdl_cache_ttl: 86400
lookup:
lookup:
apache2:
ini: /etc/php/5.6/apache2/php.ini
cli:
@ -363,27 +365,27 @@ lookup:
- php5.6-xmlrpc
xsl: php5.6-xsl
zip: php5.6-zip
modules:
- bz2
- cli
- curl
- gd
- imagick
- imap
- intl
- mbstring
- mysql
- readline
- redis
- xdebug
- xml
- zip
repo:
modules:
- bz2
- cli
- curl
- gd
- imagick
- imap
- intl
- mbstring
- mysql
- readline
- redis
- xdebug
- xml
- zip
repo:
file: /etc/apt/sources.list.d/php-sury.list
humanname: php-sury ppa
key_url: https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c
name: deb http://ppa.launchpad.net/ondrej/php/ubuntu bionic main
use_external_repo: true
version:
- '5.6'
- '7.3'
use_external_repo: true
version:
- '5.6'
- '7.3'