Ask Your Question
0

'100%FREE' value doesn't support by rspec-puppet

asked 2016-05-18 05:07:16 -0500

Chutki gravatar image

Hi,

I have below manifest for lvm

param.pp

 $usr = {
    'lv_puppet' => {
      'vg'         => 'vg_name',
      'mountpoint' => '/opt/puppet/lvm',
      'lvsize'     => '100%FREE',
      'fsowner'    => 'puppuser',
      'fsgroup'    => 'users',
      'fsperms'    => '0775',
      'options'    => 'noatime,nodiratime,discard,errors=remount-ro',
      'dump'       => '0',
      'pass'       => '3',
    }
  }

define class

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

  $fstype = hiera('lvm_fstype')
  $mkfs_options = hiera('lvm_fsoptions')

  Logical_volume[$lv_name] ->
  Filesystem["/dev/${vg}/${lv_name}"] ->
  Mount[$mountpoint]

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

  filesystem { "/dev/${vg}/${lv_name}":
    ensure  => present,
    fs_type => $fstype,
    options => $mkfs_options,
  }

I wrote below rspec-puppet for this

require 'spec_helper'

describe 'puppet_base::lvpuppdef', :type => 'define' do

  let :title do
    'lv_puppet'
  end

  let(:params) do
    { :vg         => 'vg_name',
      :mountpoint => '/opt/puppet/lvm',
      :lvsize     => '100%FREE',
      :fsowner    => 'puppuser',
      :fsgroup    => 'users',
      :fsperms    => '0755',
      :options    => 'noatime,nodiratime,discard,errors=remount-ro',
      :dump       => '0',
      :pass       => '3',
      :lv_name    => 'lv_puppet'
    }
  end

  let(:hiera_config) { 'spec/fixtures/hiera.yaml' }
  hiera = Hiera.new({ :config => 'spec/fixtures/hiera.yaml' })


 tempa = hiera.lookup('lvm_fstype',nil,nil)

tempb = hiera.lookup('lvm_fsoptions',nil,nil)

 it { should contain_logical_volume('lv_puppet').with(
    'ensure'       => 'present',
    'size'         => '100%FREE',
    'volume_group' => 'vg_name'
  )}

  it { should contain_filesystem('/dev/vg_name/lv_puppet').with(
    'ensure'  => 'present',
    'fs_type' => tempa,
    'options' => tempb
  )}

It seems the value '100%FREE' doesn't support by rspec-puppet, when I run the test case getting below error.

Failures:

  1) puppet_base::lvpuppdef should contain Logical_volume[lv_puppet] with ensure => "present", size => "100%FREE" and volume_group => "vg_name"
     Failure/Error:
       it { should contain_logical_volume('lv_puppet').with(
         'ensure'       => 'present',
         'size'         => '100%FREE',
         'volume_group' => 'vg_name'
       )}

       expected that the catalogue would contain Logical_volume[lv_puppet] with size set to "100%FREE" but it is set to nil
     # ./spec/defines/cassandra_def_spec.rb:34:in `block (2 levels) in <top (required)>'

Finished in 2.03 seconds (files took 1.29 seconds to load)
31 examples, 1 failure

Failed examples:

rspec ./spec/defines/cassandra_def_spec.rb:34 # puppet_base::lvpuppdef should contain Logical_volume[lv_puppet] with ensure => "present", size => "100%FREE" and volume_group => "vg_name"

should I pass any hard-code value to run my rspec-puppet test case sine the value '100%FREE' only use in puppet not support by ruby.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-05-21 01:53:53 -0500

updated 2016-05-21 01:55:42 -0500

As far as Ruby is concerned, 100%FREE is just a string so of course it is supported.

The defined type receives a parameter $lvsize and then passes it to the logical_volume's extents parameter:

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

Then your expectation in Rspec that it will contain a logical volume with parameter size set to $lvsize.

You should be saying:

  it { should contain_logical_volume('lv_puppet').with(
    'ensure'       => 'present',
    'extents'      => '100%FREE',
    'volume_group' => 'vg_name'
  )}
edit flag offensive delete link more

Comments

I have installed bundler gem and update the latest rake version and it solved the problem

Chutki gravatar imageChutki ( 2016-05-23 03:50:17 -0500 )edit

It's not possible that changing the Rake version really solved this problem.

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

I update my PE version to 2015.3, but I didn't do any code change.

Chutki gravatar imageChutki ( 2016-05-23 05:49:45 -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-05-18 05:07:16 -0500

Seen: 53 times

Last updated: May 21 '16