Ask Your Question
0

rspec-puppet wont support invoking other class in hiera?

asked 2015-08-20 06:22:13 -0500

Chutki gravatar image

updated 2015-08-20 06:26:42 -0500

Hi,

I am facing an issue when use rspec-puppet for hiera_hash

Below is the first example

class users {

  include users::example1
  }

class users::example1 {

 $abc = {
    'example1' => {
      'ensure'   => 'present',
      'shell'    => '/usr/bin/ksh',
      'home'     => '/home/example1',
      password'  => 'xxxxxxxx',
      'mode'     => '0700',
    }
  }
  create_resources('users::example1',$abc)
}

I wrote rspec for this, please find it below

require 'spec_helper'

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

  it { should contain_class('users::example1')}
end

It is working without any issue

Below is the second example

class env {
      include env::filetype
    }

class env::filetype {

  $tmp = hiera_hash('env::abc')
  create_resources('logical::myfile, $tmp)
}

I am getting below error when I run the manifests

Failures:

  1) env should contain Class[env::filetype]
     Failure/Error: it { should contain_class('env::filetype')}
     Puppet::Error:
       Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type logical::myfile at /etc//puppet/modules/env/spec/fixtures/modules/env/manifests/filetype.pp:7 on node 
     # ./spec/classes/env_spec.rb:5

Finished in 0.20231 seconds

I 1 example, 1 failure

So, my doubt is the rspec-puppet test case hiera will work ony inside the same module, If we invoke any other class to pass data in hiera then it wont support in rspec-puppet.

if it is so, How we can achive that is rspec-puppet

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-08-20 15:12:17 -0500

lavaman gravatar image

If you look at the parser failure, you will see it cannot find logical::myfile. You would need a module named logical in your spec/fixtures/modules directory that contains a defined type called myfile. This is usually achieved by specifying the source of that module in env/.fixtures.yaml and copied into the appropriate location with a spec_prep rake task.

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-08-20 06:22:13 -0500

Seen: 149 times

Last updated: Aug 20 '15