Ask Your Question

augeas in rspec-puppet

asked 2015-06-11 06:36:03 -0600

Chutki gravatar image

updated 2015-06-18 04:29:27 -0600


I have written below module/test/spec/defines/limitdefspec.rb,

require 'spec_helper'

describe 'test::limits_def',  :type => :class  do

  let(:params) { { :item => 'fsize', :value => 'unlimited'} }

        #it { should contain_class('test::limits_def')}
        it {should  contain_augeas('limits::limit').with(
             'lens' => 'limits.lns',
             'incl' => '/etc/security/limits.conf',
             'changes' => [ 'set /etc/security/limits.conf/domain user',
                            'set /etc/security/limits.conf/domain/type soft',
                            'set /etc/security/limits.conf/domain/item fsize',
                            'set /etc/security/limits.conf/domain/value unlimited'])

Below is my define file modules/test/manifests/limit_def.pp

define test::limit_def($item=$title,$value){

$path_exact = "domain[item=\"$item\" and ./value=\"$value\"]"

    augeas { $title:
      lens  => 'limits.lns',
      incl  => '/etc/security/limits.conf',
      onlyif  => "match $path_exact size == 0",
      changes  => ["set domain[last()+1] user",
                   "set domain[last()]/type  soft",
                   "set domain[last()]/item  $item",
                   "set domain[last()]/value $value",
                   "set domain[last()+1] user",
                   "set domain[last()]/type  hard",
                   "set domain[last()]/item  $item",
                   "set domain[last()]/value $value",],

but when I run "rake spec" getting below error

/usr/bin/ruby -S rspec spec/defines/limit_def_spec.rb


  1) test::limits_def
     Failure/Error: 'set /etc/security/limits.conf/domain/value unlimited'])
       Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class test::limits_def at line 4 on node      # ./spec/defines/limit_def_spec.rb:14

Finished in 0.05787 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/defines/limit_def_spec.rb:8 # test::limits_def
rake aborted!
ruby -S rspec spec/defines/limit_def_spec.rb failed

below is the gems

*** LOCAL GEMS ***

diff-lcs (1.1.2)
json (1.5.5)
puppet-lint (0.3.2)
rake (0.8.7)
rspec (1.3.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
rspec-mocks (2.6.0)
rspec-puppet (1.0.1)

my puppet version is PE 3.3.2


Second part

require 'spec_helper'

describe 'test::limits_def'  ,  :type => :define  do

  let :title do

  let(:params) do { :item => 'fsize', :value => 'unlimited'} end

        #it { should contain_class('test::limits_def')}
        it {should  contain_augeas('limits::limit').with(
             'lens' => 'limits.lns',
             'incl' => '/etc/security/limits.conf',
              'changes'  => ['set domain[last()+1] @user,
                   'set domain[last()]/type  soft',
                   'set domain[last()]/item  fsize',
                   'set domain[last()]/value unlimited',
                   'set domain[last()+1] @user,
                   'set domain[last()]/type  hard',
                   'set domain[last()]/item  fsize',
                   'set domain[last()]/value unlimited'])

but there is not "@user soft fsize unlimited" in limit.conf, but I am wondering how my test case pass, because rspec-puppet only test the generated catalog.

if so how come my test is passing without any issue.

edit retag flag offensive close merge delete


try changing

describe 'test::limits_def',  :type => :class  do
describe 'test::limits_def',  :type => :define  do

sfozz gravatar imagesfozz ( 2015-06-12 15:42:16 -0600 )edit

I tried, also added let :title do 'lmits::limit' end, but I am getting "/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- puppet (LoadError) from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'" error

Chutki gravatar imageChutki ( 2015-06-14 12:27:26 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-06-16 04:54:56 -0600

sfozz gravatar image

Your rspec test has the following errors

  1. it should be
    :type => :define
    as you as testing a defined type not a class.
  2. The name of the define doesn't match the name in the manifest.
  3. you haven't defined a title
    let :title do 'test' end 
    which you need otherwise the type won't be called correctly.
  4. The
    won't match unless you set the title above to be the same or visa versa.
edit flag offensive delete link more


I changed whatever changes are required but getting "Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type test::limits_def at line 4 on node # ./spec/defines/limit_def_spec.rb:18" This is line "'set /etc/security/limits.conf/domain/value unlimited'" line it referring

Chutki gravatar imageChutki ( 2015-06-16 06:21:21 -0600 )edit

You have a typo... in the manifest you have

define test::limit_conf
but in your rspec you have
describe 'test::limits_conf'
The names of the defined type don't match....

sfozz gravatar imagesfozz ( 2015-06-16 06:43:39 -0600 )edit

is ther any update on this

Chutki gravatar imageChutki ( 2015-06-17 06:29:51 -0600 )edit

Thanks all for your response, test case is woking. But I have doubt, there is not " test user" in my limit.conf file. Not sure how test case is passing with out any error. I attached my current code in the second part of the initial question due to space issue.

Chutki gravatar imageChutki ( 2015-06-18 04:22:25 -0600 )edit

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: 2015-06-11 06:36:03 -0600

Seen: 420 times

Last updated: Jun 18 '15