File tree Expand file tree Collapse file tree 6 files changed +54
-15
lines changed Expand file tree Collapse file tree 6 files changed +54
-15
lines changed Original file line number Diff line number Diff line change 1919/docs /AUTHORS.rst @ saltstack-formulas/ssf
2020/docs /CHANGELOG.rst @ saltstack-formulas/ssf
2121/docs /TOFS_pattern.rst @ saltstack-formulas/ssf
22+ /* /_mapdata / @ saltstack-formulas/ssf
2223/* /libsaltcli.jinja @ saltstack-formulas/ssf
2324/* /libtofs.jinja @ saltstack-formulas/ssf
25+ /test /integration /** /_mapdata_spec.rb @ saltstack-formulas/ssf
26+ /test /integration /** /libraries /system.rb @ saltstack-formulas/ssf
2427/test /integration /** /inspec.yml @ saltstack-formulas/ssf
2528/test /integration /** /README.md @ saltstack-formulas/ssf
2629/.gitignore @ saltstack-formulas/ssf
Original file line number Diff line number Diff line change 55{%- set tplroot = tpldir.split(' /' )[0 ] %}
66{%- from tplroot ~ " /map.jinja" import mapdata with context % }
77
8- {%- set output_file = ' /tmp/salt_mapdata_dump. yaml' % }
8+ {%- do salt[ ' log.debug ' ]( ' ### MAP.JINJA DUMP ### \n ' ~ mapdata | yaml( False )) % }
99
10- {%- do salt[' log.debug' ]( mapdata | yaml(False ) ) % }
10+ {%- set output_dir = ' /temp' if grains.os_family == ' Windows' else ' /tmp' % }
11+ {%- set output_file = output_dir ~ ' /salt_mapdata_dump.yaml' % }
1112
1213{{ tplroot }}- mapdata- dump:
1314 file .managed:
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3- mapdata_file = "_mapdata/#{ system . platform [ :finger ] . split ( '.' ) . first } .yaml"
4- mapdata_dump = inspec . profile . file ( mapdata_file )
3+ require 'yaml'
54
65control '`map.jinja` YAML dump' do
7- title 'should contain the lines '
6+ title 'should match the comparison file '
87
9- describe file ( '/tmp/salt_mapdata_dump.yaml' ) do
10- it { should exist }
11- its ( 'content' ) { should eq mapdata_dump }
8+ # Strip the `platform[:finger]` version number down to the "OS major release"
9+ mapdata_file = "_mapdata/#{ system . platform [ :finger ] . split ( '.' ) . first } .yaml"
10+
11+ # Load the mapdata from profile https://docs.chef.io/inspec/profiles/#profile-files
12+ mapdata_dump = YAML . safe_load ( inspec . profile . file ( mapdata_file ) )
13+
14+ # Derive the location of the dumped mapdata
15+ output_dir = platform [ :family ] == 'windows' ? '/temp' : '/tmp'
16+ output_file = "#{ output_dir } /salt_mapdata_dump.yaml"
17+
18+ describe 'File content' do
19+ it 'should match profile map data exactly' do
20+ expect ( yaml ( output_file ) . params ) . to eq ( mapdata_dump )
21+ end
1222 end
1323end
Original file line number Diff line number Diff line change @@ -11,9 +11,11 @@ Its goal is to share the libraries between all profiles.
1111The ` system ` library provides easy access to system dependent information:
1212
1313- ` system.platform ` : based on ` inspec.platform ` , modify to values that are more consistent from a SaltStack perspective
14- - ` system.platform[:family] ` provide a family name for Arch
15- - ` system.platform[:name] ` modify ` amazon ` to ` amazonlinux `
16- - ` system.platform[:release] ` tweak Arch and Amazon Linux:
14+ - ` system.platform[:family] ` provide a family name for Arch and Gentoo
15+ - ` system.platform[:name] ` append ` linux ` to both ` amazon ` and ` oracle ` ; ensure Windows platforms are resolved as simply ` windows `
16+ - ` system.platform[:release] ` tweak Arch, Amazon Linux, Gentoo and Windows :
1717 - ` Arch ` is always ` base-latest `
1818 - ` Amazon Linux ` release ` 2018 ` is resolved as ` 1 `
19+ - ` Gentoo ` release is trimmed to its major version number and then the init system is appended (i.e. ` sysv ` or ` sysd ` )
20+ - ` Windows ` uses the widely-used release number (e.g. ` 8.1 ` or ` 2019-server ` ) in place of the actual system release version
1921 - ` system.platform[:finger] ` is the concatenation of the name and the major release number (except for Ubuntu, which gives ` ubuntu-20.04 ` for example)
Original file line number Diff line number Diff line change @@ -15,4 +15,7 @@ supports:
1515 - platform-name : suse
1616 - platform-name : freebsd
1717 - platform-name : amazon
18+ - platform-name : oracle
1819 - platform-name : arch
20+ - platform-name : gentoo
21+ - platform : windows
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class SystemResource < Inspec.resource(1)
1010 attr_reader :platform
1111
1212 def initialize
13+ super
1314 @platform = build_platform
1415 end
1516
@@ -26,33 +27,52 @@ def build_platform
2627
2728 def build_platform_family
2829 case inspec . platform [ :name ]
29- when 'arch'
30- 'arch'
30+ when 'arch' , 'gentoo'
31+ inspec . platform [ :name ]
3132 else
3233 inspec . platform [ :family ]
3334 end
3435 end
3536
3637 def build_platform_name
3738 case inspec . platform [ :name ]
38- when 'amazon'
39- 'amazonlinux'
39+ when 'amazon' , 'oracle'
40+ "#{ inspec . platform [ :name ] } linux"
41+ when 'windows_8.1_pro' , 'windows_server_2019_datacenter'
42+ 'windows'
4043 else
4144 inspec . platform [ :name ]
4245 end
4346 end
4447
48+ # rubocop:disable Metrics/MethodLength
4549 def build_platform_release
4650 case inspec . platform [ :name ]
4751 when 'amazon'
4852 # `2018` relase is named `1` in kitchen.yaml
4953 inspec . platform [ :release ] . gsub ( /2018.*/ , '1' )
5054 when 'arch'
5155 'base-latest'
56+ when 'gentoo'
57+ "#{ inspec . platform [ :release ] . split ( '.' ) [ 0 ] } -#{ derive_gentoo_init_system } "
58+ when 'windows_8.1_pro'
59+ '8.1'
60+ when 'windows_server_2019_datacenter'
61+ '2019-server'
5262 else
5363 inspec . platform [ :release ]
5464 end
5565 end
66+ # rubocop:enable Metrics/MethodLength
67+
68+ def derive_gentoo_init_system
69+ case inspec . command ( 'systemctl' ) . exist?
70+ when true
71+ 'sysd'
72+ else
73+ 'sysv'
74+ end
75+ end
5676
5777 def build_platform_finger
5878 "#{ build_platform_name } -#{ build_finger_release } "
You can’t perform that action at this time.
0 commit comments