Skip to content

Commit 8ea3c82

Browse files
committed
test: standardise use of share suite & _mapdata state [skip ci]
* Automated using myii/ssf-formula#302
1 parent 0bbe686 commit 8ea3c82

File tree

10 files changed

+181
-2
lines changed

10 files changed

+181
-2
lines changed

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Layout/LineLength:
77
# Based on https://github.com/PyCQA/flake8-bugbear#opinionated-warnings (`B950`)
88
Max: 88
99
Metrics/BlockLength:
10-
ExcludedMethods:
10+
IgnoredMethods:
1111
- control
1212
- describe
1313
# Increase from default of `25`

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ source 'https://rubygems.org'
55
# Use the latest version of `inspec` prior to `4.23.4`, which introduces a
66
# regression where the diff isn't displayed when comparing using `eq`.
77
gem 'inspec', '~> 4.22.22'
8-
# Install the `kitchen-docker` gem from GitHub because the latest version
8+
# Install the `kitchen-docker` gem using `git` because the latest version
99
# currently available (`2.10.0`) doesn't include a recent fix for Gentoo.
1010
# rubocop:disable Layout/LineLength
1111
gem 'kitchen-docker', git: 'https://gitlab.com/saltstack-formulas/infrastructure/kitchen-docker', branch: 'ssf'

kitchen.yml

+2
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ suites:
312312
state_top:
313313
base:
314314
'*':
315+
- nginx._mapdata
315316
- nginx
316317
pillars:
317318
top.sls:
@@ -336,6 +337,7 @@ suites:
336337
state_top:
337338
base:
338339
'*':
340+
- nginx._mapdata
339341
- nginx.passenger
340342
pillars:
341343
top.sls:

nginx/_mapdata/_mapdata.jinja

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# {{ grains.get("osfinger", grains.os) }}
3+
---
4+
{#- use salt.slsutil.serialize to avoid encoding errors on some platforms #}
5+
{{ salt["slsutil.serialize"](
6+
"yaml",
7+
map,
8+
default_flow_style=False,
9+
allow_unicode=True,
10+
)
11+
| regex_replace("^\s+'$", "'", multiline=True)
12+
| trim
13+
}}

nginx/_mapdata/init.sls

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
---
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split("/")[0] %}
6+
{%- from tplroot ~ "/map.jinja" import nginx with context %}
7+
8+
{%- set _mapdata = {
9+
"values": nginx,
10+
} %}
11+
{%- do salt["log.debug"]("### MAP.JINJA DUMP ###\n" ~ _mapdata | yaml(False)) %}
12+
13+
{%- set output_dir = "/temp" if grains.os_family == "Windows" else "/tmp" %}
14+
{%- set output_file = output_dir ~ "/salt_mapdata_dump.yaml" %}
15+
16+
{{ tplroot }}-mapdata-dump:
17+
file.managed:
18+
- name: {{ output_file }}
19+
- source: salt://{{ tplroot }}/_mapdata/_mapdata.jinja
20+
- template: jinja
21+
- context:
22+
map: {{ _mapdata | yaml }}

test/integration/default/inspec.yml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ title: nginx formula
66
maintainer: SaltStack Formulas
77
license: Apache-2.0
88
summary: Verify that the nginx formula is setup and configured correctly
9+
depends:
10+
- name: share
11+
path: test/integration/share
912
supports:
1013
- platform-name: debian
1114
- platform-name: ubuntu
@@ -14,6 +17,7 @@ supports:
1417
- platform-name: opensuse
1518
- platform-name: suse
1619
- platform-name: freebsd
20+
- platform-name: openbsd
1721
- platform-name: amazon
1822
- platform-name: oracle
1923
- platform-name: arch

test/integration/passenger/inspec.yml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ title: nginx formula
66
maintainer: SaltStack Formulas
77
license: Apache-2.0
88
summary: Verify that the nginx formula is setup and configured correctly
9+
depends:
10+
- name: share
11+
path: test/integration/share
912
supports:
1013
- platform-name: debian
1114
- platform-name: ubuntu
@@ -14,6 +17,7 @@ supports:
1417
- platform-name: opensuse
1518
- platform-name: suse
1619
- platform-name: freebsd
20+
- platform-name: openbsd
1721
- platform-name: amazon
1822
- platform-name: oracle
1923
- platform-name: arch

test/integration/share/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# InSpec Profile: `share`
2+
3+
This shows the implementation of the `share` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md).
4+
5+
Its goal is to share the libraries between all profiles.
6+
7+
## Libraries
8+
9+
### `system`
10+
11+
The `system` library provides easy access to system dependent information:
12+
13+
- `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 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, openSUSE and Windows:
17+
- `Arch` is always `base-latest`
18+
- `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+
- `openSUSE` is resolved as `tumbleweed` if the `platform[:release]` is in date format
21+
- `Windows` uses the widely-used release number (e.g. `8.1` or `2019-server`) in place of the actual system release version
22+
- `system.platform[:finger]` is the concatenation of the name and the major release number (except for Ubuntu, which gives `ubuntu-20.04` for example)

test/integration/share/inspec.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: share
5+
title: InSpec shared resources
6+
maintainer: SaltStack Formulas
7+
license: Apache-2.0
8+
summary: shared resources
9+
supports:
10+
- platform-name: debian
11+
- platform-name: ubuntu
12+
- platform-name: centos
13+
- platform-name: fedora
14+
- platform-name: opensuse
15+
- platform-name: suse
16+
- platform-name: freebsd
17+
- platform-name: openbsd
18+
- platform-name: amazon
19+
- platform-name: oracle
20+
- platform-name: arch
21+
- platform-name: gentoo
22+
- platform: windows
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# frozen_string_literal: true
2+
3+
# system.rb -- InSpec resources for system values
4+
# Author: Daniel Dehennin <[email protected]>
5+
# Copyright (C) 2020 Daniel Dehennin <[email protected]>
6+
7+
class SystemResource < Inspec.resource(1)
8+
name 'system'
9+
10+
attr_reader :platform
11+
12+
def initialize
13+
super
14+
@platform = build_platform
15+
end
16+
17+
private
18+
19+
def build_platform
20+
{
21+
family: build_platform_family,
22+
name: build_platform_name,
23+
release: build_platform_release,
24+
finger: build_platform_finger
25+
}
26+
end
27+
28+
def build_platform_family
29+
case inspec.platform[:name]
30+
when 'arch', 'gentoo'
31+
inspec.platform[:name]
32+
else
33+
inspec.platform[:family]
34+
end
35+
end
36+
37+
def build_platform_name
38+
case inspec.platform[:name]
39+
when 'amazon', 'oracle'
40+
"#{inspec.platform[:name]}linux"
41+
when /^windows_/
42+
inspec.platform[:family]
43+
else
44+
inspec.platform[:name]
45+
end
46+
end
47+
48+
# rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
49+
def build_platform_release
50+
case inspec.platform[:name]
51+
when 'amazon'
52+
# `2018` relase is named `1` in kitchen.yaml
53+
inspec.platform[:release].gsub(/2018.*/, '1')
54+
when 'arch'
55+
'base-latest'
56+
when 'gentoo'
57+
"#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}"
58+
when 'opensuse'
59+
# rubocop:disable Style/NumericLiterals,Layout/LineLength
60+
inspec.platform[:release].to_i > 20210101 ? 'tumbleweed' : inspec.platform[:release]
61+
# rubocop:enable Style/NumericLiterals,Layout/LineLength
62+
when 'windows_8.1_pro'
63+
'8.1'
64+
when 'windows_server_2019_datacenter'
65+
'2019-server'
66+
when 'windows_server_2016_datacenter'
67+
'2016-server'
68+
else
69+
inspec.platform[:release]
70+
end
71+
end
72+
# rubocop:enable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
73+
74+
def derive_gentoo_init_system
75+
inspec.command('systemctl').exist? ? 'sysd' : 'sysv'
76+
end
77+
78+
def build_platform_finger
79+
"#{build_platform_name}-#{build_finger_release}"
80+
end
81+
82+
def build_finger_release
83+
case inspec.platform[:name]
84+
when 'ubuntu'
85+
build_platform_release.split('.').slice(0, 2).join('.')
86+
else
87+
build_platform_release.split('.')[0]
88+
end
89+
end
90+
end

0 commit comments

Comments
 (0)