Error while spec testing -- missing collect?

38 views
Skip to first unread message

Peter Berghold

unread,
Dec 5, 2016, 11:25:56 AM12/5/16
to puppet-users
The piece of Puppet code the spec testing is complaining about is here:

----------8< snip 8<-------------------------------------------------------------------------

  $servers = ntp_unpackservers(
    query_facts("is_ntp_server=true and sitename = ${sitename}",'ipaddress')
  )

----------8< snip 8<-------------------------------------------------------------------------

and the error I'm seeing is:

----------8< snip 8<-------------------------------------------------------------------------

     Puppet::Error:
       undefined method `collect' for "ipaddress":String at /home/<my account>/puppet-module-src/ntp/spec/fixtures/modules/ntp/manifests/client.pp:8 on node redacted

----------8< snip 8<-------------------------------------------------------------------------

so the question is what defines "collect?" 

The code sniglet is a query of PuppetDB that works well in our test and production environments but I'm having issues trying to convince RSpec it's working. 

Thoughts? Suggestions?

Rob Nelson

unread,
Dec 5, 2016, 12:43:29 PM12/5/16
to puppet...@googlegroups.com
The error is in the function query_facts, or code that it calls. Puppet is not great about reporting on a Ruby code failure called from the puppet DSL.

I couldn't tell you the actual cause but if you look wherever that function is defined you may see a collect statement and that should guide you. My guess is that some fact it relies on wasn't mocked (well) and is returning nil, thus there is no .collect method on nil.

--
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/CAArvnv3ivnqNoQk2dFzuD3YYpy4p9YBY_XpCZUgc2wTT4vNsWA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
Rob Nelson

Peter Berghold

unread,
Dec 5, 2016, 1:17:26 PM12/5/16
to puppet...@googlegroups.com
Give the man a cigar.  As soon as I mocked up "ipaddress" it was happy.  Don't know why I didn't see that....


Rob Nelson

unread,
Dec 5, 2016, 3:15:16 PM12/5/16
to puppet...@googlegroups.com
You may want to look into https://github.com/mcanevet/rspec-puppet-facts as this has bit me in the behind more than once until I made the switch. The readme is a pretty good guide to get started, and I wrote a little bit on doing OS/kernel specific tests with it at https://rnelson0.com/2016/11/04/puppet-tech-debt-day-3-excluding-os-testing/, important if you support say linux and windows. I need to write another article that's a little more complete on the setup, but if you have questions, ask away. Pretty sure mcanevet is around here, too.
On Mon, Dec 5, 2016 at 1:16 PM, Peter Berghold <salty....@gmail.com> wrote:
Give the man a cigar.  As soon as I mocked up "ipaddress" it was happy.  Don't know why I didn't see that....


On Mon, Dec 5, 2016 at 12:43 PM Rob Nelson <rnel...@gmail.com> wrote:
The error is in the function query_facts, or code that it calls. Puppet is not great about reporting on a Ruby code failure called from the puppet DSL.

I couldn't tell you the actual cause but if you look wherever that function is defined you may see a collect statement and that should guide you. My guess is that some fact it relies on wasn't mocked (well) and is returning nil, thus there is no .collect method on nil.

On Mon, Dec 5, 2016 at 5:25 PM Peter Berghold <salty....@gmail.com> wrote:
The piece of Puppet code the spec testing is complaining about is here:

----------8< snip 8<-------------------------------------------------------------------------

  $servers = ntp_unpackservers(
    query_facts("is_ntp_server=true and sitename = ${sitename}",'ipaddress')
  )

----------8< snip 8<-------------------------------------------------------------------------

and the error I'm seeing is:

----------8< snip 8<-------------------------------------------------------------------------

     Puppet::Error:
       undefined method `collect' for "ipaddress":String at /home/<my account>/puppet-module-src/ntp/spec/fixtures/modules/ntp/manifests/client.pp:8 on node redacted

----------8< snip 8<-------------------------------------------------------------------------

so the question is what defines "collect?" 

The code sniglet is a query of PuppetDB that works well in our test and production environments but I'm having issues trying to convince RSpec it's working. 

Thoughts? Suggestions?

--
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+unsubscribe@googlegroups.com.
--
Rob Nelson

--
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+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAArvnv3WRpaQn8LK0dWDVZZETc8ax%3D1MZOq%2BfL-VKU6PteKwRA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages