From 819cf1d534a22d63489c653640be334bf9182922 Mon Sep 17 00:00:00 2001 From: Justin Stoller Date: Mon, 28 Jul 2014 16:08:56 -0700 Subject: [PATCH 1/6] ntp is not supported on osx --- spec/spec_helper_acceptance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 88bc3b03..68d4e737 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,6 +1,6 @@ require 'beaker-rspec' -UNSUPPORTED_PLATFORMS = [ 'windows' ] +UNSUPPORTED_PLATFORMS = [ 'windows', 'Darwin' ] unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' if hosts.first.is_pe? From c0029a41182f9447c142a9fd06e95b508b912a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20S=C3=A9hier?= Date: Thu, 31 Jul 2014 10:32:00 +0200 Subject: [PATCH 2/6] fix for strict_variable and tests --- manifests/params.pp | 1 + spec/classes/ntp_spec.rb | 67 +++++++++++++++++++++++++++++----------- spec/spec_helper.rb | 27 ++++++++++++++++ 3 files changed, 77 insertions(+), 18 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 25e8c826..3acaa914 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -7,6 +7,7 @@ $keys_controlkey = '' $keys_requestkey = '' $keys_trusted = [] + $logfile = undef $package_ensure = 'present' $preferred_servers = [] $service_enable = true diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index c367aef8..2b9d56d4 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -1,12 +1,18 @@ require 'spec_helper' describe 'ntp' do + let(:facts) {{ :is_virtual => 'false' }} ['Debian', 'RedHat','SuSE', 'FreeBSD', 'Archlinux', 'Gentoo', 'Gentoo (Facter < 1.7)'].each do |system| + context "when on system #{system}" do if system == 'Gentoo (Facter < 1.7)' - let(:facts) {{ :osfamily => 'Linux', :operatingsystem => 'Gentoo' }} + let :facts do + super().merge({ :osfamily => 'Linux', :operatingsystem => 'Gentoo' }) + end else - let(:facts) {{ :osfamily => system }} + let :facts do + super().merge({ :osfamily => system }) + end end it { should contain_class('ntp::install') } @@ -202,11 +208,14 @@ end end end + end #context when on system context 'ntp::config' do describe "for operating system Gentoo (Facter < 1.7)" do - let(:facts) {{ :operatingsystem => 'Gentoo', - :osfamily => 'Linux' }} + let :facts do + super().merge({ :operatingsystem => 'Gentoo', + :osfamily => 'Linux' }) + end it 'uses the NTP pool servers by default' do should contain_file('/etc/ntp.conf').with({ @@ -216,7 +225,9 @@ end describe "on osfamily Gentoo" do - let(:facts) {{ :osfamily => 'Gentoo' }} + let :facts do + super().merge({ :osfamily => 'Gentoo' }) + end it 'uses the NTP pool servers by default' do should contain_file('/etc/ntp.conf').with({ @@ -226,7 +237,9 @@ end describe "on osfamily Debian" do - let(:facts) {{ :osfamily => 'debian' }} + let :facts do + super().merge({ :osfamily => 'debian' }) + end it 'uses the debian ntp servers by default' do should contain_file('/etc/ntp.conf').with({ @@ -236,7 +249,9 @@ end describe "on osfamily RedHat" do - let(:facts) {{ :osfamily => 'RedHat' }} + let :facts do + super().merge({ :osfamily => 'RedHat' }) + end it 'uses the redhat ntp servers by default' do should contain_file('/etc/ntp.conf').with({ @@ -246,7 +261,9 @@ end describe "on osfamily SuSE" do - let(:facts) {{ :osfamily => 'SuSE' }} + let :facts do + super().merge({ :osfamily => 'SuSE' }) + end it 'uses the opensuse ntp servers by default' do should contain_file('/etc/ntp.conf').with({ @@ -256,7 +273,9 @@ end describe "on osfamily FreeBSD" do - let(:facts) {{ :osfamily => 'FreeBSD' }} + let :facts do + super().merge({ :osfamily => 'FreeBSD' }) + end it 'uses the freebsd ntp servers by default' do should contain_file('/etc/ntp.conf').with({ @@ -266,7 +285,9 @@ end describe "on osfamily ArchLinux" do - let(:facts) {{ :osfamily => 'ArchLinux' }} + let :facts do + super().merge({ :osfamily => 'ArchLinux' }) + end it 'uses the NTP pool servers by default' do should contain_file('/etc/ntp.conf').with({ @@ -276,7 +297,9 @@ end describe "on osfamily Solaris and operatingsystemrelease 5.10" do - let(:facts) {{ :osfamily => 'Solaris', :operatingsystemrelease => '5.10' }} + let :facts do + super().merge({ :osfamily => 'Solaris', :operatingsystemrelease => '5.10' }) + end it 'uses the NTP pool servers by default' do should contain_file('/etc/inet/ntp.conf').with({ @@ -286,7 +309,9 @@ end describe "on osfamily Solaris and operatingsystemrelease 5.11" do - let(:facts) {{ :osfamily => 'Solaris', :operatingsystemrelease => '5.11' }} + let :facts do + super().merge({ :osfamily => 'Solaris', :operatingsystemrelease => '5.11' }) + end it 'uses the NTP pool servers by default' do should contain_file('/etc/inet/ntp.conf').with({ @@ -296,9 +321,11 @@ end describe "for operating system family unsupported" do - let(:facts) {{ + let :facts do + super().merge({ :osfamily => 'unsupported', - }} + }) + end it { expect{ subject }.to raise_error( /^The ntp module is not supported on an unsupported based system./ @@ -307,8 +334,10 @@ end describe 'for virtual machines' do - let(:facts) {{ :osfamily => 'Archlinux', - :is_virtual => 'true' }} + let :facts do + super().merge({ :osfamily => 'Archlinux', + :is_virtual => 'true' }) + end it 'should not use local clock as a time source' do should_not contain_file('/etc/ntp.conf').with({ @@ -324,8 +353,10 @@ end describe 'for physical machines' do - let(:facts) {{ :osfamily => 'Archlinux', - :is_virtual => 'false' }} + let :facts do + super().merge({ :osfamily => 'Archlinux', + :is_virtual => 'false' }) + end it 'disallows large clock skews' do should_not contain_file('/etc/ntp.conf').with({ diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f5664..270d2acd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,28 @@ require 'puppetlabs_spec_helper/module_spec_helper' + +RSpec.configure do |c| + c.include PuppetlabsSpec::Files + + c.before :each do + # Ensure that we don't accidentally cache facts and environment + # between test cases. + Facter::Util::Loader.any_instance.stubs(:load_all) + Facter.clear + Facter.clear_messages + + # Store any environment variables away to be restored later + @old_env = {} + ENV.each_key {|k| @old_env[k] = ENV[k]} + + if Gem::Version.new(`puppet --version`) >= Gem::Version.new('3.5') + Puppet.settings[:strict_variables]=true + end + if ENV['PARSER'] + Puppet.settings[:parser]=ENV['PARSER'] + end + end + + c.after :each do + PuppetlabsSpec::Files.cleanup + end +end From 18314d479aac24da49b938b06191ed4ddbf5720c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20S=C3=A9hier?= Date: Thu, 31 Jul 2014 11:03:19 +0200 Subject: [PATCH 3/6] fix test with preferred server and iburst enabled --- spec/classes/ntp_spec.rb | 310 +++++++++++++++++++-------------------- 1 file changed, 155 insertions(+), 155 deletions(-) diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 2b9d56d4..7e79869a 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -5,210 +5,210 @@ ['Debian', 'RedHat','SuSE', 'FreeBSD', 'Archlinux', 'Gentoo', 'Gentoo (Facter < 1.7)'].each do |system| context "when on system #{system}" do - if system == 'Gentoo (Facter < 1.7)' - let :facts do - super().merge({ :osfamily => 'Linux', :operatingsystem => 'Gentoo' }) - end - else - let :facts do - super().merge({ :osfamily => system }) + if system == 'Gentoo (Facter < 1.7)' + let :facts do + super().merge({ :osfamily => 'Linux', :operatingsystem => 'Gentoo' }) + end + else + let :facts do + super().merge({ :osfamily => system }) + end end - end - it { should contain_class('ntp::install') } - it { should contain_class('ntp::config') } - it { should contain_class('ntp::service') } + it { should contain_class('ntp::install') } + it { should contain_class('ntp::config') } + it { should contain_class('ntp::service') } - describe "ntp::config on #{system}" do - it { should contain_file('/etc/ntp.conf').with_owner('0') } - it { should contain_file('/etc/ntp.conf').with_group('0') } - it { should contain_file('/etc/ntp.conf').with_mode('0644') } + describe "ntp::config on #{system}" do + it { should contain_file('/etc/ntp.conf').with_owner('0') } + it { should contain_file('/etc/ntp.conf').with_group('0') } + it { should contain_file('/etc/ntp.conf').with_mode('0644') } - describe 'allows template to be overridden' do - let(:params) {{ :config_template => 'my_ntp/ntp.conf.erb' }} - it { should contain_file('/etc/ntp.conf').with({ - 'content' => /server foobar/}) - } - end + describe 'allows template to be overridden' do + let(:params) {{ :config_template => 'my_ntp/ntp.conf.erb' }} + it { should contain_file('/etc/ntp.conf').with({ + 'content' => /server foobar/}) + } + end - describe "keys for osfamily #{system}" do - context "when enabled" do + describe "keys for osfamily #{system}" do + context "when enabled" do + let(:params) {{ + :keys_enable => true, + :keys_file => '/etc/ntp/ntp.keys', + :keys_trusted => ['1', '2', '3'], + :keys_controlkey => '2', + :keys_requestkey => '3', + }} + + it { should contain_file('/etc/ntp').with({ + 'ensure' => 'directory'}) + } + it { should contain_file('/etc/ntp.conf').with({ + 'content' => /trustedkey 1 2 3/}) + } + it { should contain_file('/etc/ntp.conf').with({ + 'content' => /controlkey 2/}) + } + it { should contain_file('/etc/ntp.conf').with({ + 'content' => /requestkey 3/}) + } + end + end + + context "when disabled" do let(:params) {{ - :keys_enable => true, + :keys_enable => false, :keys_file => '/etc/ntp/ntp.keys', :keys_trusted => ['1', '2', '3'], :keys_controlkey => '2', :keys_requestkey => '3', }} - it { should contain_file('/etc/ntp').with({ + it { should_not contain_file('/etc/ntp').with({ 'ensure' => 'directory'}) } - it { should contain_file('/etc/ntp.conf').with({ + it { should_not contain_file('/etc/ntp.conf').with({ 'content' => /trustedkey 1 2 3/}) } - it { should contain_file('/etc/ntp.conf').with({ + it { should_not contain_file('/etc/ntp.conf').with({ 'content' => /controlkey 2/}) } - it { should contain_file('/etc/ntp.conf').with({ - 'content' => /requestkey 3/}) - } - end - end - - context "when disabled" do - let(:params) {{ - :keys_enable => false, - :keys_file => '/etc/ntp/ntp.keys', - :keys_trusted => ['1', '2', '3'], - :keys_controlkey => '2', - :keys_requestkey => '3', - }} - - it { should_not contain_file('/etc/ntp').with({ - 'ensure' => 'directory'}) - } - it { should_not contain_file('/etc/ntp.conf').with({ - 'content' => /trustedkey 1 2 3/}) - } - it { should_not contain_file('/etc/ntp.conf').with({ - 'content' => /controlkey 2/}) - } - it { should_not contain_file('/etc/ntp.conf').with({ - 'content' => /requestkey 3/}) - } - end - - describe 'preferred servers' do - context "when set" do - let(:params) {{ - :servers => ['a', 'b', 'c', 'd'], - :preferred_servers => ['a', 'b'] - }} - - it { should contain_file('/etc/ntp.conf').with({ - 'content' => /server a prefer\nserver b prefer\nserver c\nserver d/}) - } - end - context "when not set" do - let(:params) {{ - :servers => ['a', 'b', 'c', 'd'], - :preferred_servers => [] - }} - it { should_not contain_file('/etc/ntp.conf').with({ - 'content' => /server a prefer/}) + 'content' => /requestkey 3/}) } end - end - describe 'specified interfaces' do - context "when set" do - let(:params) {{ - :servers => ['a', 'b', 'c', 'd'], - :interfaces => ['127.0.0.1', 'a.b.c.d'] - }} - it { should contain_file('/etc/ntp.conf').with({ - 'content' => /interface ignore wildcard\ninterface listen 127.0.0.1\ninterface listen a.b.c.d/}) - } - end - context "when not set" do - let(:params) {{ - :servers => ['a', 'b', 'c', 'd'], - }} + describe 'preferred servers' do + context "when set" do + let(:params) {{ + :servers => ['a', 'b', 'c', 'd'], + :preferred_servers => ['a', 'b'] + }} - it { should_not contain_file('/etc/ntp.conf').with({ - 'content' => /interface ignore wildcard/}) - } + it { should contain_file('/etc/ntp.conf').with({ + 'content' => /server a( iburst)? prefer\nserver b( iburst)? prefer\nserver c( iburst)?\nserver d( iburst)?/}) + } + end + context "when not set" do + let(:params) {{ + :servers => ['a', 'b', 'c', 'd'], + :preferred_servers => [] + }} + + it { should_not contain_file('/etc/ntp.conf').with({ + 'content' => /server a prefer/}) + } + end end - end - - describe "ntp::install on #{system}" do - let(:params) {{ :package_ensure => 'present', :package_name => ['ntp'], }} - - it { should contain_package('ntp').with( - :ensure => 'present' - )} - - describe 'should allow package ensure to be overridden' do - let(:params) {{ :package_ensure => 'latest', :package_name => ['ntp'] }} - it { should contain_package('ntp').with_ensure('latest') } + describe 'specified interfaces' do + context "when set" do + let(:params) {{ + :servers => ['a', 'b', 'c', 'd'], + :interfaces => ['127.0.0.1', 'a.b.c.d'] + }} + + it { should contain_file('/etc/ntp.conf').with({ + 'content' => /interface ignore wildcard\ninterface listen 127.0.0.1\ninterface listen a.b.c.d/}) + } + end + context "when not set" do + let(:params) {{ + :servers => ['a', 'b', 'c', 'd'], + }} + + it { should_not contain_file('/etc/ntp.conf').with({ + 'content' => /interface ignore wildcard/}) + } + end end - describe 'should allow the package name to be overridden' do - let(:params) {{ :package_ensure => 'present', :package_name => ['hambaby'] }} - it { should contain_package('hambaby') } - end - end + describe "ntp::install on #{system}" do + let(:params) {{ :package_ensure => 'present', :package_name => ['ntp'], }} - describe 'ntp::service' do - let(:params) {{ - :service_manage => true, - :service_enable => true, - :service_ensure => 'running', - :service_name => 'ntp' - }} - - describe 'with defaults' do - it { should contain_service('ntp').with( - :enable => true, - :ensure => 'running', - :name => 'ntp' + it { should contain_package('ntp').with( + :ensure => 'present' )} - end - describe 'service_ensure' do - describe 'when overridden' do - let(:params) {{ :service_name => 'ntp', :service_ensure => 'stopped' }} - it { should contain_service('ntp').with_ensure('stopped') } + describe 'should allow package ensure to be overridden' do + let(:params) {{ :package_ensure => 'latest', :package_name => ['ntp'] }} + it { should contain_package('ntp').with_ensure('latest') } + end + + describe 'should allow the package name to be overridden' do + let(:params) {{ :package_ensure => 'present', :package_name => ['hambaby'] }} + it { should contain_package('hambaby') } end end - describe 'service_manage' do + describe 'ntp::service' do let(:params) {{ - :service_manage => false, + :service_manage => true, :service_enable => true, :service_ensure => 'running', - :service_name => 'ntpd', + :service_name => 'ntp' }} - it 'when set to false' do - should_not contain_service('ntp').with({ - 'enable' => true, - 'ensure' => 'running', - 'name' => 'ntpd' - }) + describe 'with defaults' do + it { should contain_service('ntp').with( + :enable => true, + :ensure => 'running', + :name => 'ntp' + )} end - end - end - describe 'with parameter iburst_enable' do - context 'when set to true' do - let(:params) {{ - :iburst_enable => true, - }} + describe 'service_ensure' do + describe 'when overridden' do + let(:params) {{ :service_name => 'ntp', :service_ensure => 'stopped' }} + it { should contain_service('ntp').with_ensure('stopped') } + end + end - it do - should contain_file('/etc/ntp.conf').with({ - 'content' => /iburst\n/, - }) + describe 'service_manage' do + let(:params) {{ + :service_manage => false, + :service_enable => true, + :service_ensure => 'running', + :service_name => 'ntpd', + }} + + it 'when set to false' do + should_not contain_service('ntp').with({ + 'enable' => true, + 'ensure' => 'running', + 'name' => 'ntpd' + }) + end end end - context 'when set to false' do - let(:params) {{ - :iburst_enable => false, - }} + describe 'with parameter iburst_enable' do + context 'when set to true' do + let(:params) {{ + :iburst_enable => true, + }} - it do - should_not contain_file('/etc/ntp.conf').with({ + it do + should contain_file('/etc/ntp.conf').with({ 'content' => /iburst\n/, - }) + }) + end + end + + context 'when set to false' do + let(:params) {{ + :iburst_enable => false, + }} + + it do + should_not contain_file('/etc/ntp.conf').with({ + 'content' => /iburst\n/, + }) + end end end end end - end #context when on system context 'ntp::config' do describe "for operating system Gentoo (Facter < 1.7)" do From 6eb69d8bf50903513e86da453e5b4d396ba6eae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20S=C3=A9hier?= Date: Thu, 31 Jul 2014 12:24:05 +0200 Subject: [PATCH 4/6] add logfile parameter test --- spec/classes/ntp_spec.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 7e79869a..4a9fd44f 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -207,6 +207,33 @@ end end end + + describe 'with parameter logfile' do + context 'when set to true' do + let(:params) {{ + :servers => ['a', 'b', 'c', 'd'], + :logfile => '/var/log/foobar.log', + }} + + it 'should contain logfile setting' do + should contain_file('/etc/ntp.conf').with({ + 'content' => /^logfile = \/var\/log\/foobar\.log\n/, + }) + end + end + + context 'when set to false' do + let(:params) {{ + :servers => ['a', 'b', 'c', 'd'], + }} + + it 'should not contain a logfile line' do + should_not contain_file('/etc/ntp.conf').with({ + 'content' => /logfile =/, + }) + end + end + end end end @@ -365,5 +392,4 @@ end end end - end From a844ba20be535bfa8c08cf7c0d3f23110d768cbe Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Thu, 28 Aug 2014 17:52:40 -0400 Subject: [PATCH 5/6] Update spec_helper for more consistency --- spec/spec_helper_acceptance.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 68d4e737..ccc8915b 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -3,16 +3,16 @@ UNSUPPORTED_PLATFORMS = [ 'windows', 'Darwin' ] unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' - if hosts.first.is_pe? - install_pe - else - install_puppet({ :version => '3.6.2', - :facter_version => '2.1.0', - :hiera_version => '1.3.4', - :default_action => 'gem_install' }) - hosts.each {|h| on h, "/bin/echo '' > #{h['hieraconf']}" } - end + # This will install the latest available package on el and deb based + # systems fail on windows and osx, and install via gem on other *nixes + foss_opts = { :default_action => 'gem_install' } + + if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end + hosts.each do |host| + unless host.is_pe? + on host, "/bin/echo '' > #{host['hieraconf']}" + end on host, "mkdir -p #{host['distmoduledir']}" on host, 'puppet module install puppetlabs-stdlib', :acceptable_exit_codes => [0,1] end From 7d8883aff8ee7a5127782ae71af81e1a8266506e Mon Sep 17 00:00:00 2001 From: sebastianschauenburg Date: Mon, 9 Mar 2015 15:24:13 +0100 Subject: [PATCH 6/6] Added $config_dir variable --- manifests/config.pp | 15 ++++++++++++--- manifests/init.pp | 5 +++++ manifests/params.pp | 1 + spec/classes/ntp_spec.rb | 6 ------ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 91990ba1..75b331f2 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -2,12 +2,21 @@ class ntp::config inherits ntp { if $keys_enable { - $directory = ntp_dirname($keys_file) - file { $directory: + file { $keys_file: + ensure => file, + owner => 0, + group => 0, + mode => '0644', + } + } + + if $config_dir { + file { $config_dir: ensure => directory, owner => 0, group => 0, - mode => '0755', + mode => '0644', + recurse => false, } } diff --git a/manifests/init.pp b/manifests/init.pp index 14adf595..f2b43755 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -2,6 +2,7 @@ $autoupdate = $ntp::params::autoupdate, $broadcastclient = $ntp::params::broadcastclient, $config = $ntp::params::config, + $config_dir = $ntp::params::config_dir, $config_template = $ntp::params::config_template, $disable_auth = $ntp::params::disable_auth, $disable_monitor = $ntp::params::disable_monitor, @@ -56,6 +57,10 @@ validate_string($service_name) validate_bool($udlc) + if $config_dir { + validate_absolute_path($config_dir) + } + if $autoupdate { notice('autoupdate parameter has been deprecated and replaced with package_ensure. Set this to latest for the same behavior as autoupdate => true.') } diff --git a/manifests/params.pp b/manifests/params.pp index 47a89800..71dc6872 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,6 +1,7 @@ class ntp::params { $autoupdate = false + $config_dir = undef $config_template = 'ntp/ntp.conf.erb' $disable_monitor = false $keys_enable = false diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 4864e888..d27628aa 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -45,9 +45,6 @@ :keys_requestkey => '3', }} - it { should contain_file('/etc/ntp').with({ - 'ensure' => 'directory'}) - } it { should contain_file('/etc/ntp.conf').with({ 'content' => /trustedkey 1 2 3/}) } @@ -69,9 +66,6 @@ :keys_requestkey => '3', }} - it { should_not contain_file('/etc/ntp').with({ - 'ensure' => 'directory'}) - } it { should_not contain_file('/etc/ntp.conf').with({ 'content' => /trustedkey 1 2 3/}) }