Ask Your Question

Given this entry in a Puppet manifest: before => Class['rabbitmq']

asked 2016-02-01 15:56:30 -0600

pla gravatar image

updated 2016-02-03 07:00:20 -0600

and the following in a Ruby rspec module: :before => 'Class[rabbitmq]'

Results in the rspec compiler telling me:

Failure/Error: ) expected that the catalogue would contain Exec[init-puppet-nodecert.pem] with before set to "Class[rabbitmq]" but it is set to nil # ./spec/classes/puppetmaster_spec.rb:25

I have tried adding extra square brackets, adding more single quotes, etc. and seem to make matters only worse. I hace searched and searched on the www - there just do not seem to be very many examples of people's rspec Ruby code out there.

manifest code:

exec { 'init-puppet-truststore.pem':
    path        => ["/bin", "/usr/bin"],
    command     => "mkdir -p /etc/puppet/modules/rabbitmq/files && cat /var/lib/puppet/ssl/certs/ca.pem >> /etc/puppet/modules/rabbitmq/files/truststore.pem",
    onlyif      => 'test ! -f /etc/puppet/modules/rabbitmq/files/truststore.pem || test "$(/etc/puppet/scripts/ /etc/puppet/modules/rabbitmq/files/truststore.pem /var/lib/puppet/ssl/certs/ca.pem)" == "no"',
    before      => Class['rabbitmq'],

rspec code:

it {
  should contain_exec('init-puppet-truststore.pem').with(
             :path => ['/bin', '/usr/bin'],
             :command => "mkdir -p /etc/puppet/modules/rabbitmq/files && cat /var/lib/puppet/ssl/certs/ca.pem >> /etc/puppet/modules/rabbi

tmq/files/truststore.pem", :onlyif => "test ! -f /etc/puppet/modules/rabbitmq/files/truststore.pem || test \"$(/etc/puppet/scripts/ /etc/pup pet/modules/rabbitmq/files/truststore.pem /var/lib/puppet/ssl/certs/ca.pem)\" == \"no\"" :before => 'Class[rabbitmq]' )

Like the elderly lady said in the Home Alert advertisement, "I've fallen and I won't shut up!" - or something like that...

An answer received advised that I use single quotes instead of a colon (:) in the rspec file. I have almost a dozen other rspec unit test files that also use the colon (:) character successfully. NOTE: The issue is with the line containing the :before attribute.

Below is the compiler output when single quotes are substituted for the colon character: usenlapinpm1:modules lapinp$ rspec spec /Users/lapinp/.rvm/gems/ruby-1.8.7-head/gems/rspec-core-3.1.6/lib/rspec/core/configuration.rb:1105:in `load': /Users/lapinp/0108160900platformclone/system/config/puppet/modules/spec/classes/puppetmasterspec.rb:24: syntax error, unexpected tSTRINGBEG, expecting ')' (SyntaxError) 'before' => 'Class[rabbitmq]' ^

This is not a solution for the issue I presented.

edit retag flag offensive close merge delete


Without seeing the context of your code, it is hard to provide an answer. Please edit your question to include significant code snippets and file names.

lavaman gravatar imagelavaman ( 2016-02-01 16:39:58 -0600 )edit

manifest: exec { 'init-puppet-truststore.pem': path => ["/bin", "/usr/bin"], command => "mkdir -p /etc/puppet/modules/rabbitmq/files && cat /var/lib/puppet/ssl/certs/ca.pem >> /etc/puppet/modules/rabbitmq/files/truststore.pem", (continued in next comment)

pla gravatar imagepla ( 2016-02-02 06:02:50 -0600 )edit

onlyif => 'test ! -f /etc/puppet/modules/rabbitmq/files/truststore.pem || test "$(/etc/puppet/scripts/ /etc/puppet/modules/rabbitmq/files/truststore.pem /var/lib/puppet/ssl/certs/ca.pem)" == "no"', before => Class['rabbitmq'], } rspec code in the next comment:

pla gravatar imagepla ( 2016-02-02 06:03:53 -0600 )edit

rspec: it { should contain_exec('init-puppet-truststore.pem').with( :path => ['/bin', '/usr/bin'], :command => "mkdir -p /etc/puppet/modules/rabbitmq/files && cat /var/lib/puppet/ssl/certs/ca.pem >> /etc/puppet/modules/rabbi tmq/files/truststore.pem",

pla gravatar imagepla ( 2016-02-02 06:04:29 -0600 )edit

continuation of rspec code: :onlyif => "test \! -f /etc/puppet/modules/rabbitmq/files/truststore.pem || test \"$(/etc/puppet/scripts/ /etc/pup pet/modules/rabbitmq/files/truststore.pem /var/lib/puppet/ssl/certs/ca.pem)\" == \"no\"" continued in next comment

pla gravatar imagepla ( 2016-02-02 06:05:31 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-02 17:02:10 -0600

lavaman gravatar image

I believe they stopped using symbols for parameters in rspec-puppet. Try putting quotes around all the parameters you're testing, instead of a colon in front.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-02-01 15:56:30 -0600

Seen: 345 times

Last updated: Feb 03 '16