Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters for configuring package and service #31

Merged
merged 24 commits into from
Mar 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7634c24
Add package/service params and docs
dhollinger Mar 13, 2017
9cc8e25
Add examples for new parameters
dhollinger Mar 13, 2017
9265d28
Update ensure attribute for global package resource
dhollinger Mar 13, 2017
ad31fb8
Update autofs service to reference new parameters
dhollinger Mar 13, 2017
344899c
Move tests to autofs_spec
dhollinger Mar 14, 2017
f8749fc
Remove hasstatus and hasrestart parameters
dhollinger Mar 14, 2017
2308621
Update fact calls to lookup via the facts hash
dhollinger Mar 14, 2017
bb7a462
Update version to 3.0.0-rc1
dhollinger Mar 14, 2017
c6f9396
Update package class to use structure facts
dhollinger Mar 14, 2017
c620d5d
Update tests to use rspec-puppet-facts
dhollinger Mar 14, 2017
b7bef68
Add Solaris back to supported OSes
dhollinger Mar 14, 2017
2e56a06
Update tests to work with Solaris
dhollinger Mar 14, 2017
20d1951
Add README content related to the new parameters
dhollinger Mar 14, 2017
4567a53
Add logic to account for an absent package
dhollinger Mar 17, 2017
3490e69
Add tests to account for new parameters
dhollinger Mar 17, 2017
9bbab1b
Fix rubocop failures
dhollinger Mar 17, 2017
c32427a
Remove service disabled test until we know why it fails on ubuntu1404
dhollinger Mar 17, 2017
60396db
Merge branch '21-pkg-svc-params' of github.com:dhollinger/puppet-auto…
dhollinger Mar 17, 2017
278bd58
Add skip to the service disable test until it can be fixed
dhollinger Mar 17, 2017
0b63021
Fix rubocop errors (again)
dhollinger Mar 17, 2017
18dca69
Add code to use beaker-puppet_install_helper
dhollinger Mar 17, 2017
4821c03
Add and skip the service enable check
dhollinger Mar 17, 2017
473ff62
Another rubocop fix
dhollinger Mar 17, 2017
e7fc98f
Add Solaris support back into package class
dhollinger Mar 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_, f
what kind of magic is this

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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do compile.with_all_deps?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eep, sorry @bastelfreak, saw that it was approved and @dhollinger had asked for a merge earlier in the day; didn't see that these comments were so recent.

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