Browse Source

test(map): standardise `map.jinja` verification

* Automated using https://github.com/myii/ssf-formula/pull/281
tags/v2.0.5
Imran Iqbal 4 years ago
parent
commit
2bab68f5ff
No account linked to committer's email address
6 changed files with 54 additions and 15 deletions
  1. +3
    -0
      CODEOWNERS
  2. +3
    -2
      openssh/_mapdata/init.sls
  3. +16
    -6
      test/integration/default/controls/_mapdata_spec.rb
  4. +5
    -3
      test/integration/share/README.md
  5. +3
    -0
      test/integration/share/inspec.yml
  6. +24
    -4
      test/integration/share/libraries/system.rb

+ 3
- 0
CODEOWNERS View File

/docs/AUTHORS.rst @saltstack-formulas/ssf /docs/AUTHORS.rst @saltstack-formulas/ssf
/docs/CHANGELOG.rst @saltstack-formulas/ssf /docs/CHANGELOG.rst @saltstack-formulas/ssf
/docs/TOFS_pattern.rst @saltstack-formulas/ssf /docs/TOFS_pattern.rst @saltstack-formulas/ssf
/*/_mapdata/ @saltstack-formulas/ssf
/*/libsaltcli.jinja @saltstack-formulas/ssf /*/libsaltcli.jinja @saltstack-formulas/ssf
/*/libtofs.jinja @saltstack-formulas/ssf /*/libtofs.jinja @saltstack-formulas/ssf
/test/integration/**/_mapdata_spec.rb @saltstack-formulas/ssf
/test/integration/**/libraries/system.rb @saltstack-formulas/ssf
/test/integration/**/inspec.yml @saltstack-formulas/ssf /test/integration/**/inspec.yml @saltstack-formulas/ssf
/test/integration/**/README.md @saltstack-formulas/ssf /test/integration/**/README.md @saltstack-formulas/ssf
/.gitignore @saltstack-formulas/ssf /.gitignore @saltstack-formulas/ssf

+ 3
- 2
openssh/_mapdata/init.sls View File

{%- set tplroot = tpldir.split('/')[0] %} {%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import mapdata with context %} {%- from tplroot ~ "/map.jinja" import mapdata with context %}


{%- set output_file = '/tmp/salt_mapdata_dump.yaml' %}
{%- do salt['log.debug']('### MAP.JINJA DUMP ###\n' ~ mapdata | yaml(False)) %}


{%- do salt['log.debug']( mapdata | yaml(False) ) %}
{%- set output_dir = '/temp' if grains.os_family == 'Windows' else '/tmp' %}
{%- set output_file = output_dir ~ '/salt_mapdata_dump.yaml' %}


{{ tplroot }}-mapdata-dump: {{ tplroot }}-mapdata-dump:
file.managed: file.managed:

+ 16
- 6
test/integration/default/controls/_mapdata_spec.rb View File

# frozen_string_literal: true # frozen_string_literal: true


mapdata_file = "_mapdata/#{system.platform[:finger].split('.').first}.yaml"
mapdata_dump = inspec.profile.file(mapdata_file)
require 'yaml'


control '`map.jinja` YAML dump' do control '`map.jinja` YAML dump' do
title 'should contain the lines'
title 'should match the comparison file'


describe file('/tmp/salt_mapdata_dump.yaml') do
it { should exist }
its('content') { should eq mapdata_dump }
# Strip the `platform[:finger]` version number down to the "OS major release"
mapdata_file = "_mapdata/#{system.platform[:finger].split('.').first}.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_dir = platform[:family] == 'windows' ? '/temp' : '/tmp'
output_file = "#{output_dir}/salt_mapdata_dump.yaml"

describe 'File content' do
it 'should match profile map data exactly' do
expect(yaml(output_file).params).to eq(mapdata_dump)
end
end end
end end

+ 5
- 3
test/integration/share/README.md View File

The `system` library provides easy access to system dependent information: The `system` library provides easy access to system dependent information:


- `system.platform`: based on `inspec.platform`, modify to values that are more consistent from a SaltStack perspective - `system.platform`: based on `inspec.platform`, modify to values that are more consistent from a SaltStack perspective
- `system.platform[:family]` provide a family name for Arch
- `system.platform[:name]` modify `amazon` to `amazonlinux`
- `system.platform[:release]` tweak Arch and Amazon Linux:
- `system.platform[:family]` provide a family name for Arch and Gentoo
- `system.platform[:name]` append `linux` to both `amazon` and `oracle`; ensure Windows platforms are resolved as simply `windows`
- `system.platform[:release]` tweak Arch, Amazon Linux, Gentoo and Windows:
- `Arch` is always `base-latest` - `Arch` is always `base-latest`
- `Amazon Linux` release `2018` is resolved as `1` - `Amazon Linux` release `2018` is resolved as `1`
- `Gentoo` release is trimmed to its major version number and then the init system is appended (i.e. `sysv` or `sysd`)
- `Windows` uses the widely-used release number (e.g. `8.1` or `2019-server`) in place of the actual system release version
- `system.platform[:finger]` is the concatenation of the name and the major release number (except for Ubuntu, which gives `ubuntu-20.04` for example) - `system.platform[:finger]` is the concatenation of the name and the major release number (except for Ubuntu, which gives `ubuntu-20.04` for example)

+ 3
- 0
test/integration/share/inspec.yml View File

- platform-name: suse - platform-name: suse
- platform-name: freebsd - platform-name: freebsd
- platform-name: amazon - platform-name: amazon
- platform-name: oracle
- platform-name: arch - platform-name: arch
- platform-name: gentoo
- platform: windows

+ 24
- 4
test/integration/share/libraries/system.rb View File

attr_reader :platform attr_reader :platform


def initialize def initialize
super
@platform = build_platform @platform = build_platform
end end




def build_platform_family def build_platform_family
case inspec.platform[:name] case inspec.platform[:name]
when 'arch'
'arch'
when 'arch', 'gentoo'
inspec.platform[:name]
else else
inspec.platform[:family] inspec.platform[:family]
end end


def build_platform_name def build_platform_name
case inspec.platform[:name] case inspec.platform[:name]
when 'amazon'
'amazonlinux'
when 'amazon', 'oracle'
"#{inspec.platform[:name]}linux"
when 'windows_8.1_pro', 'windows_server_2019_datacenter'
'windows'
else else
inspec.platform[:name] inspec.platform[:name]
end end
end end


# rubocop:disable Metrics/MethodLength
def build_platform_release def build_platform_release
case inspec.platform[:name] case inspec.platform[:name]
when 'amazon' when 'amazon'
inspec.platform[:release].gsub(/2018.*/, '1') inspec.platform[:release].gsub(/2018.*/, '1')
when 'arch' when 'arch'
'base-latest' 'base-latest'
when 'gentoo'
"#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}"
when 'windows_8.1_pro'
'8.1'
when 'windows_server_2019_datacenter'
'2019-server'
else else
inspec.platform[:release] inspec.platform[:release]
end end
end end
# rubocop:enable Metrics/MethodLength

def derive_gentoo_init_system
case inspec.command('systemctl').exist?
when true
'sysd'
else
'sysv'
end
end


def build_platform_finger def build_platform_finger
"#{build_platform_name}-#{build_finger_release}" "#{build_platform_name}-#{build_finger_release}"

Loading…
Cancel
Save