Skip to content

Instantly share code, notes, and snippets.

@dhollinger
Created October 3, 2016 18:41
Show Gist options
  • Save dhollinger/f6a351568260fc512ae188b981a7082f to your computer and use it in GitHub Desktop.
Save dhollinger/f6a351568260fc512ae188b981a7082f to your computer and use it in GitHub Desktop.
Puppet Test Error and source
autofs::mount with default parameters should contain Concat[/etc/auto.master]
Failure/Error: raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}")
Puppet::PreformattedError:
Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, nil is not a string. It looks to be a NilClass at /home/travis/build/dhollinger/autofs-puppet/spec/fixtures/modules/concat/manifests/init.pp:99:3 at /home/travis/build/dhollinger/autofs-puppet/spec/fixtures/modules/autofs/manifests/mount.pp:66 on node testing-worker-linux-docker-2a0050d2-3408-linux-5.prod.travis-ci.org
# == Define: autofs::mount
#
# Define to generate autofs mount point
# configuration files.
#
# === Parameters
# [*mount*]
# Location where you will mount the remote
# NFS Share.
#
# [*mapfile*]
# Name of the "auto." file that will be generated
#
# [*mapcontents*]
# The mount point options and parameters,
# Example: '* -user,rw,soft server.example.com:/path/to/home/shares'
#
# [*options*]
# Options for the autofs mount point within in the auto.master
#
# [*order*]
# Order in which entries will appear in the autofs master file.
#
# [*direct*]
# Boolean to allow for indirect map. Defaults to true to be backwards compatible.
#
# [*execute*]
# Boolean to set the map to be executable. Defaults to false to be backward compatible.
#
# [*replace*]
# Boolean to set the map file to not be replaced. Defaults to true as Puppet File resource does.
#
# These Parameters can be set statically, within an ENC, or by using Hiera.
# See README Docs for Examples.
#
define autofs::mount (
$mount,
$order,
$options = '',
$master = '/etc/auto.master',
$map_dir = '/etc/auto.master.d',
$use_dir = false,
$direct = true,
$execute = false,
$mapfile = undef,
$mapcontents = undef,
$replace = true
) {
if $mapfile {
$contents = "${mount} ${mapfile} ${options}\n"
} else {
$contents = "${mount} ${options}\n"
}
if $execute {
$mapperms = '0755'
$maptempl = 'autofs/auto.map.exec.erb'
}
else {
$mapperms = '0644'
$maptempl = 'autofs/auto.map.erb'
}
if !defined(Concat[$master]) {
concat { $master:
owner => 'root',
group => 'root',
mode => '0644',
ensure_newline => true,
notify => Service[ 'autofs' ],
}
}
if $use_dir == false {
concat::fragment { "autofs::fragment preamble ${mount} ${mapfile}":
target => $master,
content => $contents,
order => $order,
}
} else {
ensure_resource('file', $map_dir, {
'ensure' => 'directory',
'owner' => 'root',
'group' => 'root',
'mode' => '0755',
})
if !defined(Concat::Fragment['autofs::fragment preamble map directory']) {
concat::fragment { 'autofs::fragment preamble map directory':
target => $master,
content => "+dir:${map_dir}",
order => $order,
require => File[ $map_dir ],
}
}
file { "${map_dir}/${name}.autofs":
ensure => present,
owner => 'root',
group => 'root',
mode => $mapperms,
content => $contents,
require => File[ $map_dir ],
notify => Service[ 'autofs' ],
}
}
if $mapfile {
file { $mapfile:
ensure => present,
owner => 'root',
group => 'root',
mode => $mapperms,
replace => $replace,
content => template($maptempl),
require => Package[ 'autofs' ],
notify => Service[ 'autofs' ],
}
}
}
require 'spec_helper'
describe 'autofs::mount', :type => :define do
let(:title) { 'auto.home' }
let(:facts) do
{
:concat_basedir => '/etc'
}
end
let(:params) do
{
:mount => '/home',
:mapfile => '/etc/auto.home',
:mapcontents => %W( test foo bar ),
:options => '--timeout=120',
:order => '01',
:master => '/etc/auto.master'
}
end
context 'with default parameters' do
it do
should contain_concat('/etc/auto.master')
should contain_concat__fragment('autofs::fragment preamble /home /etc/auto.home').with('target' => '/etc/auto.master')
end
it do
should contain_file('/etc/auto.home').with(
'ensure' => 'present',
'owner' => 'root',
'group' => 'root',
'mode' => '0644'
)
end
end
context 'with indirect map' do
let(:params) do
{
:mount => '/home',
:mapfile => '/etc/auto.home',
:mapcontents => %W( test foo bar ),
:options => '--timeout=120',
:order => '01',
:direct => false
}
end
it do
should_not contain_file('/home').with('ensure' => 'directory')
end
end
context 'with direct map' do
let(:params) do
{
:mount => '/-',
:mapfile => '/etc/auto.home',
:mapcontents => [ '/home /test', '/home /foo', '/home /bar'],
:options => '--timeout=120',
:order => '01',
:direct => true
}
end
it do
should contain_concat__fragment('autofs::fragment preamble /- /etc/auto.home')
end
end
context 'with EL7 directory' do
let(:params) do
{
:name => 'home',
:mount => '/home',
:mapfile => '/etc/auto.home',
:mapcontents => %W( test foo bar ),
:options => '--timeout=120',
:order => '01',
:map_dir => '/etc/auto.master.d',
:use_dir => true
}
end
it do
should contain_concat__fragment('autofs::fragment preamble map directory')
end
it do
should contain_file('/etc/auto.master.d').with(
'ensure' => 'directory',
'owner' => 'root',
'group' => 'root',
'mode' => '0755'
)
should contain_file('/etc/auto.master.d/home.autofs').with(
'ensure' => 'present',
'owner' => 'root',
'group' => 'root',
'mode' => '0644'
)
should contain_file('/etc/auto.home').with(
'ensure' => 'present',
'owner' => 'root',
'group' => 'root',
'mode' => '0644'
)
end
end
context 'with executable map' do
let (:params) do
{
:mount => '/home',
:mapfile => '/etc/auto.home',
:mapcontents => %W( test foo bar ),
:options => '--timeout=120',
:order => '01',
:execute => true
}
end
it do
should contain_file('/etc/auto.home').with('mode' => '0755')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment