From c01eb62c773192887d509f90d4c263b0699df293 Mon Sep 17 00:00:00 2001 From: Steven Pritchard Date: Wed, 14 Feb 2024 12:14:51 -0600 Subject: [PATCH] Remove use of legacy facts for Puppet 8 compatibility (#169) --- CHANGELOG | 3 +++ lib/puppetx/simp/compliance_map.rb | 8 +++---- metadata.json | 2 +- .../suites/default/00_default_spec.rb | 2 +- spec/classes/init_spec.rb | 22 +++++++++---------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1df60c6..079cee3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +* Wed Feb 14 2024 Steven Pritchard - 3.8.1 +- Remove use of legacy facts for Puppet 8 compatibility + * Mon Oct 23 2023 Steven Pritchard - 3.8.0 - [puppetsync] Add EL9 support diff --git a/lib/puppetx/simp/compliance_map.rb b/lib/puppetx/simp/compliance_map.rb index 8a6bcd3..031b1d6 100644 --- a/lib/puppetx/simp/compliance_map.rb +++ b/lib/puppetx/simp/compliance_map.rb @@ -128,9 +128,9 @@ def process_options(args) config[:extra_data] = { # Add the rest of the useful information to the map - 'fqdn' => @context.lookupvar('fqdn'), - 'hostname' => @context.lookupvar('hostname'), - 'ipaddress' => @context.lookupvar('ipaddress'), + 'fqdn' => lookup_fact('networking.fqdn'), + 'hostname' => lookup_fact('networking.hostname'), + 'ipaddress' => lookup_fact('networking.ip'), 'puppetserver_info' => 'local_compile' } @@ -219,7 +219,7 @@ class << compliance_resource def write_server_report(config, report) - report_dir = File.join(config[:server_report_dir], @context.lookupvar('fqdn')) + report_dir = File.join(config[:server_report_dir], lookup_fact('networking.fqdn')) FileUtils.mkdir_p(report_dir) if config[:server_report] diff --git a/metadata.json b/metadata.json index 3b45d7f..9478e2f 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "simp-compliance_markup", - "version": "3.8.0", + "version": "3.8.1", "author": "SIMP Team", "summary": "Compliance-mapping annotation for Puppet code", "license": "Apache-2.0", diff --git a/spec/acceptance/suites/default/00_default_spec.rb b/spec/acceptance/suites/default/00_default_spec.rb index fbd915a..8efe108 100644 --- a/spec/acceptance/suites/default/00_default_spec.rb +++ b/spec/acceptance/suites/default/00_default_spec.rb @@ -50,7 +50,7 @@ class test ( } end - let(:fqdn) { fact_on(host, 'fqdn') } + let(:fqdn) { fact_on(host, 'networking.fqdn') } it 'should have a report' do tmpdir = Dir.mktmpdir diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 84f9157..bd18433 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -55,7 +55,7 @@ def remove_data let(:raw_report) { # There can be only one - report_file = "#{params['options']['server_report_dir']}/#{facts[:fqdn]}/compliance_report.yaml" + report_file = "#{params['options']['server_report_dir']}/#{facts[:networking][:fqdn]}/compliance_report.yaml" File.read(report_file) } @@ -86,11 +86,11 @@ class yum ( let(:params) { @default_params } it 'should have a server side compliance report node directory' do - expect(File).to exist("#{params['options']['server_report_dir']}/#{facts[:fqdn]}") + expect(File).to exist("#{params['options']['server_report_dir']}/#{facts[:networking][:fqdn]}") end it 'should have a server side compliance node report' do - expect(File).to exist("#{params['options']['server_report_dir']}/#{facts[:fqdn]}/compliance_report.yaml") + expect(File).to exist("#{params['options']['server_report_dir']}/#{facts[:networking][:fqdn]}/compliance_report.yaml") end it 'should have a failing check' do @@ -104,7 +104,7 @@ class yum ( context 'when dumping the catalog compliance_map' do let(:catalog_dump) { # There can be only one - File.read("#{params['options']['server_report_dir']}/#{facts[:fqdn]}/catalog_compliance_map.yaml") + File.read("#{params['options']['server_report_dir']}/#{facts[:networking][:fqdn]}/catalog_compliance_map.yaml") } let(:params){ @@ -114,7 +114,7 @@ class yum ( } it 'should have a generated catlaog' do - expect(File).to exist("#{params['options']['server_report_dir']}/#{facts[:fqdn]}/catalog_compliance_map.yaml") + expect(File).to exist("#{params['options']['server_report_dir']}/#{facts[:networking][:fqdn]}/catalog_compliance_map.yaml") expect(catalog_dump).to match(/GENERATED/) end @@ -287,7 +287,7 @@ class test4 ( let(:report) { # There can be only one - report_file = "#{params['options']['server_report_dir']}/#{facts[:fqdn]}/compliance_report.#{report_format}" + report_file = "#{params['options']['server_report_dir']}/#{facts[:networking][:fqdn]}/compliance_report.#{report_format}" if report_format == 'yaml' @report ||= YAML.load_file(report_file) @@ -316,11 +316,11 @@ class test4 ( end it 'should have a server side compliance report node directory' do - expect(File).to exist("#{params['options']['server_report_dir']}/#{facts[:fqdn]}") + expect(File).to exist("#{params['options']['server_report_dir']}/#{facts[:networking][:fqdn]}") end it 'should have a server side compliance node report' do - expect(File).to exist("#{params['options']['server_report_dir']}/#{facts[:fqdn]}/compliance_report.#{report_format}") + expect(File).to exist("#{params['options']['server_report_dir']}/#{facts[:networking][:fqdn]}/compliance_report.#{report_format}") end it 'should have a summary for each profile' do @@ -340,9 +340,9 @@ class test4 ( end it 'should have the default extra data in the report' do - expect(report['fqdn']).to eq(facts[:fqdn]) - expect(report['hostname']).to eq(facts[:hostname]) - expect(report['ipaddress']).to eq(facts[:ipaddress]) + expect(report['fqdn']).to eq(facts[:networking][:fqdn]) + expect(report['hostname']).to eq(facts[:networking][:hostname]) + expect(report['ipaddress']).to eq(facts[:networking][:ip]) expect(report['puppetserver_info']).to eq(server_facts_hash.merge({'environment' => environment})) end