Skip to content

Commit

Permalink
Remove use of legacy facts for Puppet 8 compatibility (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
silug authored Feb 14, 2024
1 parent a0da546 commit c01eb62
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Wed Feb 14 2024 Steven Pritchard <[email protected]> - 3.8.1
- Remove use of legacy facts for Puppet 8 compatibility

* Mon Oct 23 2023 Steven Pritchard <[email protected]> - 3.8.0
- [puppetsync] Add EL9 support

Expand Down
8 changes: 4 additions & 4 deletions lib/puppetx/simp/compliance_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/suites/default/00_default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand All @@ -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){
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit c01eb62

Please sign in to comment.