Skip to content

Commit ce85a54

Browse files
authored
Merge pull request #8994 from joshcooper/merge-up
(maint) Merge 7.x to main
2 parents a2a4c8a + 8f6bf84 commit ce85a54

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

lib/puppet/indirector/facts/facter.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def find(request)
4040
Puppet::Node::Facts.new(request.key, Puppet.runtime[:facter].to_hash)
4141
else
4242
# resolve does not return legacy facts unless requested
43-
Puppet::Node::Facts.new(request.key, Puppet.runtime[:facter].resolve(''))
43+
facts = Puppet.runtime[:facter].resolve('')
44+
# some versions of Facter 4 return a Facter::FactCollection instead of
45+
# a Hash, breaking API compatibility, so force a hash using `to_h`
46+
Puppet::Node::Facts.new(request.key, facts.to_h)
4447
end
4548

4649
result.add_local_facts unless request.options[:resolve_options]

spec/integration/node/facts_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
it "should be able to delegate to the :facter terminus" do
3131
allow(Puppet::Node::Facts.indirection).to receive(:terminus_class).and_return(:facter)
3232

33-
expect(Facter).to receive(:resolve).and_return("facter_hash")
33+
expect(Facter).to receive(:resolve).and_return({1 => 2})
3434
facts = Puppet::Node::Facts.new("me")
35-
expect(Puppet::Node::Facts).to receive(:new).with("me", "facter_hash").and_return(facts)
35+
expect(Puppet::Node::Facts).to receive(:new).with("me", {1 => 2}).and_return(facts)
3636

3737
expect(Puppet::Node::Facts.indirection.find("me")).to equal(facts)
3838
end

spec/unit/indirector/facts/facter_spec.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'spec_helper'
22
require 'puppet/indirector/facts/facter'
33

4+
class Puppet::Node::Facts::Facter::MyCollection < Hash; end
5+
46
describe Puppet::Node::Facts::Facter do
57
FS = Puppet::FileSystem
68

@@ -87,11 +89,24 @@
8789
it "can exclude legacy facts" do
8890
Puppet[:include_legacy_facts] = false
8991

90-
facts = Puppet::Node::Facts.new("foo")
91-
expect(Puppet::Node::Facts).to receive(:new).and_return(facts)
9292
expect(Puppet.runtime[:facter]).to receive(:resolve).with('')
93+
.and_return({'kernelversion' => '1.2.3'})
9394

94-
@facter.find(@request)
95+
values = @facter.find(@request).values
96+
expect(values).to be_an_instance_of(Hash)
97+
expect(values).to include({'kernelversion' => '1.2.3'})
98+
end
99+
100+
it "can exclude legacy facts using buggy facter implementations that return a Hash subclass" do
101+
Puppet[:include_legacy_facts] = false
102+
103+
collection = Puppet::Node::Facts::Facter::MyCollection["kernelversion" => '1.2.3']
104+
expect(Puppet.runtime[:facter]).to receive(:resolve).with('')
105+
.and_return(collection)
106+
107+
values = @facter.find(@request).values
108+
expect(values).to be_an_instance_of(Hash)
109+
expect(values).to include({'kernelversion' => '1.2.3'})
95110
end
96111
end
97112

0 commit comments

Comments
 (0)