diff --git a/.fixtures.yml b/.fixtures.yml index 02128d6..b2ed9fa 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,8 @@ fixtures: repositories: + "common": + repo: "git://github.com/ghoneycutt/puppet-module-common.git" + ref: "v1.0.2" "stdlib": repo: "git://github.com/puppetlabs/puppetlabs-stdlib.git" ref: "3.2.0" diff --git a/.travis.yml b/.travis.yml index 9750670..b594415 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ --- env: -- PUPPET_VERSION=2.7.23 -- PUPPET_VERSION=3.2.4 +- PUPPET_VERSION=2.7.22 +- PUPPET_VERSION=3.3.2 notifications: email: false rvm: @@ -9,7 +9,7 @@ rvm: - 1.8.7 matrix: allow_failures: - - env: PUPPET_VERSION=2.7.23 + - env: PUPPET_VERSION=2.7.22 language: ruby before_script: "gem install --no-ri --no-rdoc bundler" script: 'bundle exec rake validate && bundle exec rake lint && SPEC_OPTS="--format documentation" bundle exec rake spec' diff --git a/Modulefile b/Modulefile index 7ad5bb8..4f4736d 100644 --- a/Modulefile +++ b/Modulefile @@ -8,3 +8,4 @@ description 'Manages NTP server' project_page 'https://github.com/ghoneycutt/puppet-module-ntp' dependency 'puppetlabs/stdlib', '3.2.x' +dependency 'ghoneycutt/common', '>= 1.0.2' diff --git a/README.md b/README.md index 4bd53ae..7b1d1ff 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,30 @@ -# ntp module # +# ntp module +=== + +[![Build Status](https://api.travis-ci.org/ghoneycutt/puppet-module-ntp.png?branch=master)](https://travis-ci.org/ghoneycutt/puppet-module-ntp) Puppet module to manage ntp -# Compatibility # +=== + +# Compatibility + +This module is supported on the following systems with Puppet v3. -This module is supported by the following OS families. + * Debian 6 + * EL 5 + * EL 6 + * Solaris 9 + * Solaris 10 + * Solaris 11 + * Suse 9 + * Suse 10 + * Suse 11 + * Ubuntu 12.04 LTS - * Debian - * Redhat - * Suse 9, 10, 11 - * Solaris 9, 10, 11 +=== -# Parameters # +# Parameters See ntp.conf(5) for more information regarding settings. @@ -50,6 +63,12 @@ ntp.conf's mode - *Default*: 0644 +step_tickers_ensure +------------------- +Ensure step tickers file. Valid values are 'present' and 'absent'. + +- *Default*: based on OS + service_running --------------- If service should be running diff --git a/Rakefile b/Rakefile index f18ea06..6840321 100644 --- a/Rakefile +++ b/Rakefile @@ -6,7 +6,13 @@ PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] desc "Run puppet in noop mode and check for syntax errors." task :validate do - Dir['manifests/**/*.pp'].each do |path| - sh "puppet parser validate --noop #{path}" - end + Dir['manifests/**/*.pp'].each do |path| + sh "puppet parser validate --noop #{path}" + end + Dir['spec/**/*.rb','lib/**/*.rb'].each do |spec_path| + sh "ruby -c #{spec_path}" unless spec_path =~ /spec\/fixtures/ + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end end diff --git a/manifests/init.pp b/manifests/init.pp index 136af39..d0b8b3f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,15 +1,6 @@ -# Class: ntp +# == Class: ntp # -# This module manages the ntp service. -# -# Actions: -# -# Installs, configures, and manages the ntp service. -# -# Requires: -# -# Sample Usage: -# include ntp +# This module manages the ntp service. # class ntp ( $config_file_owner = 'root', @@ -97,40 +88,34 @@ } case $::osfamily { - 'debian': { + 'Debian': { $default_package_name = [ 'ntp' ] $default_package_noop = false $default_package_source = undef $default_package_adminfile = undef + $default_step_tickers_ensure = 'absent' $default_service_name = 'ntp' $default_config_file = '/etc/ntp.conf' $default_driftfile = '/var/lib/ntp/ntp.drift' - - # Verified that Ubuntu does not use /etc/ntp/step-tickers by default. - if $::operatingsystem == 'Ubuntu' { - $step_tickers_enable = false - } else { - $step_tickers_enable = true - } } - 'redhat': { + 'RedHat': { $default_package_name = [ 'ntp' ] $default_package_noop = false $default_package_source = undef $default_package_adminfile = undef + $default_step_tickers_ensure = 'present' $default_service_name = 'ntpd' $default_config_file = '/etc/ntp.conf' $default_driftfile = '/var/lib/ntp/ntp.drift' - $step_tickers_enable = true } - 'suse': { + 'Suse': { $default_package_noop = false $default_package_source = undef $default_package_adminfile = undef + $default_step_tickers_ensure = 'absent' $default_service_name = 'ntp' $default_config_file = '/etc/ntp.conf' $default_driftfile = '/var/lib/ntp/ntp.drift' - $step_tickers_enable = true case $::lsbmajdistrelease { '9','10': { @@ -144,7 +129,7 @@ } } } - 'solaris': { + 'Solaris': { case $::kernelrelease { '5.9','5.10': { $default_package_name = [ 'SUNWntp4r', 'SUNWntp4u' ] @@ -159,13 +144,13 @@ $default_package_noop = true $default_package_source = '/var/spool/pkg' $default_package_adminfile = '/var/sadm/install/admin/puppet-ntp' + $default_step_tickers_ensure = 'absent' $default_service_name = 'ntp4' $default_config_file = '/etc/inet/ntp.conf' $default_driftfile = '/var/ntp/ntp.drift' - $step_tickers_enable = false } default: { - fail("The ntp module is supported by OS Families Debian, Redhat, Suse, and Solaris. Your operatingsystem, ${::operatingsystem}, is part of the osfamily, ${::osfamily}") + fail("The ntp module is supported by OS Families Debian, RedHat, Suse, and Solaris. Your operatingsystem, ${::operatingsystem}, is part of the osfamily, ${::osfamily}") } } @@ -211,29 +196,15 @@ $driftfile_real = $driftfile } - case $step_tickers_enable { - true: { - $default_step_tickers_ensure = present - $step_tickers_owner_real = $step_tickers_owner - $step_tickers_group_real = $step_tickers_group - $step_tickers_mode_real = $step_tickers_mode - } - false: { - $default_step_tickers_ensure = absent - $step_tickers_owner_real = undef - $step_tickers_group_real = undef - $step_tickers_mode_real = undef - } - default: { - fail("step_tickers_enable must be true or false. Current value is ${step_tickers_enable}") - } - } - if $step_tickers_ensure == 'USE_DEFAULTS' { $step_tickers_ensure_real = $default_step_tickers_ensure } else { $step_tickers_ensure_real = $step_tickers_ensure } + validate_re($step_tickers_ensure_real, '^(present)|(absent)$', + "ntp::step_tickers_ensure must be 'present' or 'absent'. Detected value is <${step_tickers_ensure_real}>.") + + validate_absolute_path($step_tickers_path) # validate $my_enable_stats - must be true or false case $my_enable_stats { @@ -275,14 +246,21 @@ require => Package['ntp_package'], } - file { 'step-tickers': - ensure => $step_tickers_ensure_real, - path => $step_tickers_path, - owner => $step_tickers_owner_real, - group => $step_tickers_group_real, - mode => $step_tickers_mode_real, - content => template('ntp/step-tickers.erb'), - require => Package['ntp_package'], + if $step_tickers_ensure_real == 'present' { + + common::mkdir_p { $step_tickers_path: } + + file { 'step-tickers': + ensure => $step_tickers_ensure_real, + path => $step_tickers_path, + owner => $step_tickers_owner, + group => $step_tickers_group, + mode => $step_tickers_mode, + content => template('ntp/step-tickers.erb'), + require => [ Package['ntp_package'], + Common::Mkdir_p[$step_tickers_path], + ], + } } service { 'ntp_service': diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index b49a3b5..12f18f5 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -30,15 +30,7 @@ it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } - it { - should contain_file('step-tickers').with({ - 'ensure' => 'present', - 'path' => '/etc/ntp/step-tickers', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) - } + it { should_not contain_file('step-tickers') } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } @@ -70,12 +62,7 @@ }) } - it { - should contain_file('step-tickers').with({ - 'ensure' => 'absent', - 'path' => '/etc/ntp/step-tickers', - }) - } + it { should_not contain_file('step-tickers') } it { should contain_file('ntp_conf').with({ @@ -137,6 +124,13 @@ it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } + it { + should contain_exec('mkdir_p-/etc/ntp/step-tickers').with({ + 'command' => 'mkdir -p /etc/ntp/step-tickers', + 'unless' => 'test -d /etc/ntp/step-tickers', + }) + } + it { should contain_file('step-tickers').with({ 'ensure' => 'present', @@ -144,6 +138,7 @@ 'owner' => 'root', 'group' => 'root', 'mode' => '0644', + 'require' => [ 'Package[ntp_package]', 'Common::Mkdir_p[/etc/ntp/step-tickers]' ], }) } @@ -177,12 +172,7 @@ }) } - it { - should contain_file('step-tickers').with({ - 'ensure' => 'absent', - 'path' => '/etc/ntp/step-tickers', - }) - } + it { should_not contain_file('step-tickers') } it { should contain_file('ntp_conf').with({ @@ -237,12 +227,7 @@ }) } - it { - should contain_file('step-tickers').with({ - 'ensure' => 'absent', - 'path' => '/etc/ntp/step-tickers', - }) - } + it { should_not contain_file('step-tickers') } it { should contain_file('ntp_conf').with({ @@ -289,12 +274,7 @@ }) } - it { - should contain_file('step-tickers').with({ - 'ensure' => 'absent', - 'path' => '/etc/ntp/step-tickers', - }) - } + it { should_not contain_file('step-tickers') } it { should contain_file('ntp_conf').with({ @@ -362,15 +342,7 @@ it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } - it { - should contain_file('step-tickers').with({ - 'ensure' => 'present', - 'path' => '/etc/ntp/step-tickers', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) - } + it { should_not contain_file('step-tickers') } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } @@ -417,15 +389,7 @@ it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } - it { - should contain_file('step-tickers').with({ - 'ensure' => 'present', - 'path' => '/etc/ntp/step-tickers', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) - } + it { should_not contain_file('step-tickers') } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } @@ -472,15 +436,7 @@ it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) } - it { - should contain_file('step-tickers').with({ - 'ensure' => 'present', - 'path' => '/etc/ntp/step-tickers', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - }) - } + it { should_not contain_file('step-tickers') } it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) } @@ -523,7 +479,29 @@ it do expect { should include_class('ntp') - }.to raise_error(Puppet::Error,/The ntp module is supported by OS Families Debian, Redhat, Suse, and Solaris./) + }.to raise_error(Puppet::Error,/The ntp module is supported by OS Families Debian, RedHat, Suse, and Solaris./) + end + end + + context 'with invalid value for step_tickers_ensure param' do + let(:params) { { :step_tickers_ensure => 'invalid' } } + let(:facts) { { :osfamily => 'RedHat' } } + + it do + expect { + should include_class('ntp') + }.to raise_error(Puppet::Error,/ntp::step_tickers_ensure must be 'present' or 'absent'. Detected value is ./) + end + end + + context 'with invalid path for step_tickers_path param' do + let(:params) { { :step_tickers_path => 'invalid/path' } } + let(:facts) { { :osfamily => 'RedHat' } } + + it do + expect { + should include_class('ntp') + }.to raise_error(Puppet::Error) end end end