test: standardise use of `share` suite & `_mapdata` state [skip ci]
authorImran Iqbal <iqbalmy@hotmail.com>
Tue, 23 Mar 2021 21:25:06 +0000 (21:25 +0000)
committerImran Iqbal <iqbalmy@hotmail.com>
Tue, 23 Mar 2021 21:25:06 +0000 (21:25 +0000)
* Automated using https://github.com/myii/ssf-formula/pull/302

12 files changed:
.rubocop.yml
Gemfile
arvados/_mapdata/_mapdata.jinja [new file with mode: 0644]
arvados/_mapdata/init.sls [new file with mode: 0644]
kitchen.yml
test/integration/api/inspec.yml
test/integration/keepstore/inspec.yml
test/integration/share/README.md [new file with mode: 0644]
test/integration/share/inspec.yml [new file with mode: 0644]
test/integration/share/libraries/system.rb [new file with mode: 0644]
test/integration/shell/inspec.yml
test/integration/workbench/inspec.yml

index 9367e99c44f3fadbabb388b0725c8b75bb7e5ece..2cceb739b24f10c62274ee72abd2734c3c15c6a9 100644 (file)
@@ -7,7 +7,7 @@ Layout/LineLength:
   # Based on https://github.com/PyCQA/flake8-bugbear#opinionated-warnings (`B950`)
   Max: 88
 Metrics/BlockLength:
-  ExcludedMethods:
+  IgnoredMethods:
     - control
     - describe
   # Increase from default of `25`
diff --git a/Gemfile b/Gemfile
index 15a77c3d5bca392dc4a10a6a7f3d22fe4f75da98..c08ad6c7356dda30046f44421714a23568c2a509 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -5,7 +5,7 @@ source 'https://rubygems.org'
 # Use the latest version of `inspec` prior to `4.23.4`, which introduces a
 # regression where the diff isn't displayed when comparing using `eq`.
 gem 'inspec',      '~> 4.22.22'
-# Install the `kitchen-docker` gem from GitHub because the latest version
+# Install the `kitchen-docker` gem using `git` because the latest version
 # currently available (`2.10.0`) doesn't include a recent fix for Gentoo.
 # rubocop:disable Layout/LineLength
 gem 'kitchen-docker', git: 'https://gitlab.com/saltstack-formulas/infrastructure/kitchen-docker', branch: 'ssf'
diff --git a/arvados/_mapdata/_mapdata.jinja b/arvados/_mapdata/_mapdata.jinja
new file mode 100644 (file)
index 0000000..aa9649c
--- /dev/null
@@ -0,0 +1,13 @@
+# yamllint disable rule:indentation rule:line-length
+# {{ grains.get("osfinger", grains.os) }}
+---
+{#- use salt.slsutil.serialize to avoid encoding errors on some platforms #}
+{{ salt["slsutil.serialize"](
+     "yaml",
+     map,
+     default_flow_style=False,
+     allow_unicode=True,
+   )
+   | regex_replace("^\s+'$", "'", multiline=True)
+   | trim
+}}
diff --git a/arvados/_mapdata/init.sls b/arvados/_mapdata/init.sls
new file mode 100644 (file)
index 0000000..d73a3f5
--- /dev/null
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# vim: ft=sls
+---
+{#- Get the `tplroot` from `tpldir` #}
+{%- set tplroot = tpldir.split("/")[0] %}
+{%- from tplroot ~ "/map.jinja" import arvados with context %}
+
+{%- set _mapdata = {
+      "values": arvados,
+    } %}
+{%- 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" %}
+
+{{ tplroot }}-mapdata-dump:
+  file.managed:
+    - name: {{ output_file }}
+    - source: salt://{{ tplroot }}/_mapdata/_mapdata.jinja
+    - template: jinja
+    - context:
+        map: {{ _mapdata | yaml }}
index 37ed50b19106e9c3e3c0ed1827a676804f1cda2d..bb4266652a36c419ea8e665c775018cd415cd442 100644 (file)
@@ -211,6 +211,7 @@ suites:
       state_top:
         base:
           '*':
+            - arvados._mapdata
             - single_host.host_entries
             - single_host.snakeoil_certs
             - locale
@@ -271,6 +272,7 @@ suites:
       state_top:
         base:
           '*':
+            - arvados._mapdata
             - single_host.host_entries
             - single_host.snakeoil_certs
             - nginx.passenger
@@ -304,6 +306,7 @@ suites:
       state_top:
         base:
           '*':
+            - arvados._mapdata
             # We also test repo here. No sense for a whole separate suite
             - arvados.repo
             - arvados.shell
@@ -325,6 +328,7 @@ suites:
       state_top:
         base:
           '*':
+            - arvados._mapdata
             - arvados.repo
             - arvados.keepstore
             # - arvados.clean
index 5745cdaed9f3020f0ade31ec5addac5ba6aa1915..3b3a09d148498bde81be0db0299cb8e743e5c220 100644 (file)
@@ -6,6 +6,9 @@ title: arvados formula api submodule
 maintainer: SaltStack Formulas
 license: Apache-2.0
 summary: Verify that the arvados formula api is setup and configured correctly
+depends:
+  - name: share
+    path: test/integration/share
 supports:
   - platform-name: debian
   - platform-name: ubuntu
@@ -14,6 +17,7 @@ supports:
   - platform-name: opensuse
   - platform-name: suse
   - platform-name: freebsd
+  - platform-name: openbsd
   - platform-name: amazon
   - platform-name: oracle
   - platform-name: arch
index 61a872f730b6b2eaf7d493f2c4c93f85256cef2d..a5efd401fe83dc0d124673f97472fde06ee36e91 100644 (file)
@@ -6,6 +6,9 @@ title: arvados formula keepstore submodule
 maintainer: SaltStack Formulas
 license: Apache-2.0
 summary: Verify that the arvados formula keepstore is setup and configured correctly
+depends:
+  - name: share
+    path: test/integration/share
 supports:
   - platform-name: debian
   - platform-name: ubuntu
@@ -14,6 +17,7 @@ supports:
   - platform-name: opensuse
   - platform-name: suse
   - platform-name: freebsd
+  - platform-name: openbsd
   - platform-name: amazon
   - platform-name: oracle
   - platform-name: arch
diff --git a/test/integration/share/README.md b/test/integration/share/README.md
new file mode 100644 (file)
index 0000000..5c5785b
--- /dev/null
@@ -0,0 +1,22 @@
+# InSpec Profile: `share`
+
+This shows the implementation of the `share` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md).
+
+Its goal is to share the libraries between all profiles.
+
+## Libraries
+
+### `system`
+
+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[: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, openSUSE and Windows:
+    - `Arch` is always `base-latest`
+    - `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`)
+    - `openSUSE` is resolved as `tumbleweed` if the `platform[:release]` is in date format
+    - `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)
diff --git a/test/integration/share/inspec.yml b/test/integration/share/inspec.yml
new file mode 100644 (file)
index 0000000..cf623a1
--- /dev/null
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# vim: ft=yaml
+---
+name: share
+title: InSpec shared resources
+maintainer: SaltStack Formulas
+license: Apache-2.0
+summary: shared resources
+supports:
+  - platform-name: debian
+  - platform-name: ubuntu
+  - platform-name: centos
+  - platform-name: fedora
+  - platform-name: opensuse
+  - platform-name: suse
+  - platform-name: freebsd
+  - platform-name: openbsd
+  - platform-name: amazon
+  - platform-name: oracle
+  - platform-name: arch
+  - platform-name: gentoo
+  - platform: windows
diff --git a/test/integration/share/libraries/system.rb b/test/integration/share/libraries/system.rb
new file mode 100644 (file)
index 0000000..461dea4
--- /dev/null
@@ -0,0 +1,90 @@
+# frozen_string_literal: true
+
+# system.rb -- InSpec resources for system values
+# Author: Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
+# Copyright (C) 2020 Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
+
+class SystemResource < Inspec.resource(1)
+  name 'system'
+
+  attr_reader :platform
+
+  def initialize
+    super
+    @platform = build_platform
+  end
+
+  private
+
+  def build_platform
+    {
+      family: build_platform_family,
+      name: build_platform_name,
+      release: build_platform_release,
+      finger: build_platform_finger
+    }
+  end
+
+  def build_platform_family
+    case inspec.platform[:name]
+    when 'arch', 'gentoo'
+      inspec.platform[:name]
+    else
+      inspec.platform[:family]
+    end
+  end
+
+  def build_platform_name
+    case inspec.platform[:name]
+    when 'amazon', 'oracle'
+      "#{inspec.platform[:name]}linux"
+    when /^windows_/
+      inspec.platform[:family]
+    else
+      inspec.platform[:name]
+    end
+  end
+
+  # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
+  def build_platform_release
+    case inspec.platform[:name]
+    when 'amazon'
+      # `2018` relase is named `1` in kitchen.yaml
+      inspec.platform[:release].gsub(/2018.*/, '1')
+    when 'arch'
+      'base-latest'
+    when 'gentoo'
+      "#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}"
+    when 'opensuse'
+      # rubocop:disable Style/NumericLiterals,Layout/LineLength
+      inspec.platform[:release].to_i > 20210101 ? 'tumbleweed' : inspec.platform[:release]
+      # rubocop:enable Style/NumericLiterals,Layout/LineLength
+    when 'windows_8.1_pro'
+      '8.1'
+    when 'windows_server_2019_datacenter'
+      '2019-server'
+    when 'windows_server_2016_datacenter'
+      '2016-server'
+    else
+      inspec.platform[:release]
+    end
+  end
+  # rubocop:enable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
+
+  def derive_gentoo_init_system
+    inspec.command('systemctl').exist? ? 'sysd' : 'sysv'
+  end
+
+  def build_platform_finger
+    "#{build_platform_name}-#{build_finger_release}"
+  end
+
+  def build_finger_release
+    case inspec.platform[:name]
+    when 'ubuntu'
+      build_platform_release.split('.').slice(0, 2).join('.')
+    else
+      build_platform_release.split('.')[0]
+    end
+  end
+end
index ecf5bfd9881fc158e7427ed104352c908c9ff7a8..521d02a9b43621ace5a836e03937fd9cc5a27556 100644 (file)
@@ -7,6 +7,9 @@ maintainer: SaltStack Formulas
 license: Apache-2.0
 # yamllint disable-line rule:line-length
 summary: Verify that the arvados formula shell submodule is setup and configured correctly
+depends:
+  - name: share
+    path: test/integration/share
 supports:
   - platform-name: debian
   - platform-name: ubuntu
@@ -15,6 +18,7 @@ supports:
   - platform-name: opensuse
   - platform-name: suse
   - platform-name: freebsd
+  - platform-name: openbsd
   - platform-name: amazon
   - platform-name: oracle
   - platform-name: arch
index 86575b34089f3ef99fe355b5562ab5209165f4de..335d70c7732c5d84dcc32cec7a56627eb2865a77 100644 (file)
@@ -6,6 +6,9 @@ title: arvados formula workbench submodule
 maintainer: SaltStack Formulas
 license: Apache-2.0
 summary: Verify that the arvados formula workbench is setup and configured correctly
+depends:
+  - name: share
+    path: test/integration/share
 supports:
   - platform-name: debian
   - platform-name: ubuntu
@@ -14,6 +17,7 @@ supports:
   - platform-name: opensuse
   - platform-name: suse
   - platform-name: freebsd
+  - platform-name: openbsd
   - platform-name: amazon
   - platform-name: oracle
   - platform-name: arch