Simon Piette
2013-Apr-30 00:45 UTC
[Puppet Users] rspec-puppet testing with puppet $::settings
Hi all, Let''s say I have this in a manifest: file { "${::settings::vardir}/files": ensure => directory } And I want to test it in the catalog using: it { should create_file(''/var/lib/puppet/files'') } It won''t work because an mktemp directory is made for vardir for each catalogue. The catalogue will containt a File[/tmp/d20130429-26229-3glbki/files] reference. Curiously, in the "it" block, Puppet[:ssldir] is expanded to /dev/null/ssl and Puppet[:vardir] to /dev/null (consequently). Is it possible to access the Puppet[:vardir] from the {Class,Define,Host}ExampleGroup? Or any other $::settings variables? Other ways would be to include a puppet.conf to inject settings, or as we already do with facts, inject :settings at the beginning of the describe block. Any solution for testing variables that depends on settings will be welcome. Thanks, -- 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Wolf Noble
2013-Apr-30 06:48 UTC
Re: [Puppet Users] rspec-puppet testing with puppet $::settings
Hi Simon, On Apr 29, 2013, at 23:35, "Simon Piette" <piette.simon@gmail.com> wrote:> Hi all, > <snip> > Any solution for testing variables that depends on settings will be welcomeWhat I''ve done elsewhere is to make a parameter for, in your case, vardir: (untested, but close) Class foo($vardir = $::settings::vardir){ file { "${vardir}/files": ensure => directory } } Then in spec/classes/foo_main_spec.rb: require ''spec_helper'' require ''puppetlabs_spec_helper/module_spec_helper'' vartest = Puppet.settings[:vardir] describe ''foo'', :type => :class do #... #Then you can assign vartest as a class parameter to your tests. end W =MobileMailPlease excuse brevity or spelling errors -- 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Wolf Noble
2013-Apr-30 16:05 UTC
Re: [Puppet Users] rspec-puppet testing with puppet $::settings
Hi Simon, On Apr 29, 2013, at 7:45 PM, Simon Piette <piette.simon@gmail.com> wrote:> Hi all, > <snip> > Any solution for testing variables that depends on settings will be welcome. > > Thanks,I sent this last night from another account, but it didn''t seem to go through: What I''ve done elsewhere is to make a parameter for, in your case, vardir: (untested, but close) Class foo($vardir = $::settings::vardir){ file { "${vardir}/files": ensure => directory } } Then in spec/classes/foo_main_spec.rb: require ''spec_helper'' require ''puppetlabs_spec_helper/module_spec_helper'' vartest = Puppet.settings[:vardir] describe ''foo'', :type => :class do #... #Then you can assign vartest as a class parameter to your tests. end Hope that helps. W ________________________________ This message may contain confidential or privileged information. If you are not the intended recipient, please advise us immediately and delete this message. See http://www.datapipe.com/legal/email_disclaimer/ for further information on confidentiality and the risks of non-secure electronic communication. If you cannot access these links, please notify us by reply message and we will send the contents to you. -- 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Simon Piette
2013-Apr-30 17:08 UTC
Re: [Puppet Users] rspec-puppet testing with puppet $::settings
Hi Wolfe, On Tue, Apr 30, 2013 at 12:05 PM, Wolf Noble <wnoble@datapipe.com> wrote:> Hi Simon, > On Apr 29, 2013, at 7:45 PM, Simon Piette <piette.simon@gmail.com> > wrote: > > What I''ve done elsewhere is to make a parameter for, in your case, vardir: > > > (untested, but close) > > Class foo($vardir = $::settings::vardir){ > file { "${vardir}/files": > ensure => directory > } > } > > > Then in > spec/classes/foo_main_spec.rb: > require ''spec_helper'' > require ''puppetlabs_spec_helper/module_spec_helper'' > vartest = Puppet.settings[:vardir] > describe ''foo'', :type => :class do > #... > #Then you can assign vartest as a class parameter to your tests. > end > > > >That''s what I did for this module: https://github.com/spiette/puppet-selinux/blob/master/manifests/params.pp But under other circumstances, (a puppet module) I can''t do this, I have to use the $::settings variable. Thanks, Simon -- 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Wolf Noble
2013-May-01 15:13 UTC
Re: [Puppet Users] rspec-puppet testing with puppet $::settings
Hi Simon, On Tue, Apr 30, 2013 at 12:08 PM, Simon Piette <piette.simon@gmail.com>wrote:> Hi Wolfe, > > On Tue, Apr 30, 2013 at 12:05 PM, Wolf Noble <wnoble@datapipe.com> wrote: > >> Hi Simon, >> On Apr 29, 2013, at 7:45 PM, Simon Piette <piette.simon@gmail.com> >> wrote: >> >> What I''ve done elsewhere is to make a parameter for, in your case, vardir: >> >> >> (untested, but close) >> >> Class foo($vardir = $::settings::vardir){ >> file { "${vardir}/files": >> ensure => directory >> } >> } >> >> >> Then in >> spec/classes/foo_main_spec.rb: >> require ''spec_helper'' >> require ''puppetlabs_spec_helper/module_spec_helper'' >> vartest = Puppet.settings[:vardir] >> describe ''foo'', :type => :class do >> #... >> #Then you can assign vartest as a class parameter to your tests. >> end >> >> >> >> > That''s what I did for this module: > > https://github.com/spiette/puppet-selinux/blob/master/manifests/params.pp > > But under other circumstances, (a puppet module) I can''t do this, I have > to use the $::settings variable. > > Thanks, > > Simon > >I suspect what''s going on here, is the class you''re testing doesn''t have the ability to override the $::settings::vardir variable. I''ve found that if I make the relevant variable a parameter to the class in question, I can override it in the tests in question. It may be possible to set a different class''s parameter to a value from a test, but I''ve not found a way. This has resulted in me making whatever variables I need to override parameters to the class I''m testing. I''d be curious to hear how others have accomplished this. Would you mind showing us the module you''re talking about where you were having problems with this approach? Perhaps the list can offer some input on other ways to accomplish your needs. CAVEAT: The statement that I''ve not seen a better way doesn''t mean there isn''t one. -- 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Simon Piette
2013-May-02 11:58 UTC
Re: [Puppet Users] rspec-puppet testing with puppet $::settings
Hi Wolf, On Wed, May 1, 2013 at 11:13 AM, Wolf Noble <wolf@wolfspyre.com> wrote:> > > I suspect what''s going on here, is the class you''re testing doesn''t have > the ability to override the $::settings::vardir variable. > I''ve found that if I make the relevant variable a parameter to the class > in question, I can override it in the tests in question. >It does, but it doesn''t make sense. It''s for a puppet module ( https://github.com/spiette/puppet-puppet/blob/master/manifests/master/certificate.pp). I want to change the exec {link-ca-crl: } for a file. I need the $::settings as I would need a fact. I can add the parameter, but it would be there for testing purpose only. I''ll fill a bug at rspec-puppet.> It may be possible to set a different class''s parameter to a value from a > test, but I''ve not found a way. >I don''t like the idea of changing a manifest to get around a limitation of the testing framework. Thanks for your feedback, Simon -- 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.