Skip to content

Commit

Permalink
- Added Puppet 4 types for all parameters.
Browse files Browse the repository at this point in the history
- Added `rspec-puppet-facts` to run tests on all supported os versions.
- Updated puppet and dependency versions for the module.
  • Loading branch information
rehanone committed May 5, 2018
1 parent 501f765 commit 3172471
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 215 deletions.
5 changes: 3 additions & 2 deletions manifests/config.pp
@@ -1,10 +1,11 @@
#
class autofs::config inherits autofs {

autofs::mapfile { $autofs::master_config:
directory => undef,
}

create_resources('autofs::includes', $autofs::includes)
create_resources('autofs::include', $autofs::includes)
create_resources('autofs::mapfile', $autofs::mapfiles)
create_resources('autofs::mount', $autofs::mounts)
}
}
11 changes: 6 additions & 5 deletions manifests/include.pp
@@ -1,16 +1,17 @@
define autofs::include(
$mapfile = $name,
$order = undef
#
define autofs::include (
String $mapfile = $name,
Optional[String] $order = undef
) {
include ::autofs

if $mapfile == $autofs::master_config {
fail("${autofs::mapfile_config_dir}/${autofs::master_config} can't include itself!")
fail("${autofs::map_config_dir}/${autofs::master_config} can't include itself!")
}

concat::fragment { "${autofs::master_config}/${mapfile}":
target => $autofs::master_config,
content => "+${mapfile}",
order => $order;
}
}
}
54 changes: 21 additions & 33 deletions manifests/init.pp
@@ -1,38 +1,26 @@
# == Define: autofs
# Class: autofs

class autofs(
$config_file_owner = $autofs::params::config_file_owner,
$config_file_group = $autofs::params::config_file_group,
$master_config = $autofs::params::master_config,
$map_config_dir = $autofs::params::map_config_dir,
$package_manage = $autofs::params::package_manage,
$package_name = $autofs::params::package_name,
$package_ensure = $autofs::params::package_ensure,
$service_name = $autofs::params::service_name,
$service_manage = $autofs::params::service_manage,
$service_hasrestart = $autofs::params::service_hasrestart,
$service_hasstatus = $autofs::params::service_hasstatus,
$service_ensure = $autofs::params::service_ensure,
$service_enable = $autofs::params::service_enable,
$service_restart = $autofs::params::service_restart,
$mapfiles = {},
$mounts = {},
$includes = {},
class autofs (
String $config_file_owner = $autofs::params::config_file_owner,
String $config_file_group = $autofs::params::config_file_group,
String $master_config = $autofs::params::master_config,
Stdlib::Absolutepath
$map_config_dir = $autofs::params::map_config_dir,
Boolean $package_manage = $autofs::params::package_manage,
Array[String] $package_name = $autofs::params::package_name,
String $package_ensure = $autofs::params::package_ensure,
String $service_name = $autofs::params::service_name,
Boolean $service_manage = $autofs::params::service_manage,
Boolean $service_hasrestart = $autofs::params::service_hasrestart,
Boolean $service_hasstatus = $autofs::params::service_hasstatus,
Variant[Enum[running, stopped], Boolean]
$service_ensure = $autofs::params::service_ensure,
Boolean $service_enable = $autofs::params::service_enable,
Optional[String] $service_restart = $autofs::params::service_restart,
Hash $mapfiles = lookup('autofs::mapfiles', Hash, 'hash', {}),
Hash $mounts = lookup('autofs::mounts', Hash, 'hash', {}),
Hash $includes = lookup('autofs::includes', Hash, 'hash', {}),
) inherits autofs::params {
validate_string($master_config)
validate_absolute_path($map_config_dir)
validate_bool($package_manage)
validate_string($package_ensure)
validate_string($service_name)
validate_bool($service_manage)
validate_bool($service_hasrestart)
validate_bool($service_hasstatus)
validate_string($service_ensure)
validate_bool($service_enable)
validate_string($service_restart)
validate_hash($mapfiles)
validate_hash($mounts)
validate_hash($includes)

# Anchor this as per #8040 - this ensures that classes won't float off and
# mess everything up. You can read about this at:
Expand Down
2 changes: 1 addition & 1 deletion manifests/install.pp
Expand Up @@ -6,4 +6,4 @@
ensure => $autofs::package_ensure,
}
}
}
}
41 changes: 13 additions & 28 deletions manifests/mapfile.pp
@@ -1,42 +1,26 @@
#
define autofs::mapfile(
$directory,
$ensure = present,
$mapfile = $name,
$options = undef,
$order = undef,
$maptype = 'file' ,
$mounts = {}
define autofs::mapfile (
Optional[Stdlib::Absolutepath] $directory,
Enum[present, absent, purged] $ensure = present,
String $mapfile = $name,
Optional[String] $options = undef,
Optional[String] $order = undef,
Enum[file, program, yp, nisplus, hesiod, ldap, ldaps]
$maptype = file,
Hash $mounts = {}
) {

include ::autofs

validate_string($mapfile)
validate_string($options)
validate_hash($mounts)

validate_re($ensure, '^present$|^absent$|^purged$', 'ensure must be one of: present, absent, or purged')

# surround $supported_map_types list items with ^...$ for regular expression matching
$supported_map_types_re = regsubst($::autofs::supported_map_types, '^.*$', '^\0$')
# join $supported_map_types list with commas, put an 'or' before the
# last supported type, and remove the comma if only two items in list.
$supported_map_types_str = regsubst(regsubst(join($::autofs::supported_map_types, ', '), ', ([^,]*)$', ', or \1'), '^([^,]*),( or [^,]*)$', '\1\2')
# check $maptype is valid
validate_re($maptype, $supported_map_types_re, "maptype must be one of: ${supported_map_types_str}")

# $mapfile_prefix is equal to "${maptype}:", _unless_:
# 1) $maptype == 'file'
# 2) $use_map_prefix is false
if $maptype != 'file' and $::autofs::use_map_prefix {
if $maptype != file and $::autofs::use_map_prefix {
$mapfile_prefix = "${maptype}:"
} else {
$mapfile_prefix = ''
}

if $mapfile != $autofs::master_config {
validate_absolute_path($directory)

if $mapfile != $autofs::master_config and $directory != undef {
if $ensure == present {
concat::fragment { "${autofs::master_config}/${mapfile}":
target => $autofs::master_config,
Expand All @@ -59,7 +43,7 @@
}

# Only create the mapfile and any mounts if $maptype == file
if $maptype == 'file' {
if $maptype == file {
concat { $mapfile:
ensure => $concat_ensure,
owner => $autofs::config_file_owner,
Expand All @@ -77,3 +61,4 @@
})
}
}

24 changes: 8 additions & 16 deletions manifests/mount.pp
@@ -1,24 +1,16 @@
#
define autofs::mount(
$mapfile,
$map,
$mount = $name,
$ensure = 'present',
$options = '-rw',
$order = undef,
String $mapfile,
String $map,
String $mount = $name,
Enum[present, absent] $ensure = present,
Autofs::MountOptions $options = '-rw',
Optional[String] $order = undef,
) {
validate_string($mapfile)
validate_string($map)
validate_string($mount)
validate_string($options)

validate_re($ensure, '^present$|^absent$', 'ensure must be one of: present or absen')
validate_re($options, '^-', 'options must start with a hypen')

include ::autofs

if $mapfile == $autofs::master_config {
fail("You can't add mounts directly to ${autofs::mapfile_config_dir}/${autofs::master_config}!")
fail("You can't add mounts directly to ${autofs::map_config_dir}/${autofs::master_config}!")
}

if $ensure == 'present' {
Expand All @@ -28,4 +20,4 @@
order => $order;
}
}
}
}
5 changes: 1 addition & 4 deletions manifests/service.pp
@@ -1,8 +1,5 @@
#
class autofs::service inherits autofs {
if ! ($autofs::service_ensure in [ 'running', 'stopped' ]) {
fail('service_ensure parameter must be running or stopped')
}

if $autofs::service_manage == true {
service { 'autofs':
Expand All @@ -14,4 +11,4 @@
restart => $autofs::service_restart;
}
}
}
}
6 changes: 3 additions & 3 deletions metadata.json
Expand Up @@ -10,11 +10,11 @@
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 3.0.0 < 5.0.0"
"version_requirement": ">= 4.0.0 < 5.0.0"
},
{
"name": "puppetlabs/concat",
"version_requirement": ">= 1.0.4 < 3.0.0"
"version_requirement": ">= 4.0.0 < 5.0.0"
}
],
"operatingsystem_support": [
Expand Down Expand Up @@ -76,7 +76,7 @@
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 3.2.0 < 5.0.0"
"version_requirement": ">= 4.7.0 < 6.0.0"
}
],
"tags": [
Expand Down
39 changes: 23 additions & 16 deletions spec/defines/resource_include_spec.rb
@@ -1,25 +1,32 @@
require 'spec_helper'

describe 'autofs::include' do
let(:title) { 'auto.include' }
let(:facts) { { osfamily: 'RedHat', concat_basedir: '/mock_dir' } }
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

describe 'testing class' do
it { is_expected.not_to raise_error }
it do
is_expected.to contain_concat__fragment('auto.master/auto.include')
.with_content(%r{\+auto\.include})
end
end
let(:title) { 'auto.include' }

describe 'testing class' do
it { is_expected.not_to raise_error }
it do
is_expected.to contain_concat__fragment('auto.master/auto.include')
.with_content(%r{\+auto\.include})
end
end

describe 'testing all parameters' do
let(:params) { { mapfile: 'auto.foo', order: '5' } }
describe 'testing all parameters' do
let(:params) { { mapfile: 'auto.foo', order: '5' } }

it { is_expected.not_to raise_error }
it do
is_expected.to contain_concat__fragment('auto.master/auto.foo')
.with_content(%r{\+auto\.foo})
.with_order('5')
it { is_expected.not_to raise_error }
it do
is_expected.to contain_concat__fragment('auto.master/auto.foo')
.with_content(%r{\+auto\.foo})
.with_order('5')
end
end
end
end
end

0 comments on commit 3172471

Please sign in to comment.