diff --git a/CHANGELOG.md b/CHANGELOG.md index 945cd91..954dd6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org). +## [1.0.1] +### Changed +- tftp class parameters signature to include ensure and enable as parameters. + ## [1.0.0] ### Added - Add puppet 4 and 5 diff --git a/README.md b/README.md index cb8a52a..d346413 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Parameters: * port: bind port, default 69. * options: service option, default --secure. * inetd: run service via xinetd, default true. +* ensure: ensure service state (running) +* enable: define whether the service should start at boot (true) Example: diff --git a/manifests/init.pp b/manifests/init.pp index 029ae70..85541d3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -8,6 +8,8 @@ # [*port*]: tftp service bind port (default 69). # [*options*]: tftp service bind port (default 69). # [*inetd*]: Run as an xinetd service instead of standalone daemon (false) +# [*ensure*]: Ensure service state (running) +# [*enable*]: Define whether the service should start at boot (true) # # Actions: # @@ -18,9 +20,11 @@ # Usage: # # class { 'tftp': -# directory => '/opt/tftp', -# address => $::ipaddress, -# options => '--ipv6 --timeout 60', +# directory => '/opt/tftp', +# address => $::ipaddress, +# options => '--ipv6 --timeout 60', +# ensure => running, +# enable => true, # } # class tftp ( @@ -30,6 +34,8 @@ $port = $tftp::params::port, $options = $tftp::params::options, $inetd = $tftp::params::inetd, + $ensure = $tftp::params::ensure, + $enable = $tftp::params::enable, $package = $tftp::params::package, $binary = $tftp::params::binary, $defaults = $tftp::params::defaults, @@ -73,8 +79,8 @@ $svc_ensure = stopped $svc_enable = false } else { - $svc_ensure = running - $svc_enable = true + $svc_ensure = $ensure + $svc_enable = $enable } $start = $tftp::params::provider ? { diff --git a/manifests/params.pp b/manifests/params.pp index a2b850b..004906e 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -7,6 +7,8 @@ $options = '--secure' $binary = '/usr/sbin/in.tftpd' $inetd = true + $ensure = running + $enable = true case $::osfamily { 'debian': { diff --git a/spec/classes/tftp_spec.rb b/spec/classes/tftp_spec.rb index 60b30e6..e39c284 100644 --- a/spec/classes/tftp_spec.rb +++ b/spec/classes/tftp_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' describe 'tftp', :type => :class do - describe 'when deploying on debian as standalone' do + describe 'when deploying on debian as standalone with default params' do let(:facts) { { :operatingsystem => 'Debian', :osfamily => 'Debian', :path => '/usr/local/bin:/usr/bin:/bin', } } - let(:params) { { :inetd => false, } } + let(:params) { { :inetd => false } } it { should contain_file('/etc/default/tftpd-hpa') should contain_package('tftpd-hpa') @@ -18,7 +18,28 @@ } end - describe 'when deploying on ubuntu 14.04 as standalone' do + + describe 'when deploying on debian as standalone with service disabled' do + let(:facts) { { :operatingsystem => 'Debian', + :osfamily => 'Debian', + :path => '/usr/local/bin:/usr/bin:/bin', } } + + let(:params) { { :inetd => false, :enable => false, :ensure => 'stopped',} } + it { + should contain_file('/etc/default/tftpd-hpa') + should contain_package('tftpd-hpa') + should contain_service('tftpd-hpa').with({ + 'ensure' => 'stopped', + 'enable' => false, + 'hasstatus' => false, + 'provider' => nil, + }) + } + end + + + + describe 'when deploying on ubuntu 14.04 as standalone with default params' do let(:facts) { { :operatingsystem => 'Ubuntu', :osfamily => 'Debian', :operatingsystemrelease => '14.04', @@ -36,7 +57,25 @@ } end - describe 'when deploying on ubuntu 14.10 as standalone' do + describe 'when deploying on ubuntu 14.04 as standalone with service disabled' do + let(:facts) { { :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :operatingsystemrelease => '14.04', + :path => '/usr/local/bin:/usr/bin:/bin', } } + let(:params) { { :inetd => false, :ensure => 'stopped', :enable => false,} } + it { + should contain_package('tftpd-hpa') + should contain_file('/etc/default/tftpd-hpa') + should contain_service('tftpd-hpa').with({ + 'ensure' => 'stopped', + 'enable' => false, + 'hasstatus' => true, + 'provider' => 'upstart', + }) + } + end + + describe 'when deploying on ubuntu 14.10 as standalone with default params' do let(:facts) { { :operatingsystem => 'Ubuntu', :osfamily => 'Debian', :operatingsystemrelease => '14.10', @@ -54,7 +93,25 @@ } end - describe 'when deploying on ubuntu 15.04 or greater as standalone' do + describe 'when deploying on ubuntu 14.10 as standalone with service disabled' do + let(:facts) { { :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :operatingsystemrelease => '14.10', + :path => '/usr/local/bin:/usr/bin:/bin', } } + let(:params) { { :inetd => false, :ensure => 'stopped', :enable => false, } } + it { + should contain_package('tftpd-hpa') + should contain_file('/etc/default/tftpd-hpa') + should contain_service('tftpd-hpa').with({ + 'ensure' => 'stopped', + 'enable' => false, + 'hasstatus' => true, + 'provider' => 'upstart', + }) + } + end + + describe 'when deploying on ubuntu 15.04 or greater as standalone with default params' do let(:facts) { { :operatingsystem => 'Ubuntu', :osfamily => 'Debian', :operatingsystemrelease => '15.04', @@ -72,7 +129,25 @@ } end - describe 'when deploying on ubuntu 16.04 or greater as standalone' do + describe 'when deploying on ubuntu 15.04 or greater as standalone with service disabled' do + let(:facts) { { :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :operatingsystemrelease => '15.04', + :path => '/usr/local/bin:/usr/bin:/bin', } } + let(:params) { { :inetd => false, :ensure => 'stopped', :enable => false, } } + it { + should contain_package('tftpd-hpa') + should contain_file('/etc/default/tftpd-hpa') + should contain_service('tftpd-hpa').with({ + 'ensure' => 'stopped', + 'enable' => false, + 'hasstatus' => true, + 'provider' => 'systemd', + }) + } + end + + describe 'when deploying on ubuntu 16.04 or greater as standalone with default params' do let(:facts) { { :operatingsystem => 'Ubuntu', :osfamily => 'Debian', :operatingsystemrelease => '16.04', @@ -90,6 +165,24 @@ } end + describe 'when deploying on ubuntu 16.04 or greater as standalone with service disabled' do + let(:facts) { { :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', + :operatingsystemrelease => '16.04', + :path => '/usr/local/bin:/usr/bin:/bin', } } + let(:params) { { :inetd => false, :ensure => 'stopped', :enable => false, } } + it { + should contain_package('tftpd-hpa') + should contain_file('/etc/default/tftpd-hpa') + should contain_service('tftpd-hpa').with({ + 'ensure' => 'stopped', + 'enable' => false, + 'hasstatus' => true, + 'provider' => 'systemd', + }) + } + end + describe 'when deploying on redhat family as standalone' do let (:facts) { { :osfamily => 'RedHat', :path => '/usr/local/bin:/usr/bin:/bin', } } @@ -109,6 +202,25 @@ } end + describe 'when deploying on redhat family as standalone with service disabled' do + let (:facts) { { :osfamily => 'RedHat', + :path => '/usr/local/bin:/usr/bin:/bin', } } + let(:params) { { :inetd => false, :ensure => 'stopped', :enable => false, } } + it { + should contain_package('tftpd-hpa').with({ + 'name' => 'tftp-server', + }) + + should contain_service('tftpd-hpa').with({ + 'ensure' => 'stopped', + 'enable' => 'false', + 'hasstatus' => false, + 'provider' => 'base', + 'start' => '/usr/sbin/in.tftpd -l -a 0.0.0.0:69 -u nobody --secure /var/lib/tftpboot', + }) + } + end + describe 'when deploying on redhat family with custom options as standalone' do let (:facts) { { :osfamily => 'RedHat', :path => '/usr/local/bin:/usr/bin:/bin', } }