Closed rnelson0 closed 3 years ago
Hi @rnelson0,
After looking at this, we realized this was similar to another issue we had seen recently. The underlying problem is that we currently package the old pure-Ruby Facter 2.x gem in the PDK. Since it isn't actually used at runtime, it's just there to satisfy the Puppet gem's dependency. However this currently causes rspec-puppet-facts to use the 2.x fact sets which are increasingly out of date with what facter 3.x actually produces.
We have already ticketed a solution to this (https://tickets.puppetlabs.com/browse/PDK-1394) which will let us configure rspec-puppet-facts to use a newer fact set regardless of what version of the facter gem is installed into the PDK. Hope to have this fixed in the next-ish PDK release.
Great, I can confirm that on_supported_os(facterversion: '3.11.0')...
fixes the problem. I'll leave my facts.merge()
in place until this is fixed, seems less harmful if I leave it in place too long.
This same issue occurs with pdk bundle exec puppet …
I ran into what I think is this same bug when writing a spec test for a custom Ruby fact using PDK 1.13.0.
The fact parses and munges the networking
fact. When trying to stub out values for the networking
fact, rspec was throwing this warning:
WARNING: An expectation of ':value' was set on 'nil'
Some pry
debugging:
[10] pry(#<RSpec::ExampleGroups::LogicalInterface::OnAPhysicalHost>)> allow(Facter.fact(:networking)).to receive(:value).and_return(physical_networking_facts)
WARNING: An expectation of `:value` was set on `nil`. To allow expectations on `nil` and suppress this message, set `RSpec::Mocks.configuration.allow_message_expectations_on_nil` to `true`. To disallow expectations on `nil`, set `RSpec::Mocks.configuration.allow_message_expectations_on_nil` to `false`. Called from (pry):6:in `block (3 levels) in <top (required)>'.
[11] pry(#<RSpec::ExampleGroups::LogicalInterface::OnAPhysicalHost>)> Facter.fact(:networking)
=> nil
[12] pry(#<RSpec::ExampleGroups::LogicalInterface::OnAPhysicalHost>)> Facter.value(:facterversion)
=> "2.5.6"
As this was a spec test for a Ruby fact and not Puppet code, the on_supported_os
workaround didn't work, and I couldn't figure out how to set the Facter version in spec_helper.rb or anywhere else.
What ended up fixing my tests was detecting if the fact was nil
then adding it.
Original, broken test:
before(:each) do
Facter.clear
allow(Facter.fact(:networking)).to receive(:value).and_return(networking_hash) # This failed.
allow(Facter.fact(:virtual)).to receive(:value).and_return('physical')
end
New, working test:
before(:each) do
Facter.clear
# Workaround for https://github.com/puppetlabs/pdk/issues/694
if Facter.fact(:networking).nil?
Facter.add(:networking) {}
Facter.flush
end
allow(Facter.fact(:networking)).to receive(:value).and_return(networking_hash)
allow(Facter.fact(:virtual)).to receive(:value).and_return('physical')
end
@rodjek Do you have any thoughts on Nate's issue here?
This issue has been marked stale because it is open with no recent activity. The PDK Team is actively prioritizing existing bugs and new features, if this issue is still important to you please comment and we will add this to our backlog to complete.
Not sure when it got fixed, but as of PDK 1.18.1 with the following gems, the workaround from my previous comment isn't needed. Looks like this problem has been solved?
Thanks for the follow up @natemccurdy - I'll close this issue for now, if you believe it's been resolved. If not, we can reopen again
When performing a test, I do not receive a
networking
hash entry in the facts received fromrspec-puppet-facts
. This is causing me an issue withsaz/ssh
, where I have to duplicate this structure in my test.To Reproduce Test a class that includes
ssh::server
with redhat 6 or 7 listed as a supported OS in metadata.json. Includepp facts
inside the OS loop to print out the received facts.Expected behavior That the facts include the networking hash found in recent facterdb entries (dated Dec 11, 2018; release included in PDK is from Dec 13, 2018).
Additional context
I do not understand enough of how rspec-puppet-facts/facterdb works to determine why it is not using the
facts/3.9/redhat-7-x86_64.facts
path, sorry.