rspec, trusted facts, and node facts

110 views
Skip to first unread message

jcbollinger

unread,
Apr 5, 2018, 6:07:35 PM4/5/18
to Puppet Users
I am working on rspec tests for a module for Puppet 5 that refers to nodes' $::trusted_facts hash, and, separately, relies on nodes' $::networking fact.  In particular it uses the values of $::networking['fqdn'] and $::networking['hostname'].  I would like to test scenarios where the attributes of $::networking are unrelated to the node name, or even are absent altogether, but I can't figure out how to do it.

Through a combination of documentation and trial and error, I think I have determined that in order for rspec-puppet to provide the $::trusted_facts hash to the catalog builder, I need to configure its trusted_node_data parameter to true, and to define a node name in my tests via let(:node) { 'node-name' }.

After doing so, however, I found that the catalog builder was receiving different values for the hostname and fqdn than those I specify via a let(:facts) call.  After much head scratching, hypothesizing, and net searching, I think I finally established that by default, rspec-puppet uses the node name to set values for these properties, overriding anything to the contrary in the facts I provide.

But wait!  Rspec-puppet also has a configuration parameter, derive_node_facts_from_nodename, that seems custom-made for disabling the troublesome behavior.  That's great, except that setting that parameter to false seems to disable the $::trusted_facts hash as well.

Is there some combination of rspec configuration settings and test code that can give me the test scenarios I want?  That is, $::trusted_facts presented to the catalog builder and containing at least the certname key, with $::networking['fqdn'] and $::networking['hostname'] taking independent values (or being undefined), as I specify separately?


John

jcbollinger

unread,
Apr 6, 2018, 10:12:46 AM4/6/18
to Puppet Users
On Thursday, April 5, 2018 at 5:07:35 PM UTC-5, jcbollinger wrote:

Of course, I realize at this point that I am too dumb to spell "::trusted" correctly.  But that's ancillary -- I still want to test scenarios where the node's fqdn and hostname are independent of its certname, and rspec-puppet seems unwilling to let me set the two former facts in any way other than by allowing them to be derived automatically from the node name / certname.

John

Nick Miller

unread,
Apr 6, 2018, 10:19:04 AM4/6/18
to puppet...@googlegroups.com
There was some discussion on a GitHub issue relating to this: https://github.com/rodjek/rspec-puppet/pull/643

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/c57cafc2-45c3-4ed4-b627-4722876fc8d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

OnyxPoint-logo-symbol-primary.png

Nicholas Miller
Consultant | Onyx Point, Inc.

7050 Hi Tech Drive, Suite 102

Hanover, MD. 21076
e: nick....@onyxpoint.com
w: 443-655-3675

copmany.pngcareers.pngproduct.pngmeetups.pngblog.png


jcbollinger

unread,
Apr 6, 2018, 10:30:49 AM4/6/18
to Puppet Users


On Friday, April 6, 2018 at 9:19:04 AM UTC-5, Nick Miller wrote:
There was some discussion on a GitHub issue relating to this: https://github.com/rodjek/rspec-puppet/pull/643


Thanks, NIck.  It looks like I've finally got this sorted.  I went back to twiddling the trusted_node_data and derive_node_facts_from_nodename rspec-puppet parameters, tweaked the tests, and made some spelling corrections in the class under test.  My tests are now passing, and I'm satisfied that I understand why.

Cheers,

John


nand...@gmail.com

unread,
Mar 25, 2021, 2:00:18 PM3/25/21
to Puppet Users
Hi all ,
I have started my rspec code to test modules for unit testing .as there is no good document to start with ,  Can you share some of your rspec code testing the modules using rspec and steps to run spec against servers ,

Regards,
Nandha

David Schmitt

unread,
Mar 26, 2021, 6:00:36 AM3/26/21
to Puppet Users

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

nandha kumar

unread,
Mar 26, 2021, 9:30:58 AM3/26/21
to puppet...@googlegroups.com
Hi David ,

Yes I did see the site , but it doesn't help me much with proper procedure. 

I am looking out to run test against list of nodegroups and how can I achieve that ?

Regards,
Nandha 

nand...@gmail.com

unread,
Apr 5, 2021, 5:09:04 AM4/5/21
to Puppet Users

Hi all,

I have somehow managed to write basic rspec test . But i need to run the rspec test on multiple servers .
Please some one provide guidance on running rspec against different node groups or envs ?

Regards,
Nandha
Reply all
Reply to author
Forward
0 new messages