Ask Your Question
0

Function 'fail' does not return a value in rspec-puppet

asked 2016-04-27 07:09:48 -0500

Chutki gravatar image

updated 2016-04-28 00:14:14 -0500

Hi,

I have below manifests

class module_name::params {


  $filetype = $::operatingsystemmajrelease ? {
    '5'     => 'ext3',
    '6'     => 'ext4',
    '7'     => 'xfs',
    default => fail("OS release ${::operatingsystemrelease} is not supported.")
}

below is the define class for the module

define module_name::iterate($fssize,$disk) {


  include 'module_name::params'


  $add_disk = inline_template('<%= fssize.to_i + 1 %>')


  if versioncmp("${add_disk}", "${disk}") <= 0 {
    if versioncmp("${add_disk}", '10') < 0 {


      file { "/grid/0${add_disk}" :
        ensure => directory,
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
      }


      filesystem { $::module_name::params::pdisk[$add_disk] :
        ensure  => present,
        fs_type => $::module_name::params::filetype,
        options => $::module_name::params::mkfs_options,
      }
      mount { "hadoopfs${add_disk}" :
        ensure  => mounted,
        name    => "/grid/0${add_disk}",
        device  => $::module_name::params::pdisk[$add_disk],
        filetype  => $::module_name::params::filetype,
        options => 'defaults,noatime',
        atboot  => true,
        dump    => '1',
        pass    => '2',
        require => File["/grid/0${add_disk}"]
      }
 module_name::iterate { "count+${add_disk}":
      fssize => $add_disk,
      disk   => $disk,
    }
  }
}

Rspec-puppet

describe 'module_name::iterate', :type => 'define' do

  let(:pre_condition) { 'include module_name::params' }
  let(:facts) {{ :operatingsystemrelease => '6' }}
  let(:title) { 'osversion' }
  let(:params) do
    {
      '5' => 'ext3',
      '6' => 'ext4',
      '7' => 'xfs',

    }
  end  

  ['01',
   '02',
   '03',
   '04',
   '05',
   '06',
   '07',
   '08',
   '09',
   '010',
   '011',
   '012',
   '013',
   '014',
   '015',
   '016',
   '016',
   '017',
   '018',
   '019',
   '020',
   '021',
   '022',
   '023',
   '024'].each do|value|

     it { should contain_file("/grid/#{value}").with(
        'ensure' => 'directory',
        'owner'  => 'root',
        'group'  => 'root',
        'mode'   => '0755',
      )}
  end
end

when I run rspec-puppet getting below error message

hadoop::recursion  should contain File[/grid/01] with ensure => "directory", owner => "root", group => "root" and mode => "0755"
     Failure/Error: )}
     Puppet::Error:
       Function 'fail' does not return a value at /root/modules/hadoop/spec/fixtures/modules/hadoop/manifests/params.pp:15 on node puppet.example.com
     # ./spec/defines/hadoop_def_spec.rb:381:in `block (4 levels) in <top (required)>'

  2) hadoop::recursion  should contain File[/grid/02] with ensure => "directory", owner => "root", group => "root" and mode => "0755"
     Failure/Error: )}
     Puppet::Error:
       Function 'fail' does not return a value at /root/modules/hadoop/spec/fixtures/modules/hadoop/manifests/params.pp:15 on node puppet.example.com
     # ./spec/defines/hadoop_def_spec.rb:381:in `block (4 levels) in <top (required)>'

The intent of the code is, create disk with recursion.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-04-27 21:50:48 -0500

updated 2016-04-28 05:57:01 -0500

You have a loop in your test:

['01',
'02',
'03',
'04',
'05',
'06',
'07',
'08',
'09',
'010',
'011',
'012',
'013',
'014',
'015',
'016',
'017',
'018',
'019',
'020',
'021',
'022',
'023',
'024'].each do|value,fssize|
...
end

Consider:

irb(main):001:0> ['01', '02', '03', '04'].each do |value,fssize|
irb(main):002:1* puts "got #{value} and #{fssize}"
irb(main):003:1> end
got 01 and 
got 02 and 
got 03 and 
got 04 and 
=> ["01", "02", "03", "04"]

You can't hope to understand Rspec-puppet if you don't put in the time to learn the very basics of Ruby I am afraid.

edit flag offensive delete link more

Comments

I edited my test case, still getting same "Function 'fail' does not return a value at" error. So the problem is with params.pp manifests.

Chutki gravatar imageChutki ( 2016-04-28 00:17:44 -0500 )edit

I got an update from your previous answer https://ask.puppet.com/question/24063/function-fail-does-not-return-a-value/ , but I can't edit the manifests since it was done by someone. so is there any option to accept this default as a selecter in rspec-puppet.

Chutki gravatar imageChutki ( 2016-04-28 00:18:40 -0500 )edit

Let's get this straight. 1) It's your job to test the other team's code with Rspec. 2) Your test showed that the other team's code doesn't work. 3) Now you're asking if there is a way to make your test pass, despite the code under test not working.

Alex Harvey gravatar imageAlex Harvey ( 2016-04-28 05:38:17 -0500 )edit

It may be confronting, but you do need to tell the person who wrote this code that it does not work, and there is no alternative. :)

Alex Harvey gravatar imageAlex Harvey ( 2016-04-28 05:52:23 -0500 )edit

Thanks for an update :)

Chutki gravatar imageChutki ( 2016-04-29 01:12:53 -0500 )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

Stats

Asked: 2016-04-27 07:09:48 -0500

Seen: 112 times

Last updated: Apr 28 '16