From 194aa97dff47acd59076865489914b4148b1b76d Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Mon, 21 Sep 2020 12:17:12 +0100 Subject: [PATCH] test(share): remove unnecessary hostname mangling * https://github.com/saltstack-formulas/openssh-formula/pull/195 --- .../default/controls/_mapdata_spec.rb | 7 +---- test/integration/share/README.md | 1 - test/integration/share/libraries/system.rb | 30 ------------------- 3 files changed, 1 insertion(+), 37 deletions(-) diff --git a/test/integration/default/controls/_mapdata_spec.rb b/test/integration/default/controls/_mapdata_spec.rb index 8d064de..2e287f2 100644 --- a/test/integration/default/controls/_mapdata_spec.rb +++ b/test/integration/default/controls/_mapdata_spec.rb @@ -1,15 +1,10 @@ # frozen_string_literal: true -# Replace per minion strings -replacement = { - hostname: system.hostname -} - # Keep only first 2 digits from Ubuntu finger mapdata_file = "_mapdata/#{system.platform[:finger].split('.').first}.yaml" # Load the mapdata from profile https://docs.chef.io/inspec/profiles/#profile-files -mapdata_dump = inspec.profile.file(mapdata_file) % replacement +mapdata_dump = inspec.profile.file(mapdata_file) control '`map.jinja` YAML dump' do title 'should contain the lines' diff --git a/test/integration/share/README.md b/test/integration/share/README.md index ef2d8d8..7de80b2 100644 --- a/test/integration/share/README.md +++ b/test/integration/share/README.md @@ -10,7 +10,6 @@ Its goal is to share the libraries between all profiles. The `system` library provides easy access to system dependent information: -- `system.hostname`: return the result of `hostname -s` or `hostnamectl --static` based on the availability of either command - `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` diff --git a/test/integration/share/libraries/system.rb b/test/integration/share/libraries/system.rb index 3c6304c..ebd32b3 100644 --- a/test/integration/share/libraries/system.rb +++ b/test/integration/share/libraries/system.rb @@ -4,47 +4,17 @@ # Author: Daniel Dehennin # Copyright (C) 2020 Daniel Dehennin -HOSTNAME_CMDS = %w[hostname hostnamectl].freeze -HOSTNAME_CMDS_OPT = { - 'hostname' => '-s', - 'hostnamectl' => '--static' -}.freeze - class SystemResource < Inspec.resource(1) name 'system' attr_reader :platform - attr_reader :hostname def initialize @platform = build_platform - @hostname = found_hostname end private - def found_hostname - cmd = guess_hostname_cmd - - unless cmd.exit_status.zero? - raise Inspec::Exceptions::ResourceSkipped, - "Error running '#{cmd}': #{cmd.stderr}" - end - - cmd.stdout.chomp - end - - def guess_hostname_cmd - HOSTNAME_CMDS.each do |cmd| - if inspec.command(cmd).exist? - return inspec.command("#{cmd} #{HOSTNAME_CMDS_OPT[cmd]}") - end - end - - raise Inspec::Exceptions::ResourceSkipped, - "Error: #{@platform[:finger]}} has none of #{HOSTNAME_CMDS.join(', ')}" - end - def build_platform { family: build_platform_family,