From 460e4b16afdcd2eb0ad574f86742c90e4f8b2372 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Mon, 25 Mar 2024 08:58:27 +0100 Subject: [PATCH 1/3] Add more fact-based tests --- spec/acceptance/basic_spec.rb | 4 +++- spec/classes/init_spec.rb | 34 ++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/spec/acceptance/basic_spec.rb b/spec/acceptance/basic_spec.rb index 7e8ab76..fcbe82b 100644 --- a/spec/acceptance/basic_spec.rb +++ b/spec/acceptance/basic_spec.rb @@ -6,6 +6,8 @@ end specify do - expect(file('/etc/motd')).to have_attributes(content: /Foreman project/) + expect(file('/etc/motd')).to be_file + .and(have_attributes(content: /Foreman project/)) + .and(have_attributes(content: /FQDN:\s+#{host_inventory['fqdn']}/)) end end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 5a85722..7c0c72c 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,19 +1,29 @@ require 'spec_helper' describe 'motd' do - context 'default parameters' do - it { is_expected.to compile.with_all_deps } - it do - is_expected.to contain_file('/etc/motd') - .with_ensure('file') - .with_content(/property of the Foreman project/) - end - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) { facts } + + describe 'with default parameters' do + it { is_expected.to compile.with_all_deps } - context 'with ensure absent parameters' do - let(:params) { {ensure: 'absent'} } + it 'should contain a valid /etc/motd' do + is_expected.to contain_file('/etc/motd') + .with_ensure('file') + .with_content(/property of the Foreman project/) + .with_content(/FQDN:\s+#{facts['fqdn']}/) + .with_content(/Kernel:\s+#{facts['kernelrelease']}/) + .with_content(/Memory:\s#{facts['memorysize']}/) + end + end - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file('/etc/motd').with_ensure('absent') } + describe 'with ensure absent parameters' do + let(:params) { {ensure: 'absent'} } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file('/etc/motd').with_ensure('absent') } + end + end end end From 9ebfe986282a31302cb08ec8de250f7bf60aecf7 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Mon, 25 Mar 2024 09:18:57 +0100 Subject: [PATCH 2/3] Use structured facts --- templates/motd.erb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/templates/motd.erb b/templates/motd.erb index 6830e3e..1353af1 100644 --- a/templates/motd.erb +++ b/templates/motd.erb @@ -10,14 +10,12 @@ LOG OFF IMMEDIATELY if you do not agree to the conditions stated in this warning. ******************************************************************************* -<%= @operatingsystem %> <%= @operatingsystemrelease %> <%= @architecture %> +<%= @facts['os']['name'] %> <%= @facts['os']['release']['full'] %> <%= @facts['os']['architecture'] %> -FQDN: <%= @fqdn %> (<%= @ipaddress %>) -<% if has_variable?("processor0") then -%> -Processor: <%= @processorcount %>x <%= @processor0 %> -<% end -%> -Kernel: <%= @kernelrelease %> -Memory: <%= @memorysize %> +FQDN: <%= @facts['networking']['fqdn'] %> (<%= @facts['networking']['ipaddress'] %>) +Processor: <%= @facts['processors']['count'] %>x <%= @facts['processors']['models'][0] %> +Kernel: <%= @facts['kernelrelease'] %> +Memory: <%= @facts['memory']['system']['total'] %> <% if has_variable?("owner") then -%> Owner: <%= @owner -%> From 648f3c07df4f3651c9cee195431a8262a7d9730f Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Mon, 25 Mar 2024 08:42:51 +0100 Subject: [PATCH 3/3] Add Puppet 8 support --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 3185b89..e0d72af 100644 --- a/metadata.json +++ b/metadata.json @@ -21,7 +21,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 7.0.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "operatingsystem_support": [