Ask Your Question
0

rspec-puppet test case calling default value against passing right facts

asked 2016-06-03 05:24:52 -0600

Chutki gravatar image

Below is my param manifests

class module_name::params {

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

below id manifests

class module_name::lvm {

  $flsy = {
    'lv_hpp' => {
      'vg'         => 'vg01',
      'mountpoint' => '/usr/xxx',
      'lvsize'     => '1G',
      'fsowner'    => 'root',
      'fsgroup'    => 'root',
      'fsperms'    => '0755',
      'options'    => 'defaults,noatime',
      'dump'       =>  '0',
      'pass'       =>  '0',
    },
create_resources ('module_name::moddef', $hadfs)
}

below manifests is for define class

define module_name::moddef (
  $vg,
  $mountpoint,
  $lvsize,
  $fsowner,
  $fsgroup,
  $fsperms,
  $options,
  $dump,
  $pass,
  $lv_name = $title,
) {

  include 'module_name::params'


  logical_volume { $lv_name:
    ensure       => present,
    size         => $lvsize,
    volume_group => $vg,
  }
}

I have witten below rspec-puppet test case

describe 'module_name::lvm' do

  let(:facts) {{ :operatingsystemmajrelease => '7', :blockdevices => 'sdb' }}




    it { should contain_hadoop_base__hadlvmdef('lv_hpp')}
  end
end

define type test case

require 'spec_helper'

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

let(:facts) {{ :operatingsystemrelease => '7'}}
let(:pre_condition) { 'include module_name::params'}

flsy = {
    'lv_hpp' => {
      'vg'         => 'vg01',
      'mountpoint' => '/usr/xxx',
      'lvsize'     => '1G',
      'fsowner'    => 'root',
      'fsgroup'    => 'root',
      'fsperms'    => '0755',
      'options'    => 'defaults,noatime',
      'dump'       =>  '0',
      'pass'       =>  '0',
    }
}

flsy .each do|title,value|
    context title do

      let(:title) { title }

      let(:params) {{
        'vg'         => value['vg'],
        'lvsize'     => value['lvsize'],
        'mountpoint' => value['mountpoint'],
        'fsowner'    => value['fsowner'],
        'fsgroup'    => value['fsgroup'],
        'fsperms'    => value['fsperms'],
        'options'    => value['options'],
        'dump'       => value['dump'],
        'pass'       => value['pass']
      }}

      it { should contain_logical_volume(title).with(
        'ensure'       => 'present',
        'size'         => value['lvsize'],
        'volume_group' => value['vg']
      )}
    end
  end
end

when I run test getting below error

Evaluation Error: Error while evaluating a Function Call,  7 is not supported. at /root/modules_new/module_name/spec/fixtures/modules/module_name/manif
ests/params.pp:15:16 on node

My doubt is, why its calling default value. I am passing operatingsystemrelease 7 (:facts) but still why its calling default.

edit retag flag offensive close merge delete

Comments

The params class would fail with a syntax error if that was really your params class. So please update with your actual code.

Alex Harvey gravatar imageAlex Harvey ( 2016-06-06 01:36:51 -0600 )edit

I have just copy pasted the params.pp manifests. I didn't do anything. what I have pasted here is my actual code.

Chutki gravatar imageChutki ( 2016-06-07 02:11:48 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-06-07 03:16:42 -0600

If this was really your code you'd receive a message like this

       error during compilation: Function 'fail' does not return a value at /Users/alexharvey/git/test/spec/fixtures/modules/test/manifests/params.pp:6 on node alexs-macbook-pro.local

This has been pointed out to you before in previous questions; you can't pass in the fail function as a default in a selector.

edit flag offensive delete link more

Comments

No, I got "Evaluation Error: Error while evaluating a Function Call, OS release 7 is not supported. at /root/modules_new/module_name/spec/fixtures/modules/module_name/manifests/params.pp:15:16 on node"

Chutki gravatar imageChutki ( 2016-06-07 05:00:11 -0600 )edit

I am passing :facts os version 7 in my test case but the error seems its picking default value. mu puppet version 2015.3

Chutki gravatar imageChutki ( 2016-06-07 05:01:08 -0600 )edit

One way or another, the params.pp file in your post can't be the one that's actually being used. For a start, your error message says the error's on line 15 of params.pp, but your params.pp above only has 8 lines.

Alex Harvey gravatar imageAlex Harvey ( 2016-06-07 05:17:33 -0600 )edit

I have added few commented line before the class { } in params.pp manifests, but I didn't paste it here. That's the reason it howing line no 15, but the actual error line is " default => fail(" ${::operatingsystemrelease} is not supported.")"

Chutki gravatar imageChutki ( 2016-06-08 02:16:31 -0600 )edit

my test case worked. I used "let(:facts) {{ :operatingsystemrelease => '7'}}" in define test case rather than "operatingsystemmajrelease => '7'" . Thanks Alex for you help on this

Chutki gravatar imageChutki ( 2016-06-08 04:14:18 -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

Stats

Asked: 2016-06-03 05:24:52 -0600

Seen: 81 times

Last updated: Jun 07 '16