Skip to content

Commit

Permalink
Merge pull request #31 from dhollinger/21-pkg-svc-params
Browse files Browse the repository at this point in the history
Add parameters for configuring package and service
  • Loading branch information
wyardley authored Mar 18, 2017
2 parents 5a39d70 + e7fc98f commit 789beb9
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 77 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,25 @@ include autofs
By default this installs and starts the autofs service with the module's default master
file.

Additional granularity will be coming in release 3.0.0
You can also manage the state of the autofs package or service.

By default the module will install the autofs package and start/enable the autofs service.
You can configure this by using the parameters defined in the main init class.

For example, to ensure the package is absent:
```puppet
class { 'autofs':
package_ensure => 'absent',
}
```

To ensure that a service is disabled and not running:
```puppet
class { 'autofs':
service_ensure => 'stopped',
service_enable => false,
}
```


### Map Files
Expand Down
29 changes: 27 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,24 @@
# @author Vox Pupuli <[email protected]>
# @author David Hollinger III <[email protected]>
#
# To use this module, simply declare it in your manifest.
# @example Declaring the autofs class
# include autofs
#
# The module now supports the ability to not only enable autofs,
# but to also disable or uninstall it completely.
# @example Removing the package
# class { 'autofs':
# package_ensure => 'absent',
# }
#
# @example Disable the autofs service
# class { 'autofs':
# service_ensure => 'stopped',
# service_enable => false,
# }
#
#
# @example using hiera with automatic lookup
# ---
# autofs::mounts:
Expand Down Expand Up @@ -44,12 +59,22 @@
# @option mounts [Array] :mapcontents Mount point options and parameters. Each
# array element represents a line in the configuration file.
# @option mounts [Boolean] :replace Enforce the configuration state or not.
# @param package_ensure Determines the state of the package. Can be set to: installed, absent, lastest, or a specific version string.
# @param service_ensure Determines state of the service. Can be set to: running or stopped.
# @param service_enable Determines if the service should start with the system boot. true
# will start the autofs service on boot. false will not start the autofs service
# on boot.
#
class autofs (
Optional[Hash] $mounts = undef
Optional[Hash] $mounts = undef,
String $package_ensure = 'installed',
Enum[ 'stopped', 'running' ] $service_ensure = 'running',
Boolean $service_enable = true,
) {
contain '::autofs::package'
contain '::autofs::service'
unless $package_ensure == 'absent' {
contain '::autofs::service'
}

if $mounts {
$data = hiera_hash('autofs::mounts', $mounts)
Expand Down
9 changes: 4 additions & 5 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#
class autofs::package {
Package {
ensure => installed,
ensure => $autofs::package_ensure,
}
case $::osfamily {
case $facts['os']['family'] {
'Debian', 'Ubuntu': {
package { 'autofs': }
}
Expand All @@ -33,11 +33,10 @@
package { 'autofs': }
}
'Solaris': {
# Solaris includes autofs
# Block to prevent failures
# Already installed in Solaris
}
default: {
fail("${::operatingsystem} not supported.")
fail("${facts['operatingsystem']} not supported.")
}
}
}
24 changes: 5 additions & 19 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,12 @@
# @author Vox Pupuli <[email protected]>
# @author David Hollinger III <[email protected]>
#
# @param ensure Determines state of the service. Can be set to: running or stopped.
# @param enable Determines if the service should start with the system boot. true
# will start the autofs service on boot. false will not start the autofs service
# on boot.
# @param service_restart Determines if the service has a restart command. If true,
# puppet will use the restart command to restart the service. If false, the
# stop, then start commands will be used instead.
# @param service_status Determines if service has a status command.
#
class autofs::service (
String $ensure = running,
Boolean $enable = true,
Boolean $service_restart = true,
Boolean $service_status = true
){
class autofs::service {
service { 'autofs':
ensure => $ensure,
enable => $enable,
hasstatus => $service_status,
hasrestart => $service_restart,
ensure => $autofs::service_ensure,
enable => $autofs::service_enable,
hasstatus => true,
hasrestart => true,
require => Package['autofs'],
}
}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-autofs",
"version": "2.1.2-rc0",
"version": "3.0.0-rc1",
"author": "Vox Pupuli",
"summary": "Module for installing and managing autofs",
"license": "Apache-2.0",
Expand Down
54 changes: 54 additions & 0 deletions spec/acceptance/autofs_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,59 @@ class { 'autofs': }
end
end
end

context 'package set to absent' do
before(:context) do
cleanup_helper
end

it 'applies' do
pp = <<-EOS
class { 'autofs':
package_ensure => 'absent',
}
EOS

apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe package('autofs') do
it { is_expected.not_to be_installed }
end
end

context 'package installed but service disabled' do
before(:context) do
cleanup_helper
end

it 'applies' do
pp = <<-EOS
class { 'autofs':
service_ensure => 'stopped',
service_enable => false,
}
EOS

apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe package('autofs') do
it { is_expected.to be_installed }
end

describe service('autofs') do
it { is_expected.not_to be_running }
end

# Skipped until we can pinpoint why serverspec
# doesn't properly check if an Upstart service
# is enabled or not
describe service('autofs') do
xit { is_expected.not_to be_enabled }
end
end
end
end
48 changes: 29 additions & 19 deletions spec/classes/autofs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,40 @@
describe 'autofs', type: :class do
let(:hiera_config) { 'spec/fixtures/hiera/hiera.yaml' }
hiera = Hiera.new(config: 'spec/fixtures/hiera/hiera.yaml')
opsys = %w(
Debian
Ubuntu
RedHat
CentOS
Suse
)

opsys.each do |os|
context 'main init tests' do
on_supported_os.select { |_, f| f[:os]['family'] != 'Solaris' }.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end

context 'main init tests' do
let(:facts) do
facts.merge(concat_basedir: '/etc')
end
it { is_expected.to compile }
it { is_expected.to contain_class('autofs') }
it { is_expected.to contain_class('autofs::package') }
it { is_expected.to contain_class('autofs::service') }

# Check Package and service
it { is_expected.to contain_package('autofs').with_ensure('installed') }
it { is_expected.to contain_service('autofs').that_requires('Package[autofs]') }
it { is_expected.to contain_service('autofs').with_ensure('running') }
it { is_expected.to contain_service('autofs').with_enable(true) }
end
end

context 'disable package' do
let(:facts) do
facts.merge(concat_basedir: '/etc')
end
let(:params) do
{
osfamily: os.to_s,
concat_basedir: '/etc'
package_ensure: 'absent'
}
end
it { is_expected.to compile }
it { is_expected.to contain_class('autofs') }
it { is_expected.to contain_class('autofs::package') }
it { is_expected.to contain_class('autofs::service') }

# Check Package and service
it { is_expected.to contain_package('autofs').with_ensure('installed') }
it { is_expected.to contain_service('autofs').that_requires('Package[autofs]') }
it { is_expected.to contain_package('autofs').with_ensure('absent') }
end
end

Expand Down
18 changes: 0 additions & 18 deletions spec/classes/package_spec.rb

This file was deleted.

11 changes: 0 additions & 11 deletions spec/classes/service_spec.rb

This file was deleted.

3 changes: 2 additions & 1 deletion spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require 'beaker-rspec/helpers/serverspec'
require 'beaker/puppet_install_helper'

run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no'

RSpec.configure do |c|
# Project root
module_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
Expand All @@ -10,7 +12,6 @@
c.before :suite do
# Install module and deps
hosts.each do |host|
install_puppet_agent_on(hosts, options)
install_dev_puppet_module_on(host, source: module_root, module_name: 'autofs',
target_module_path: '/opt/puppetlabs/puppet/modules')
# Due to RE-6764, running yum update renders the machine unable to install
Expand Down

0 comments on commit 789beb9

Please sign in to comment.