Is it possible to pass extra flags to Puppet via rspec?`

153 views
Skip to first unread message

Amos Shapira

unread,
Jun 26, 2013, 10:23:29 PM6/26/13
to puppet...@googlegroups.com
Hello,

I'm writing my first puppet function rspec test and am having a problem which I don't see how to solve.

The function (and the test) involve access to files through the File Server. In order for the function (and the test) to work I need to pass "--fileserverconf=fileserver.conf" parameter to Puppet.

So far I haven't found a way to do that.

If I understand the rspec-puppet source at https://github.com/rodjek/rspec-puppet/blob/master/lib/rspec-puppet.rb correctly then the list of parameters I can pass is limited to the ones mentioned in lines 16-22. Am I right?

Does anyone know how can I pass other parameters, or otherwise affect Puppet's configuration to set this value?

Thanks,

--Amos

Wolf Noble

unread,
Jun 26, 2013, 10:35:12 PM6/26/13
to puppet...@googlegroups.com
Hi Amos,

Here's what I've done:

in spec/spec_helper.rb:

Puppet.settings[:confdir] = "spec/fixtures"

then in the class I was working on, I made a parameter:


class foo(
  $puppetdir = $settings::confdir
  ){
}


then in that class's spec test:

require 'spec_helper'
require 'puppetlabs_spec_helper/module_spec_helper'
foo = Puppet.settings[:confdir]

describe 'foo', :type => :class do

let (:params) do { 'puppetdir' => foo } end




it stands to reason that a similar method could be employed to feed your function, but I'm not certain.






--
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 post to this group, send email to puppet...@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Nan Liu

unread,
Jun 26, 2013, 11:14:58 PM6/26/13
to puppet...@googlegroups.com
Oddly enough, you can't depend on rspec-puppet to configure the settings for spec test. For example, puppetlab's spec helper configures the modulepath [1] to include spec/fixtures/modules, but this does not seem to configure Puppet[:modulepath] setting. For whatever reason, puppet loads the modules correctly from spec/fixtures/modules, but when you debug the spec test, it appears to set the module path to:

(rdb:1) p Puppet[:modulepath]
"/dev/null/modules:/usr/share/puppet/modules"

You can do what Wolf suggested. File server conf is somewhat inconsistent, since the setting is actually: Puppet[:fileserverconfig].

HTH,

Nan


 

Justin Stoller

unread,
Jun 27, 2013, 12:28:24 AM6/27/13
to puppet...@googlegroups.com
It's been a while since I jumped into this code and it's late, forgive me if I say something naive inline.


On Wed, Jun 26, 2013 at 8:14 PM, Nan Liu <nan...@gmail.com> wrote:
On Wed, Jun 26, 2013 at 7:23 PM, Amos Shapira <amos.s...@gmail.com> wrote:
I'm writing my first puppet function rspec test and am having a problem which I don't see how to solve.

The function (and the test) involve access to files through the File Server. In order for the function (and the test) to work I need to pass "--fileserverconf=fileserver.conf" parameter to Puppet.

So far I haven't found a way to do that.

If I understand the rspec-puppet source at https://github.com/rodjek/rspec-puppet/blob/master/lib/rspec-puppet.rb correctly then the list of parameters I can pass is limited to the ones mentioned in lines 16-22. Am I right?
 
Those are the limit you can pass to the RSpec.configure { ... } block in your spec helper.

Does anyone know how can I pass other parameters, or otherwise affect Puppet's configuration to set this value?

Have you tried something like:

describe 'foo' do
    before do
        Puppet[:fileserverconfig] = '/my/path/to/fileserver.conf'
    end

    ....your tests....

end

Oddly enough, you can't depend on rspec-puppet to configure the settings for spec test. For example, puppetlab's spec helper configures the modulepath [1] to include spec/fixtures/modules, but this does not seem to configure Puppet[:modulepath] setting. For whatever reason, puppet loads the modules correctly from spec/fixtures/modules, but when you debug the spec test, it appears to set the module path to:

(rdb:1) p Puppet[:modulepath]
"/dev/null/modules:/usr/share/puppet/modules"

Nan - 

In puppetlabs_spec_helper/puppet_spec_helper[1] which was based on a file in Puppet[2] the confdir and vardir are explicitly set to '/dev/null' which causes the modulepath you're seeing in Puppet "proper".

I believe, however the subject catalog/function that is tested in each example group (unless you explicitly create a subject yourself) should mask that value with what ever is passed into RSpec.configure (like the modulepath setting in module_spec_helper) for its compilation/initialization[3][4].


 - Justin

You can do what Wolf suggested. File server conf is somewhat inconsistent, since the setting is actually: Puppet[:fileserverconfig].

HTH,

Nan


 

--
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 post to this group, send email to puppet...@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

Join us at PuppetConf 2013, August 22-23 in San Francisco -
http://bit.ly/pupconf13

Nan Liu

unread,
Jun 27, 2013, 2:09:28 AM6/27/13
to puppet...@googlegroups.com
On Wed, Jun 26, 2013 at 9:28 PM, Justin Stoller <jus...@puppetlabs.com> wrote: 
In puppetlabs_spec_helper/puppet_spec_helper[1] which was based on a file in Puppet[2] the confdir and vardir are explicitly set to '/dev/null' which causes the modulepath you're seeing in Puppet "proper".

I believe, however the subject catalog/function that is tested in each example group (unless you explicitly create a subject yourself) should mask that value with what ever is passed into RSpec.configure (like the modulepath setting in module_spec_helper) for its compilation/initialization[3][4].

Thanks for the clarification, that would certainly explain why I'm seeing /dev/null in module path. 

Nan

Amos Shapira

unread,
Jun 29, 2013, 2:48:01 AM6/29/13
to puppet...@googlegroups.com
Thanks for the tip, Justin and everyone else who replied.
I'll try your suggestion.

Cheers,

--Amos


--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/ynVp988yEcU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.

To post to this group, send email to puppet...@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Reply all
Reply to author
Forward
0 new messages