Ask Your Question
0

Failure/Error: should create_class

asked 2015-05-17 07:31:54 -0500

kemra102 gravatar image

updated 2015-05-20 18:10:39 -0500

I am trying to run some rspec tests and I am getting the following error:

Failures:

  1) auditd when called with no parameters on RedHat 7 
     Failure/Error: should create_class('auditd')
     Puppet::Error:
       Could not find class auditd for iacon.cybertron.local on node iacon.cybertron.local

The spec/classes/init_spec.rb in question (my only test):

require 'spec_helper'
describe 'auditd', :type => :class do
  describe 'when called with no parameters on RedHat 7' do
    let (:facts) {{
      :osfamily               => 'RedHat',
      :operatingsystemrelease => '7',
    }}
    it {
      should create_class('auditd')
      should contain_package('audit').with({
        'ensure' => 'present',
      })
      should contain_file('/etc/audit/auditd.conf').with({
        'ensure' => 'file',
        'owner'  => 'root',
        'group'  => 'root',
        'mode'   => '0640',
      })
      should contain_file('/etc/audit/audit.rules').with({
        'ensure' => 'file',
        'owner'  => 'root',
        'group'  => 'root',
        'mode'   => '0640',
      })
      should contain_service('auditd').with({
        'ensure'    => 'running',
        'enable'    => 'true',
        'hasstatus' => 'true',
        'restart'   => '/usr/libexec/initscripts/legacy-actions/auditd/restart',
        'stop'      => '/usr/libexec/initscripts/legacy-actions/auditd/stop',
      })
    }
  end
end

The class name for the module is correct so I don't understand why I'm getting this error.

EDITED TO ANSWER QUESTIONS

Originally I copied the testing set-up of this module, as I'd seen the author sucessfully run the tests. I did re-do the test set-up as per the rspec-puppet instructions using both the manual and the automatic instructions but both produced the same errors.

The directory layout (following the automated rspec-puppet method) currently looks like this:

.
├── CHANGELOG
├── Gemfile
├── Gemfile.lock
├── LICENSE
├── manifests
│   ├── init.pp
│   └── params.pp
├── metadata.json
├── Rakefile
├── README.md
├── spec
│   ├── classes
│   │   └── init_spec.rb
│   ├── defines
│   ├── fixtures
│   │   ├── manifests
│   │   │   └── site.pp
│   │   └── modules
│   │       └── auditd
│   │           ├── manifests -> ../../../../manifests
│   │           └── templates -> ../../../../templates
│   ├── functions
│   ├── hosts
│   └── spec_helper.rb
├── templates
│   ├── auditd.conf.erb
│   └── audit.rules.erb
└── tests
    └── init.pp

The code itself (minus the testing stuff) can be found here.

edit retag flag offensive close merge delete

Comments

1

Do you get the same result if you remove the "should contain_*" checks and leave the "should create_class" test? It might make sense to boil it down to the simplest test case and enable debug as shown here: http://www.ruempler.eu/2012/04/03/puppet-rspec-debugging/. Please post output of that again.

GregLarkin gravatar imageGregLarkin ( 2015-05-19 17:43:13 -0500 )edit

Glad to hear it's working! It looks like the difference between the current code and your original version is the addition of the "context" line. Not sure what that does exactly, but if it works, great! :) Here is some more info: http://betterspecs.org/#contexts

GregLarkin gravatar imageGregLarkin ( 2015-05-20 17:47:37 -0500 )edit

If you want, convert the end of your question to an answer of your own, and I'll mark it correct for you. You found the solution, so you deserve the karma!

GregLarkin gravatar imageGregLarkin ( 2015-05-20 17:53:53 -0500 )edit

Thanks for all the assistance and the links, some very useful stuff there.

kemra102 gravatar imagekemra102 ( 2015-05-20 18:11:31 -0500 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2015-05-20 18:10:50 -0500

kemra102 gravatar image

Stripping the test back down to the basics:

require 'spec_helper'
  describe 'auditd', :type => :class do
    context 'with defaults for all parameters' do
      let (:facts) {{
        :osfamily               => 'RedHat',
        :operatingsystemrelease => '7',
      }}
      it { should contain_class('auditd') }
    end
end

and following the instructions on this Puppetlabs blog post made the basic test pass! Adding the other criteria back in also kept the test passing so all is well!

edit flag offensive delete link more
1

answered 2015-05-18 18:26:26 -0500

GregLarkin gravatar image

Do you have the rspec configuration set up correcly according to: http://rspec-puppet.com/setup/? Also, what is the structure of your module (directory names, file names, class names within those files, etc.)?

Anything that is not quite right with one of those items could cause the error that you see. Please post back with any further details.

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

Stats

Asked: 2015-05-17 07:31:54 -0500

Seen: 304 times

Last updated: May 20 '15