From c2df56745086606ba88f6824bd85211996a13662 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 17:55:16 -0400 Subject: Add ntp::config, a class to manage the ntp configuration file. --- manifests/config.pp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 manifests/config.pp diff --git a/manifests/config.pp b/manifests/config.pp new file mode 100644 index 0000000..30a46aa --- /dev/null +++ b/manifests/config.pp @@ -0,0 +1,16 @@ +class ntp::config( + $config = $ntp::config, + $config_template = $ntp::config_template, + $restrict = $ntp::restrict, + $servers = $ntp::servers, +) { + + file { $config: + ensure => file, + owner => 0, + group => 0, + mode => '0644', + content => template("ntp/${config_template}"), + } + +} -- cgit v1.2.3 From 3ce96dafa278bcc49e4acafe72674342560f41c9 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 17:55:31 -0400 Subject: Add ntp::install, a class to manage the ntp packages. --- manifests/install.pp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 manifests/install.pp diff --git a/manifests/install.pp b/manifests/install.pp new file mode 100644 index 0000000..beaf197 --- /dev/null +++ b/manifests/install.pp @@ -0,0 +1,18 @@ +class ntp::install( + $autoupdate = $ntp::autoupdate, + $package_name = $ntp::package_name, +) { + + validate_bool($autoupdate) + + $package_ensure = $autoupdate ? { + true => 'latest', + default => 'present', + } + + package { 'ntp': + ensure => $package_ensure, + name => $package_name, + } + +} -- cgit v1.2.3 From 3fe6df58d1c5c289655985401c0aecd9a2f996f1 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 17:55:41 -0400 Subject: Add ntp::params, a place to centralize all configuration information. --- manifests/params.pp | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 manifests/params.pp diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..ba9a540 --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,79 @@ +class ntp::params() { + + $autoupdate = false + $enable_service = true + $ensure_service = 'running' + $restrict = true + + case $::osfamily { + 'Debian': { + $config = '/etc/ntp.conf' + $config_template = 'ntp.conf.debian.erb' + $package_name = [ 'ntp' ] + $service_name = 'ntp' + $servers = [ + '0.debian.pool.ntp.org iburst', + '1.debian.pool.ntp.org iburst', + '2.debian.pool.ntp.org iburst', + '3.debian.pool.ntp.org iburst', + ] + } + 'RedHat': { + $config = '/etc/ntp.conf' + $config_template = 'ntp.conf.el.erb' + $package_name = [ 'ntp' ] + $service_name = 'ntpd' + $servers = [ + '0.centos.pool.ntp.org', + '1.centos.pool.ntp.org', + '2.centos.pool.ntp.org', + ] + } + 'SuSE': { + $config = '/etc/ntp.conf' + $config_template = 'ntp.conf.suse.erb' + $package_name = [ 'ntp' ] + $service_name = 'ntp' + $servers = [ + '0.opensuse.pool.ntp.org', + '1.opensuse.pool.ntp.org', + '2.opensuse.pool.ntp.org', + '3.opensuse.pool.ntp.org', + ] + } + 'FreeBSD': { + $config = '/etc/ntp.conf' + $config_template = 'ntp.conf.freebsd.erb' + $package_name = ['net/ntp'] + $service_name = 'ntpd' + $servers = [ + '0.freebsd.pool.ntp.org iburst maxpoll 9', + '1.freebsd.pool.ntp.org iburst maxpoll 9', + '2.freebsd.pool.ntp.org iburst maxpoll 9', + '3.freebsd.pool.ntp.org iburst maxpoll 9', + ] + } + 'Linux': { + # Account for distributions that don't have $::osfamily specific settings. + case $::operatingsystem { + 'Archlinux': { + $config = '/etc/ntp.conf' + $config_template = 'ntp.conf.archlinux.erb' + $package_name = ['ntp'] + $service_name = 'ntpd' + $servers = [ + '0.pool.ntp.org', + '1.pool.ntp.org', + '2.pool.ntp.org', + ] + } + default: { + fail("The ${module_name} module is not supported on an ${::operatingsystem} distribution.") + } + } + } + default: { + fail("The ${module_name} module is not supported on an ${::osfamily} based system.") + } + } +} -- cgit v1.2.3 From e6d35855e0208e7fc54a085316fd11a1dba13d18 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 17:56:01 -0400 Subject: Refactor out the main ntp class to break it up into 4 smaller ones. --- manifests/init.pp | 146 ++++++------------------------------------------------ 1 file changed, 15 insertions(+), 131 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index af1f8d5..845bbb9 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -45,138 +45,22 @@ # } # # [Remember: No empty lines between comments and class definition] -class ntp($servers='UNSET', - $ensure='running', - $enable=true, - $restrict=true, - $config_template=undef, - $autoupdate=false -) { +class ntp( + $autoupdate = $ntp::params::autoupdate, + $config = $ntp::params::config, + $config_template = $ntp::params::config_template, + $enable_service = $ntp::params::enable_service, + $ensure_service = $ntp::params::ensure_service, + $package_name = $ntp::params::package_name, + $restrict = $ntp::params::restrict, + $servers = $ntp::params::servers, + $service_name = $ntp::params::service_name, +) inherits ntp::params { - if ! ($ensure in [ 'running', 'stopped' ]) { - fail('ensure parameter must be running or stopped') - } + include '::ntp::install' + include '::ntp::config' + include '::ntp::service' - if $autoupdate == true { - $package_ensure = latest - } elsif $autoupdate == false { - $package_ensure = present - } else { - fail('autoupdate parameter must be true or false') - } + Class['::ntp::install'] -> Class['::ntp::config'] ~> Class['::ntp::service'] - case $::osfamily { - Debian: { - $supported = true - $pkg_name = [ 'ntp' ] - $svc_name = 'ntp' - $config = '/etc/ntp.conf' - $config_tpl = 'ntp.conf.debian.erb' - if ($servers == 'UNSET') { - $servers_real = [ '0.debian.pool.ntp.org iburst', - '1.debian.pool.ntp.org iburst', - '2.debian.pool.ntp.org iburst', - '3.debian.pool.ntp.org iburst', ] - } else { - $servers_real = $servers - } - } - RedHat: { - $supported = true - $pkg_name = [ 'ntp' ] - $svc_name = 'ntpd' - $config = '/etc/ntp.conf' - $config_tpl = 'ntp.conf.el.erb' - if ($servers == 'UNSET') { - $servers_real = [ '0.centos.pool.ntp.org', - '1.centos.pool.ntp.org', - '2.centos.pool.ntp.org', ] - } else { - $servers_real = $servers - } - } - SuSE: { - $supported = true - $pkg_name = [ 'ntp' ] - $svc_name = 'ntp' - $config = '/etc/ntp.conf' - $config_tpl = 'ntp.conf.suse.erb' - if ($servers == 'UNSET') { - $servers_real = [ '0.opensuse.pool.ntp.org', - '1.opensuse.pool.ntp.org', - '2.opensuse.pool.ntp.org', - '3.opensuse.pool.ntp.org', ] - } else { - $servers_real = $servers - } - } - FreeBSD: { - $supported = true - $pkg_name = ['net/ntp'] - $svc_name = 'ntpd' - $config = '/etc/ntp.conf' - $config_tpl = 'ntp.conf.freebsd.erb' - if ($servers == 'UNSET') { - $servers_real = [ '0.freebsd.pool.ntp.org iburst maxpoll 9', - '1.freebsd.pool.ntp.org iburst maxpoll 9', - '2.freebsd.pool.ntp.org iburst maxpoll 9', - '3.freebsd.pool.ntp.org iburst maxpoll 9', ] - } else { - $servers_real = $servers - } - } - - Linux: { - if ($::operatingsystem == 'Archlinux') { - $supported = true - $pkg_name = ['ntp'] - $svc_name = 'ntpd' - $config = '/etc/ntp.conf' - $config_tpl = 'ntp.conf.archlinux.erb' - - if ($servers == 'UNSET') { - $servers_real = [ '0.pool.ntp.org', - '1.pool.ntp.org', - '2.pool.ntp.org' ] - } else { - $servers_real = $servers - } - } else { - fail("The ${module_name} module is not supported on an ${::operatingsystem} system") - } - } - - default: { - fail("The ${module_name} module is not supported on ${::osfamily} based systems") - } - } - - if ($config_template == undef) { - $template_real = "${module_name}/${config_tpl}" - } else { - $template_real = $config_template - } - - package { 'ntp': - ensure => $package_ensure, - name => $pkg_name, - } - - file { $config: - ensure => file, - owner => 0, - group => 0, - mode => '0644', - content => template($template_real), - require => Package[$pkg_name], - } - - service { 'ntp': - ensure => $ensure, - enable => $enable, - name => $svc_name, - hasstatus => true, - hasrestart => true, - subscribe => [ Package[$pkg_name], File[$config] ], - } } -- cgit v1.2.3 From b47ce3980fe62cf25a72ee71fd96a8eb0c915e0d Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 17:56:14 -0400 Subject: Add ntp::service, a class to manage the ntp service. --- manifests/service.pp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 manifests/service.pp diff --git a/manifests/service.pp b/manifests/service.pp new file mode 100644 index 0000000..aea661d --- /dev/null +++ b/manifests/service.pp @@ -0,0 +1,20 @@ +class ntp::service ( + $ensure_service = $ntp::ensure_service, + $enable_service = $ntp::enable_service, + $service_name = $ntp::service_name, +) { + + if ! ($ensure_service in [ 'running', 'stopped' ]) { + fail('ensure_service parameter must be running or stopped') + } + validate_bool($enable_service) + + service { 'ntp': + ensure => $ensure_service, + enable => $enable_service, + name => $service_name, + hasstatus => true, + hasrestart => true, + } + +} -- cgit v1.2.3 From 441c5ba4e8b292509e74a83d4a3cdfa73cfdf14a Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 17:56:25 -0400 Subject: Rename all the servers_real functions to servers. --- templates/ntp.conf.archlinux.erb | 2 +- templates/ntp.conf.debian.erb | 2 +- templates/ntp.conf.el.erb | 2 +- templates/ntp.conf.freebsd.erb | 2 +- templates/ntp.conf.suse.erb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/ntp.conf.archlinux.erb b/templates/ntp.conf.archlinux.erb index 5e27334..22395d9 100644 --- a/templates/ntp.conf.archlinux.erb +++ b/templates/ntp.conf.archlinux.erb @@ -6,7 +6,7 @@ # - https://wiki.archlinux.org/index.php/Network_Time_Protocol_daemon # Associate to public NTP pool servers; see http://www.pool.ntp.org/ -<% [@servers_real].flatten.each do |server| -%> +<% [@servers].flatten.each do |server| -%> server <%= server %> <% end -%> diff --git a/templates/ntp.conf.debian.erb b/templates/ntp.conf.debian.erb index 15451cd..7225fad 100644 --- a/templates/ntp.conf.debian.erb +++ b/templates/ntp.conf.debian.erb @@ -26,7 +26,7 @@ filegen clockstats file clockstats type day enable # pool: # Managed by puppet class { "ntp": servers => [ ... ] } -<% [@servers_real].flatten.each do |server| -%> +<% [@servers].flatten.each do |server| -%> server <%= server %> <% end -%> diff --git a/templates/ntp.conf.el.erb b/templates/ntp.conf.el.erb index 77c731a..4e90569 100644 --- a/templates/ntp.conf.el.erb +++ b/templates/ntp.conf.el.erb @@ -24,7 +24,7 @@ restrict -6 ::1 # Please consider joining the pool (http://www.pool.ntp.org/join.html). # Managed by puppet class { "ntp": servers => [ ... ] } -<% [@servers_real].flatten.each do |server| -%> +<% [@servers].flatten.each do |server| -%> server <%= server %> <% end -%> diff --git a/templates/ntp.conf.freebsd.erb b/templates/ntp.conf.freebsd.erb index 1cf00cc..a55ba3d 100644 --- a/templates/ntp.conf.freebsd.erb +++ b/templates/ntp.conf.freebsd.erb @@ -25,6 +25,6 @@ tinker panic 0 <% end -%> -<% [@servers_real].flatten.each do |server| -%> +<% [@servers].flatten.each do |server| -%> server <%= server %> <% end -%> diff --git a/templates/ntp.conf.suse.erb b/templates/ntp.conf.suse.erb index 4ce6205..e44e068 100644 --- a/templates/ntp.conf.suse.erb +++ b/templates/ntp.conf.suse.erb @@ -39,7 +39,7 @@ fudge 127.127.1.0 stratum 10 # LCL is unsynchronized <% end -%> # Managed by puppet class { "ntp": servers => [ ... ] } -<% [@servers_real].flatten.each do |server| -%> +<% [@servers].flatten.each do |server| -%> server <%= server %> <% end -%> -- cgit v1.2.3 From 735984e75e7a510559659f1f477c60ba2c881d9a Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 18:17:02 -0400 Subject: Rework specs to pass with renamed params. --- spec/classes/ntp_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index a29c4e4..5b28a3b 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -82,7 +82,7 @@ describe 'ntp' do }} it { expect{ subject }.to raise_error( - /^The ntp module is not supported on unsupported based systems/ + /^The ntp module is not supported on an unsupported based system./ )} end @@ -137,7 +137,7 @@ describe 'ntp' do it { should contain_service('ntp').with_hasstatus(true) } it { should contain_service('ntp').with_hasrestart(true) } it 'should allow service ensure to be overridden' do - params[:ensure] = 'stopped' + params[:ensure_service] = 'stopped' subject.should contain_service('ntp').with_ensure('stopped') end it 'should allow package ensure to be overridden' do -- cgit v1.2.3 From dc0efbfacf6f7135e0437495e6f69f971da6285d Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 18:19:12 -0400 Subject: Ensure that users can pass in templates from outside of the ntp module. --- manifests/config.pp | 2 +- manifests/params.pp | 10 +++++----- spec/fixtures/manifests/site.pp | 0 3 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 spec/fixtures/manifests/site.pp diff --git a/manifests/config.pp b/manifests/config.pp index 30a46aa..3295548 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -10,7 +10,7 @@ class ntp::config( owner => 0, group => 0, mode => '0644', - content => template("ntp/${config_template}"), + content => template($config_template), } } diff --git a/manifests/params.pp b/manifests/params.pp index ba9a540..9d20a13 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -8,7 +8,7 @@ class ntp::params() { case $::osfamily { 'Debian': { $config = '/etc/ntp.conf' - $config_template = 'ntp.conf.debian.erb' + $config_template = 'ntp/ntp.conf.debian.erb' $package_name = [ 'ntp' ] $service_name = 'ntp' $servers = [ @@ -20,7 +20,7 @@ class ntp::params() { } 'RedHat': { $config = '/etc/ntp.conf' - $config_template = 'ntp.conf.el.erb' + $config_template = 'ntp/ntp.conf.el.erb' $package_name = [ 'ntp' ] $service_name = 'ntpd' $servers = [ @@ -31,7 +31,7 @@ class ntp::params() { } 'SuSE': { $config = '/etc/ntp.conf' - $config_template = 'ntp.conf.suse.erb' + $config_template = 'ntp/ntp.conf.suse.erb' $package_name = [ 'ntp' ] $service_name = 'ntp' $servers = [ @@ -43,7 +43,7 @@ class ntp::params() { } 'FreeBSD': { $config = '/etc/ntp.conf' - $config_template = 'ntp.conf.freebsd.erb' + $config_template = 'ntp/ntp.conf.freebsd.erb' $package_name = ['net/ntp'] $service_name = 'ntpd' $servers = [ @@ -58,7 +58,7 @@ class ntp::params() { case $::operatingsystem { 'Archlinux': { $config = '/etc/ntp.conf' - $config_template = 'ntp.conf.archlinux.erb' + $config_template = 'ntp/ntp.conf.archlinux.erb' $package_name = ['ntp'] $service_name = 'ntpd' $servers = [ diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp deleted file mode 100644 index e69de29..0000000 -- cgit v1.2.3 From 75efd2a9e423d421a970eafe4e10071676c81561 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 18:52:04 -0400 Subject: Some syntax fixes as well as deprecate autoupdate. --- manifests/init.pp | 1 + manifests/install.pp | 11 ++--------- manifests/params.pp | 7 ++++++- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 845bbb9..ad443c3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -51,6 +51,7 @@ class ntp( $config_template = $ntp::params::config_template, $enable_service = $ntp::params::enable_service, $ensure_service = $ntp::params::ensure_service, + $package_ensure = $ntp::params::package_ensure, $package_name = $ntp::params::package_name, $restrict = $ntp::params::restrict, $servers = $ntp::params::servers, diff --git a/manifests/install.pp b/manifests/install.pp index beaf197..f9c61f1 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,15 +1,8 @@ class ntp::install( - $autoupdate = $ntp::autoupdate, - $package_name = $ntp::package_name, + $package_ensure = $ntp::package_ensure, + $package_name = $ntp::package_name, ) { - validate_bool($autoupdate) - - $package_ensure = $autoupdate ? { - true => 'latest', - default => 'present', - } - package { 'ntp': ensure => $package_ensure, name => $package_name, diff --git a/manifests/params.pp b/manifests/params.pp index 9d20a13..91186da 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -3,8 +3,13 @@ class ntp::params() { $autoupdate = false $enable_service = true $ensure_service = 'running' + $package_ensure = 'present' $restrict = true + if $autoupdate { + notice('autoupdate parameter has been deprecated and replaced with package_ensure. Set this to latest for the same behavior as autoupdate => true.') + } + case $::osfamily { 'Debian': { $config = '/etc/ntp.conf' @@ -61,7 +66,7 @@ class ntp::params() { $config_template = 'ntp/ntp.conf.archlinux.erb' $package_name = ['ntp'] $service_name = 'ntpd' - $servers = [ + $servers = [ '0.pool.ntp.org', '1.pool.ntp.org', '2.pool.ntp.org', -- cgit v1.2.3 From 1a199c77dff8569927c65544185f92dfb0a15c46 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 18:52:21 -0400 Subject: Fix specs now things are renamed. --- spec/classes/ntp_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 5b28a3b..c70908a 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -141,7 +141,7 @@ describe 'ntp' do subject.should contain_service('ntp').with_ensure('stopped') end it 'should allow package ensure to be overridden' do - params[:autoupdate] = true + params[:package_ensure] = 'latest' subject.should contain_package('ntp').with_ensure('latest') end it 'should allow template to be overridden' do -- cgit v1.2.3 From 82057592fe4e83ed15f1b5a9d4cd652fd0b8e528 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 5 Jul 2013 19:18:20 -0400 Subject: Add Gentoo support. (And reformat archlinux vars) --- Modulefile | 2 +- manifests/params.pp | 20 ++++++++++++---- spec/classes/ntp_spec.rb | 19 +++++++++++++++ templates/ntp.conf.gentoo.erb | 54 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 templates/ntp.conf.gentoo.erb diff --git a/Modulefile b/Modulefile index 3b18895..7755b15 100644 --- a/Modulefile +++ b/Modulefile @@ -4,7 +4,7 @@ source 'git://github.com/puppetlabs/puppetlabs-ntp' author 'Puppet Labs' license 'Apache Version 2.0' summary 'NTP Module' -description 'NTP Module for Debian, Ubuntu, CentOS, RHEL, OEL, Fedora, FreeBSD & Arch' +description 'NTP Module for Debian, Ubuntu, CentOS, RHEL, OEL, Fedora, FreeBSD, ArchLinux and Gentoo.' project_page 'http://github.com/puppetlabs/puppetlabs-ntp' ## Add dependencies, if any: diff --git a/manifests/params.pp b/manifests/params.pp index 91186da..1a9b7c8 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -62,16 +62,28 @@ class ntp::params() { # Account for distributions that don't have $::osfamily specific settings. case $::operatingsystem { 'Archlinux': { - $config = '/etc/ntp.conf' + $config = '/etc/ntp.conf' $config_template = 'ntp/ntp.conf.archlinux.erb' - $package_name = ['ntp'] - $service_name = 'ntpd' - $servers = [ + $package_name = ['ntp'] + $service_name = 'ntpd' + $servers = [ '0.pool.ntp.org', '1.pool.ntp.org', '2.pool.ntp.org', ] } + 'Gentoo': { + $config = '/etc/ntp.conf' + $config_template = 'ntp/ntp.conf.gentoo.erb' + $package_name = ['net-misc/ntp'] + $service_name = 'ntpd' + $servers = [ + '0.gentoo.pool.ntp.org', + '1.gentoo.pool.ntp.org', + '2.gentoo.pool.ntp.org', + '3.gentoo.pool.ntp.org', + ] + } default: { fail("The ${module_name} module is not supported on an ${::operatingsystem} distribution.") } diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index c70908a..527c53f 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -123,6 +123,25 @@ describe 'ntp' do end end + describe "for operating system Gentoo" do + + let(:params) {{}} + let(:facts) { { :operatingsystem => 'Gentoo', + :osfamily => 'Linux' } } + + it { should contain_service('ntp').with_name('ntpd') } + it { should contain_package('ntp').with_name('net-misc/ntp').with_ensure('present') } + + it 'should use the NTP pool servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + "server 0.gentoo.pool.ntp.org", + "server 1.gentoo.pool.ntp.org", + "server 2.gentoo.pool.ntp.org", + "server 3.gentoo.pool.ntp.org"] + (content.split("\n") & expected_lines).should == expected_lines + end + end ['Debian', 'RedHat','SuSE', 'FreeBSD'].each do |osfamily| describe "for operating system family #{osfamily}" do diff --git a/templates/ntp.conf.gentoo.erb b/templates/ntp.conf.gentoo.erb new file mode 100644 index 0000000..7b00b46 --- /dev/null +++ b/templates/ntp.conf.gentoo.erb @@ -0,0 +1,54 @@ +# NOTES: +# DHCP clients can append or replace NTP configuration files. +# You should consult your DHCP client documentation about its +# default behaviour and how to change it. + +# Name of the servers ntpd should sync with +# Please respect the access policy as stated by the responsible person. +#server ntp.example.tld iburst + +# Managed by puppet class { "ntp": servers => [ ... ] } +<% [@servers].flatten.each do |server| -%> +server <%= server %> +<% end -%> + +# Common pool for random people +#server pool.ntp.org + +## +# A list of available servers can be found here: +# http://www.pool.ntp.org/ +# http://www.pool.ntp.org/#use +# A good way to get servers for your machine is: +# netselect -s 3 pool.ntp.org +## + +# you should not need to modify the following paths +driftfile /var/lib/ntp/ntp.drift + +#server ntplocal.example.com prefer +#server timeserver.example.org + +# Warning: Using default NTP settings will leave your NTP +# server accessible to all hosts on the Internet. + +# If you want to deny all machines (including your own) +# from accessing the NTP server, uncomment: +#restrict default ignore + + +<% if @restrict -%> +# To deny other machines from changing the +# configuration but allow localhost: +restrict default nomodify nopeer +restrict 127.0.0.1 +restrict ::1 +<% end -%> + + +# To allow machines within your network to synchronize +# their clocks with your server, but ensure they are +# not allowed to configure the server or used as peers +# to synchronize against, uncomment this line. +# +#restrict 192.168.0.0 mask 255.255.255.0 nomodify nopeer notrap -- cgit v1.2.3 From b5136d77edb0f43c25247b45395277d32838b2ea Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 8 Jul 2013 10:29:01 -0400 Subject: Rename package_ensure to ensure_package. Add the anchor pattern. Move the deprecation warning out of params to init. --- manifests/init.pp | 16 ++++++++++++++-- manifests/params.pp | 6 +----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index ad443c3..f109640 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -50,18 +50,30 @@ class ntp( $config = $ntp::params::config, $config_template = $ntp::params::config_template, $enable_service = $ntp::params::enable_service, + $ensure_package = $ntp::params::ensure_package, $ensure_service = $ntp::params::ensure_service, - $package_ensure = $ntp::params::package_ensure, + $manage_service = $ntp::params::manage_service, $package_name = $ntp::params::package_name, $restrict = $ntp::params::restrict, $servers = $ntp::params::servers, $service_name = $ntp::params::service_name, ) inherits ntp::params { + if $autoupdate { + notice('autoupdate parameter has been deprecated and replaced with ensure_package. Set this to latest for the same behavior as autoupdate => true.') + } + include '::ntp::install' include '::ntp::config' include '::ntp::service' - Class['::ntp::install'] -> Class['::ntp::config'] ~> Class['::ntp::service'] + # Anchor this as per #8140 - this ensures that classes won't float off and + # mess everything up. You can read about this at: + # http://docs.puppetlabs.com/puppet/2.7/reference/lang_containment.html#known-issues + anchor { 'ntp::begin': } + anchor { 'ntp::end': } + + Anchor['ntp::begin'] -> Class['::ntp::install'] -> Class['::ntp::config'] + ~> Class['::ntp::service'] -> Anchor['ntp::end'] } diff --git a/manifests/params.pp b/manifests/params.pp index 1a9b7c8..dd55cd6 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -3,13 +3,9 @@ class ntp::params() { $autoupdate = false $enable_service = true $ensure_service = 'running' - $package_ensure = 'present' + $ensure_package = 'present' $restrict = true - if $autoupdate { - notice('autoupdate parameter has been deprecated and replaced with package_ensure. Set this to latest for the same behavior as autoupdate => true.') - } - case $::osfamily { 'Debian': { $config = '/etc/ntp.conf' -- cgit v1.2.3 From 824aa319a22d0be5349a3c00f9c9157dee4bc430 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 8 Jul 2013 10:29:14 -0400 Subject: Ensure the rename is done everywhere and wrap the service in a manage_service param. --- manifests/install.pp | 4 ++-- manifests/service.pp | 17 ++++++++++------- spec/classes/ntp_spec.rb | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index f9c61f1..b91538a 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,10 +1,10 @@ class ntp::install( - $package_ensure = $ntp::package_ensure, + $ensure_package = $ntp::ensure_package, $package_name = $ntp::package_name, ) { package { 'ntp': - ensure => $package_ensure, + ensure => $ensure_package, name => $package_name, } diff --git a/manifests/service.pp b/manifests/service.pp index aea661d..5ec4323 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,6 +1,7 @@ class ntp::service ( - $ensure_service = $ntp::ensure_service, $enable_service = $ntp::enable_service, + $ensure_service = $ntp::ensure_service, + $manage_service = $ntp::manage_service, $service_name = $ntp::service_name, ) { @@ -9,12 +10,14 @@ class ntp::service ( } validate_bool($enable_service) - service { 'ntp': - ensure => $ensure_service, - enable => $enable_service, - name => $service_name, - hasstatus => true, - hasrestart => true, + if $manage_service == true { + service { 'ntp': + ensure => $ensure_service, + enable => $enable_service, + name => $service_name, + hasstatus => true, + hasrestart => true, + } } } diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 527c53f..65d8e3b 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -160,7 +160,7 @@ describe 'ntp' do subject.should contain_service('ntp').with_ensure('stopped') end it 'should allow package ensure to be overridden' do - params[:package_ensure] = 'latest' + params[:ensure_package] = 'latest' subject.should contain_package('ntp').with_ensure('latest') end it 'should allow template to be overridden' do -- cgit v1.2.3 From 0d87be43451920f3bdea2037f79504d61047f405 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 11:27:17 -0400 Subject: Rewrite the spec tests to cover the 4 different classes and improve a few missing gaps in the testing. --- spec/classes/ntp_config_spec.rb | 161 ++++++++++++++++++++++++++++++++++++ spec/classes/ntp_install_spec.rb | 72 ++++++++++++++++ spec/classes/ntp_service_spec.rb | 73 ++++++++++++++++ spec/classes/ntp_spec.rb | 174 ++------------------------------------- 4 files changed, 313 insertions(+), 167 deletions(-) create mode 100644 spec/classes/ntp_config_spec.rb create mode 100644 spec/classes/ntp_install_spec.rb create mode 100644 spec/classes/ntp_service_spec.rb diff --git a/spec/classes/ntp_config_spec.rb b/spec/classes/ntp_config_spec.rb new file mode 100644 index 0000000..ddb9be9 --- /dev/null +++ b/spec/classes/ntp_config_spec.rb @@ -0,0 +1,161 @@ +require 'spec_helper' + +describe 'ntp::config' do + + def param_value(subject, type, title, param) + catalogue.resource(type, title).send(:parameters)[param.to_sym] + end + + let(:params) {{:servers => 'fake.pool.ntp.org'} } + + describe 'test platform specific resources' do + + describe "for operating system family Debian" do + + let(:params) {{}} + let(:facts) {{ :osfamily => 'debian' }} + + it 'should use the debian ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = ['server 0.debian.pool.ntp.org iburst', + 'server 1.debian.pool.ntp.org iburst', + 'server 2.debian.pool.ntp.org iburst', + 'server 3.debian.pool.ntp.org iburst'] + (content.split("\n") & expected_lines).should == expected_lines + end + + it 'should use different restrict settings if set' do + params[:restrict] == '127.0.0.1' + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = ['restrict 127.0.0.1'] + (content.split("\n") & expected_lines).should == expected_lines + end + end + + describe "for operating system family RedHat" do + + let(:params) {{}} + let(:facts) {{ :osfamily => 'redhat' }} + + it 'should use the redhat ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + 'server 0.centos.pool.ntp.org', + 'server 1.centos.pool.ntp.org', + 'server 2.centos.pool.ntp.org'] + (content.split("\n") & expected_lines).should == expected_lines + end + end + + describe "for operating system family SuSE" do + + let(:params) {{}} + let(:facts) {{ :osfamily => 'suse' }} + + it 'should use the opensuse ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + 'server 0.opensuse.pool.ntp.org', + 'server 1.opensuse.pool.ntp.org', + 'server 2.opensuse.pool.ntp.org', + 'server 3.opensuse.pool.ntp.org'] + (content.split("\n") & expected_lines).should == expected_lines + end + end + + describe "for operating system family FreeBSD" do + + let(:params) {{}} + let(:facts) {{ :osfamily => 'freebsd' }} + + it 'should use the freebsd ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + "server 0.freebsd.pool.ntp.org iburst maxpoll 9", + "server 1.freebsd.pool.ntp.org iburst maxpoll 9", + "server 2.freebsd.pool.ntp.org iburst maxpoll 9", + "server 3.freebsd.pool.ntp.org iburst maxpoll 9"] + (content.split("\n") & expected_lines).should == expected_lines + end + + describe "for operating system family unsupported" do + let(:facts) {{ + :osfamily => 'unsupported', + }} + + it { expect{ subject }.to raise_error( + /^The ntp module is not supported on an unsupported based system./ + )} + end + + end + + describe "for virtual machines" do + + let(:params) {{}} + let(:facts) {{ :operatingsystem => 'Archlinux', + :osfamily => 'Linux', + :isvirtual => 'false' }} + + it 'should not use local clock as a time source' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + 'server 127.127.1.0 # local clock', + 'fudge 127.127.1.0 stratum 10' ] + (content.split("\n") & expected_lines).should_not == expected_lines + end + end + + describe "for operating system Archlinux" do + + let(:params) {{}} + let(:facts) {{ :operatingsystem => 'Archlinux', + :osfamily => 'Linux' }} + + + it 'should use the NTP pool servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + "server 0.pool.ntp.org", + "server 1.pool.ntp.org", + "server 2.pool.ntp.org"] + (content.split("\n") & expected_lines).should == expected_lines + end + end + + describe "for operating system Gentoo" do + + let(:params) {{}} + let(:facts) {{ :operatingsystem => 'Gentoo', + :osfamily => 'Linux' }} + + + it 'should use the NTP pool servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + "server 0.gentoo.pool.ntp.org", + "server 1.gentoo.pool.ntp.org", + "server 2.gentoo.pool.ntp.org", + "server 3.gentoo.pool.ntp.org"] + (content.split("\n") & expected_lines).should == expected_lines + end + end + + ['Debian', 'RedHat','SuSE', 'FreeBSD'].each do |osfamily| + describe "for operating system family #{osfamily}" do + + let(:facts) {{ :osfamily => osfamily }} + + 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') } + it 'should allow template to be overridden' do + params[:config_template] = 'my_ntp/ntp.conf.erb' + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = ['server foobar'] + (content.split("\n") & expected_lines).should == expected_lines + end + end + end + end +end diff --git a/spec/classes/ntp_install_spec.rb b/spec/classes/ntp_install_spec.rb new file mode 100644 index 0000000..2102878 --- /dev/null +++ b/spec/classes/ntp_install_spec.rb @@ -0,0 +1,72 @@ +require 'spec_helper' + +describe 'ntp::install' do + + ['Debian', 'RedHat', 'SuSE', 'FreeBSD'].each do |osfamily| + describe "for osfamily #{osfamily}" do + + let(:facts) {{ :osfamily => osfamily }} + let(:params) {{ + :package_ensure => 'present', + :package_name => 'ntp', + }} + + it { should contain_package('ntp').with( + :ensure => 'present', + :name => 'ntp' + )} + + it 'should allow package ensure to be overridden' do + params[:package_ensure] = 'latest' + subject.should contain_package('ntp').with_ensure('latest') + end + + it 'should allow the package name to be overridden' do + params[:package_name] = 'hambaby' + subject.should contain_package('ntp').with_name('hambaby') + end + + end + end + + describe "for distribution gentoo" do + + let(:facts) {{ :osfamily => 'Linux', :operatingsystem => 'Gentoo' }} + let(:params) {{ + :package_ensure => 'present', + :package_name => 'net-misc/ntp', + }} + + it { should contain_package('ntp').with( + :ensure => 'present', + :name => 'net-misc/ntp' + )} + + it 'should allow package ensure to be overridden' do + params[:package_ensure] = 'latest' + subject.should contain_package('ntp').with_ensure('latest') + end + + end + + describe "for distribution archlinux" do + + let(:facts) {{ :osfamily => 'Linux', :operatingsystem => 'ArchLinux' }} + let(:params) {{ + :package_ensure => 'present', + :package_name => 'ntp', + }} + + it { should contain_package('ntp').with( + :ensure => 'present', + :name => 'ntp' + )} + + it 'should allow package ensure to be overridden' do + params[:package_ensure] = 'latest' + subject.should contain_package('ntp').with_ensure('latest') + end + + end + +end diff --git a/spec/classes/ntp_service_spec.rb b/spec/classes/ntp_service_spec.rb new file mode 100644 index 0000000..7ce1717 --- /dev/null +++ b/spec/classes/ntp_service_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' + +describe 'ntp::service' do + + ['Debian', 'RedHat', 'SuSE', 'FreeBSD'].each do |osfamily| + describe "for osfamily #{osfamily}" do + + let(:facts) {{ :osfamily => osfamily }} + let(:params) {{ + :service_manage => true, + :service_enable => true, + :service_ensure => 'running', + :service_name => 'ntp' + }} + + it { should contain_service('ntp').with( + :enable => true, + :ensure => 'running', + :name => 'ntp' + )} + + it 'should allow service ensure to be overridden' do + params[:service_ensure] = 'stopped' + subject.should contain_service('ntp').with_ensure('stopped') + end + end + end + + ['ArchLinux', 'Gentoo'].each do |operatingsystem| + describe "for distribution #{operatingsystem}" do + + let(:facts) {{ :osfamily => 'Linux', :operatingsystem => operatingsystem }} + let(:params) {{ + :service_manage => true, + :service_enable => true, + :service_ensure => 'running', + :service_name => 'ntpd' } + } + + it 'should contain service' do + should contain_service('ntp').with( + :enable => true, + :ensure => 'running', + :name => 'ntpd') + end + + it 'should allow service ensure to be overridden' do + params[:service_ensure] = 'stopped' + subject.should contain_service('ntp').with_ensure('stopped') + end + + end + end + + describe "isn't managed if service_manage is false" do + + let(:facts) {{ :osfamily => 'Debian' }} + + let(:params) {{ + :service_manage => false, + :service_enable => true, + :service_ensure => 'running', + :service_name => 'ntpd', + }} + + it { should_not contain_service('ntp').with( + :enable => true, + :ensure => 'running', + :name => 'ntpd' + )} + end + +end diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 65d8e3b..4ffd817 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -1,175 +1,15 @@ -#!/usr/bin/env rspec require 'spec_helper' describe 'ntp' do - def param_value(subject, type, title, param) - catalogue.resource(type, title).send(:parameters)[param.to_sym] - end + let(:facts) {{ :osfamily => 'Debian' }} - let(:params) { {:servers => 'fake.pool.ntp.org'} } + it { should include_class('ntp::install') } + it { should include_class('ntp::config') } + it { should include_class('ntp::service') } - describe 'test platform specific resources' do + # These are currently breaking for me. + #it { should have_class_count(3) } + #it { should have_resource_count(0) } - describe "for operating system family Debian" do - - let(:params) {{}} - let(:facts) { { :osfamily => 'debian' } } - - it { should contain_service('ntp').with_name('ntp') } - it 'should use the debian ntp servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = ['server 0.debian.pool.ntp.org iburst', - 'server 1.debian.pool.ntp.org iburst', - 'server 2.debian.pool.ntp.org iburst', - 'server 3.debian.pool.ntp.org iburst'] - (content.split("\n") & expected_lines).should == expected_lines - end - end - - describe "for operating system family RedHat" do - - let(:params) {{}} - let(:facts) { { :osfamily => 'redhat' } } - - it { should contain_service('ntp').with_name('ntpd') } - it 'should use the redhat ntp servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = [ - 'server 0.centos.pool.ntp.org', - 'server 1.centos.pool.ntp.org', - 'server 2.centos.pool.ntp.org'] - (content.split("\n") & expected_lines).should == expected_lines - end - end - - describe "for operating system family SuSE" do - - let(:params) {{}} - let(:facts) { { :osfamily => 'suse' } } - - it { should contain_service('ntp').with_name('ntp') } - it 'should use the opensuse ntp servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = [ - 'server 0.opensuse.pool.ntp.org', - 'server 1.opensuse.pool.ntp.org', - 'server 2.opensuse.pool.ntp.org', - 'server 3.opensuse.pool.ntp.org'] - (content.split("\n") & expected_lines).should == expected_lines - end - end - - describe "for operating system family FreeBSD" do - - let(:params) {{}} - let(:facts) { { :osfamily => 'freebsd' } } - - it { should contain_service('ntp').with_name('ntpd') } - it 'should use the freebsd ntp servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = [ - "server 0.freebsd.pool.ntp.org iburst maxpoll 9", - "server 1.freebsd.pool.ntp.org iburst maxpoll 9", - "server 2.freebsd.pool.ntp.org iburst maxpoll 9", - "server 3.freebsd.pool.ntp.org iburst maxpoll 9"] - (content.split("\n") & expected_lines).should == expected_lines - end - - describe "for operating system family unsupported" do - let(:facts) {{ - :osfamily => 'unsupported', - }} - - it { expect{ subject }.to raise_error( - /^The ntp module is not supported on an unsupported based system./ - )} - end - - end - - describe "for virtual machines" do - - let(:params) {{}} - let(:facts) { { :operatingsystem => 'Archlinux', - :osfamily => 'Linux', - :isvirtual => 'false' } } - - it 'should not use local clock as a time source' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = [ - 'server 127.127.1.0 # local clock', - 'fudge 127.127.1.0 stratum 10' ] - (content.split("\n") & expected_lines).should_not == expected_lines - end - end - - describe "for operating system Archlinux" do - - let(:params) {{}} - let(:facts) { { :operatingsystem => 'Archlinux', - :osfamily => 'Linux' } } - - it { should contain_service('ntp').with_name('ntpd') } - it { should contain_package('ntp').with_ensure('present') } - - it 'should use the NTP pool servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = [ - "server 0.pool.ntp.org", - "server 1.pool.ntp.org", - "server 2.pool.ntp.org"] - (content.split("\n") & expected_lines).should == expected_lines - end - end - - describe "for operating system Gentoo" do - - let(:params) {{}} - let(:facts) { { :operatingsystem => 'Gentoo', - :osfamily => 'Linux' } } - - it { should contain_service('ntp').with_name('ntpd') } - it { should contain_package('ntp').with_name('net-misc/ntp').with_ensure('present') } - - it 'should use the NTP pool servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = [ - "server 0.gentoo.pool.ntp.org", - "server 1.gentoo.pool.ntp.org", - "server 2.gentoo.pool.ntp.org", - "server 3.gentoo.pool.ntp.org"] - (content.split("\n") & expected_lines).should == expected_lines - end - end - - ['Debian', 'RedHat','SuSE', 'FreeBSD'].each do |osfamily| - describe "for operating system family #{osfamily}" do - - let(:facts) { { :osfamily => osfamily } } - - 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') } - it { should contain_package('ntp').with_ensure('present') } - it { should contain_service('ntp').with_ensure('running') } - it { should contain_service('ntp').with_hasstatus(true) } - it { should contain_service('ntp').with_hasrestart(true) } - it 'should allow service ensure to be overridden' do - params[:ensure_service] = 'stopped' - subject.should contain_service('ntp').with_ensure('stopped') - end - it 'should allow package ensure to be overridden' do - params[:ensure_package] = 'latest' - subject.should contain_package('ntp').with_ensure('latest') - end - it 'should allow template to be overridden' do - params[:config_template] = 'my_ntp/ntp.conf.erb' - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = ['server foobar'] - (content.split("\n") & expected_lines).should == expected_lines - end - end - end - end end -- cgit v1.2.3 From d934a26cfaf7b2ffeb7276ed26049c186894a87b Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 11:27:53 -0400 Subject: Rename parameters, remove outdated documentation, and adds inherit to ntp on the child classes. --- manifests/config.pp | 2 +- manifests/init.pp | 55 ++++------------------------------------------------ manifests/install.pp | 6 +++--- manifests/params.pp | 7 ++++--- manifests/service.pp | 19 +++++++++--------- 5 files changed, 21 insertions(+), 68 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 3295548..80368f0 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -3,7 +3,7 @@ class ntp::config( $config_template = $ntp::config_template, $restrict = $ntp::restrict, $servers = $ntp::servers, -) { +) inherits ntp { file { $config: ensure => file, diff --git a/manifests/init.pp b/manifests/init.pp index f109640..2dd9184 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,61 +1,14 @@ -# Class: ntp -# -# This module manages the ntp service. -# -# Jeff McCune -# 2011-02-23 -# -# Tested platforms: -# - Debian 6.0 Squeeze -# - CentOS 5.4 -# - Amazon Linux 2011.09 -# - FreeBSD 9.0 -# - Archlinux -# -# Parameters: -# -# $servers = [ '0.debian.pool.ntp.org iburst', -# '1.debian.pool.ntp.org iburst', -# '2.debian.pool.ntp.org iburst', -# '3.debian.pool.ntp.org iburst', ] -# -# $restrict = true -# Whether to restrict ntp daemons from allowing others to use as a server. -# -# $autoupdate = false -# Whether to update the ntp package automatically or not. -# -# $enable = true -# Automatically start ntp deamon on boot. -# -# $template = '${module_name}/${config_tpl}' -# Override with your own explicit template. -# -# Actions: -# -# Installs, configures, and manages the ntp service. -# -# Requires: -# -# Sample Usage: -# -# class { "ntp": -# servers => [ 'time.apple.com' ], -# autoupdate => false, -# } -# -# [Remember: No empty lines between comments and class definition] class ntp( $autoupdate = $ntp::params::autoupdate, $config = $ntp::params::config, $config_template = $ntp::params::config_template, - $enable_service = $ntp::params::enable_service, - $ensure_package = $ntp::params::ensure_package, - $ensure_service = $ntp::params::ensure_service, - $manage_service = $ntp::params::manage_service, + $package_ensure = $ntp::params::package_ensure, $package_name = $ntp::params::package_name, $restrict = $ntp::params::restrict, $servers = $ntp::params::servers, + $service_enable = $ntp::params::service_enable, + $service_ensure = $ntp::params::service_ensure, + $service_manage = $ntp::params::service_manage, $service_name = $ntp::params::service_name, ) inherits ntp::params { diff --git a/manifests/install.pp b/manifests/install.pp index b91538a..95d225b 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,10 +1,10 @@ class ntp::install( - $ensure_package = $ntp::ensure_package, + $package_ensure = $ntp::package_ensure, $package_name = $ntp::package_name, -) { +) inherits ntp { package { 'ntp': - ensure => $ensure_package, + ensure => $package_ensure, name => $package_name, } diff --git a/manifests/params.pp b/manifests/params.pp index dd55cd6..7903176 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,10 +1,11 @@ class ntp::params() { $autoupdate = false - $enable_service = true - $ensure_service = 'running' - $ensure_package = 'present' + $package_ensure = 'present' $restrict = true + $service_enable = true + $service_ensure = 'running' + $service_manage = true case $::osfamily { 'Debian': { diff --git a/manifests/service.pp b/manifests/service.pp index 5ec4323..741e65b 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,19 +1,18 @@ class ntp::service ( - $enable_service = $ntp::enable_service, - $ensure_service = $ntp::ensure_service, - $manage_service = $ntp::manage_service, + $service_enable = $ntp::service_enable, + $service_ensure = $ntp::service_ensure, + $service_manage = $ntp::service_manage, $service_name = $ntp::service_name, -) { +) inherits ntp { - if ! ($ensure_service in [ 'running', 'stopped' ]) { - fail('ensure_service parameter must be running or stopped') + if ! ($service_ensure in [ 'running', 'stopped' ]) { + fail('service_ensure parameter must be running or stopped') } - validate_bool($enable_service) - if $manage_service == true { + if $service_manage == true { service { 'ntp': - ensure => $ensure_service, - enable => $enable_service, + ensure => $service_ensure, + enable => $service_enable, name => $service_name, hasstatus => true, hasrestart => true, -- cgit v1.2.3 From 281423586a77943a248b40cd2dea942f33287f26 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 11:28:22 -0400 Subject: Rewrite the README and prepare the CHANGELOG. --- CHANGELOG | 4 ++ README.markdown | 193 +++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 132 insertions(+), 65 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 261fc01..2c45f01 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +2013-07-08 - Version 1.0.0 +Features: +- Completely refactored to split across several classes. + 2011-11-10 Dan Bode - 0.0.4 Add Amazon Linux as a supported platform Add unit tests diff --git a/README.markdown b/README.markdown index 3a84185..a134838 100644 --- a/README.markdown +++ b/README.markdown @@ -1,110 +1,173 @@ -ntp -==== +#ntp -[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-ntp.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-ntp) +####Table of Contents +1. [Overview](#overview) +2. [Module Description - What the module does and why it is useful](#module-description) +3. [Setup - The basics of getting started with ntp](#setup) + * [What ntp affects](#what-ntp-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with ntp](#beginning-with-ntp) +4. [Usage - Configuration options and additional functionality](#usage) +5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +5. [Limitations - OS compatibility, etc.](#limitations) +6. [Development - Guide for contributing to the module](#development) -Overview --------- +##Overview -The NTP module installs, configures, and manages the network time service. +The NTP module installs, configures, and manages the ntp service. +##Module Description -Module Description -------------------- +The NTP module handles running NTP across a range of operating systems and +distributions. Where possible we use the upstream ntp templates so that the +results closely match what you'd get if you modified the package default conf +files. -The NTP module allows Puppet to install, configure, and then manage your Network Time Protocol service. The module allows you to setup and manage time settings across many servers from one place. +##Setup -Setup ------ +###What ntp affects -**What NTP affects:** +* ntp package. +* ntp configuration file. +* ntp service. -* package/service/configuration files for NTP -* server settings - -### Beginning with NTP +###Beginning with ntp -To setup NTP on a server +include '::ntp' is enough to get you up and running. If you wish to pass in +parameters like which servers to use then you can use: - class { "ntp": - servers => [ 'time.apple.com' ], - autoupdate => false, + class { '::ntp': + servers => [ 'ntp1.corp.com', 'ntp2.corp.com' ], } -Usage ------- +##Usage -When making changes to your configuration of NTP, you may need to stop and restart the ntp service. To keep the ntp service stopped, pass ensure => stopped to the class: +All interaction with the ntp module can do be done through the main ntp class. +This means you can simply toggle the options in the ntp class to get at the +full functionality. - class { ntp: - ensure => running, - servers => [ 'time.apple.com iburst', - 'pool.ntp.org iburst' , ] - autoupdate => true, +###I just want NTP, what's the minimum I need? + + include '::ntp' + +###I just want to tweak the servers, nothing else. + + class { '::ntp': + servers => [ 'ntp1.corp.com', 'ntp2.corp.com' ], } -The `ntp` class has several parameters to assist configuration of the ntp service. -**Parameters within `ntp`** +###I'd like to make sure I restrict who can connect as well. -####`servers` + class { '::ntp': + servers => [ 'ntp1.corp.com', 'ntp2.corp.com' ], + restrict => 'restrict 127.0.0.1', + } -NTP will use your operating system's default server if this parameter is left unspecified. This parameter accepts an array of servers, - - class { 'ntp': - servers => [ '0.debian.pool.ntp.org iburst', - '1.debian.pool.ntp.org iburst', - '2.debian.pool.ntp.org iburst', - '3.debian.pool.ntp.org iburst', ] +###I'd like to opt out of having the service controlled, we use another tool for that. + + class { '::ntp': + servers => [ 'ntp1.corp.com', 'ntp2.corp.com' ], + restrict => 'restrict 127.0.0.1', + manage_service => false, } -####`restrict` +###Looks great! But I'd like a different template, we need to do something unique here. + + class { '::ntp': + servers => [ 'ntp1.corp.com', 'ntp2.corp.com' ], + restrict => 'restrict 127.0.0.1', + manage_service => false, + config_template => 'different/module/custom.template.erb', + } -This parameter specifies whether to restrict ntp daemons from allowing others to use as a server. +##Reference + +###Classes + +* ntp: Main class, includes all the rest. +* ntp::install: Handles the packages. +* ntp::config: Handles the configuration file. +* ntp::service: Handles the service. + +###Parameters + +The following parameters are available in the ntp module ####`autoupdate` -This parameter is used to determine whether the ntp package will be updated automatically or not. +Deprecated: This parameter previously determined if the ntp module should be +automatically updated to the latest version available. Replaced by package\_ +ensure. + +####`config` + +This sets the file to write ntp configuration into. + +####`config_template` + +This determines which template puppet should use for the ntp configuration. -####`enable` +####`package_ensure` -This parameter allows you to choose whether to automatically start ntp daemon on boot. +This can be set to 'present' or 'latest' or a specific version to choose the +ntp package to be installed. -####`template` +####`package_name` -This parameter allows you to explicitly override the template used. +This determines the name of the package to install. +####`restrict` + +This sets the restrict options in the ntp configuration. + +####`servers` + +This selects the servers to use for ntp peers. + +####`service_enable` + +This determines if the service should be enabled at boot. + +####`service_ensure` + +This determines if the service should be running or not. -Limitations ------------- +####`service_manage` -This module has been built and tested using Puppet 2.6.x, 2.7, and 3.x. +This selects if puppet should manage the service in the first place. + +####`service_name` + +This selects the name of the ntp service for puppet to manage. + + +##Limitations + +This module has been built on and tested against Puppet 2.7 and higher. The module has been tested on: -* Enterprise Linux 5 -* Debian 6.0 -* CentOS 5.4. +* RedHat Enterprise Linux 5/6 +* Debian 6/7 +* CentOS 5/6. * Ubuntu 12.04 +* Gentoo +* Arch Linux +* FreeBSD Testing on other platforms has been light and cannot be guaranteed. -Development ------------- +##Development -Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. +Puppet Labs modules on the Puppet Forge are open projects, and community +contributions are essential for keeping them great. We can’t access the +huge number of platforms and myriad of hardware, software, and deployment +configurations that Puppet is intended to serve. -We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. +We want to keep it as easy as possible to contribute changes so that our +modules work in your environment. There are a few guidelines that we need +contributors to follow so that we can have a chance of keeping on top of things. You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing) - -Release Notes --------------- - -**0.2.0** - -0.2.0 is a backwards compatible feature and bug-fix release. Since -0.1.0, support for Amazon Linux was added, fixes for style were -implemented, and support was added for tinker_panic. tinker_panic -will default to on when the fact is_virtual is true. -- cgit v1.2.3 From 626e988e636d1615f514e4e3eb58a8f0ae047e4a Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 11:50:43 -0400 Subject: Add rspec-system framework. --- .nodeset.yml | 35 +++++++++++++++++++++++++++++++++++ Gemfile | 9 +++++++-- Rakefile | 2 +- spec/spec_helper_system.rb | 26 ++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 .nodeset.yml create mode 100644 spec/spec_helper_system.rb diff --git a/.nodeset.yml b/.nodeset.yml new file mode 100644 index 0000000..cbd0d57 --- /dev/null +++ b/.nodeset.yml @@ -0,0 +1,35 @@ +--- +default_set: 'centos-64-x64' +sets: + 'centos-59-x64': + nodes: + "main.foo.vm": + prefab: 'centos-59-x64' + 'centos-64-x64': + nodes: + "main.foo.vm": + prefab: 'centos-64-x64' + 'fedora-18-x64': + nodes: + "main.foo.vm": + prefab: 'fedora-18-x64' + 'debian-607-x64': + nodes: + "main.foo.vm": + prefab: 'debian-607-x64' + 'debian-70rc1-x64': + nodes: + "main.foo.vm": + prefab: 'debian-70rc1-x64' + 'ubuntu-server-10044-x64': + nodes: + "main.foo.vm": + prefab: 'ubuntu-server-10044-x64' + 'ubuntu-server-12042-x64': + nodes: + "main.foo.vm": + prefab: 'ubuntu-server-12042-x64' + 'sles-11sp1-x64': + nodes: + "main.foo.vm": + prefab: 'sles-11sp1-x64' diff --git a/Gemfile b/Gemfile index 8e5e04d..42962fc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,12 @@ -source :rubygems +source 'https://rubygems.org' group :development, :test do - gem 'puppetlabs_spec_helper', :require => false + gem 'rake', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'rspec-system-puppet', :require => false + gem 'puppet-lint', :require => false + gem 'serverspec', :require => false + gem 'rspec-system-serverspec', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index 14f1c24..bb60173 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,2 @@ -require 'rubygems' require 'puppetlabs_spec_helper/rake_tasks' +require 'rspec-system/rake_task' diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb new file mode 100644 index 0000000..d520846 --- /dev/null +++ b/spec/spec_helper_system.rb @@ -0,0 +1,26 @@ +require 'rspec-system/spec_helper' +require 'rspec-system-puppet/helpers' +require 'rspec-system-serverspec/helpers' +include Serverspec::Helper::RSpecSystem +include Serverspec::Helper::DetectOS +include RSpecSystemPuppet::Helpers + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Enable colour + c.tty = true + + c.include RSpecSystemPuppet::Helpers + + # This is where we 'setup' the nodes before running our tests + c.before :suite do + # Install puppet + puppet_install + + # Install modules and dependencies + puppet_module_install(:source => proj_root, :module_name => 'ntp') + shell('puppet module install puppetlabs-stdlib') + end +end -- cgit v1.2.3 From 19b140786a6483a02b96d60605dc257d3625d3b7 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 12:22:18 -0400 Subject: Add some basic tests. --- spec/system/basic_spec.rb | 25 +++++++++++++++++++++++++ spec/system/ntp_install_spec.rb | 11 +++++++++++ 2 files changed, 36 insertions(+) create mode 100644 spec/system/basic_spec.rb create mode 100644 spec/system/ntp_install_spec.rb diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb new file mode 100644 index 0000000..87fedd2 --- /dev/null +++ b/spec/system/basic_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper_system' + +describe 'basic tests:' do + # Using puppet_apply as a subject + context puppet_apply 'notice("foo")' do + its(:stdout) { should =~ /foo/ } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + + # Using puppet_apply as a helper + it 'my class should work with no errors' do + pp = <<-EOS + class { 'ntp': } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end +end + diff --git a/spec/system/ntp_install_spec.rb b/spec/system/ntp_install_spec.rb new file mode 100644 index 0000000..434cf58 --- /dev/null +++ b/spec/system/ntp_install_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper_system' + +describe 'ntp::install class' do + let(:os) { + node.facts['osfamily'] + } + + describe package('ntp') do + it { should be_installed } + end +end -- cgit v1.2.3 From b1bedbe26227680d47250e1f4c542384baa43982 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 16:06:03 -0400 Subject: Improve the rspec-system tests, making sure we test for the package being installed and the config file at least makes basic sense. --- spec/system/basic_spec.rb | 28 ++++++++-------------------- spec/system/class_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ spec/system/ntp_config_spec.rb | 35 +++++++++++++++++++++++++++++++++++ spec/system/ntp_install_spec.rb | 22 +++++++++++++++++++++- 4 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 spec/system/class_spec.rb create mode 100644 spec/system/ntp_config_spec.rb diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb index 87fedd2..7b717a0 100644 --- a/spec/system/basic_spec.rb +++ b/spec/system/basic_spec.rb @@ -1,25 +1,13 @@ require 'spec_helper_system' -describe 'basic tests:' do - # Using puppet_apply as a subject - context puppet_apply 'notice("foo")' do - its(:stdout) { should =~ /foo/ } - its(:stderr) { should be_empty } - its(:exit_code) { should be_zero } - end - - # Using puppet_apply as a helper - it 'my class should work with no errors' do - pp = <<-EOS - class { 'ntp': } - EOS - - # Run it twice and test for idempotency - puppet_apply(pp) do |r| - r.exit_code.should_not == 1 - r.refresh - r.exit_code.should be_zero +# Here we put the more basic fundamental tests, ultra obvious stuff. +describe "basic tests:" do + context 'make sure we have copied the module across' do + # No point diagnosing any more if the module wasn't copied properly + context shell 'ls /etc/puppet/modules/ntp' do + its(:stdout) { should =~ /Modulefile/ } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } end end end - diff --git a/spec/system/class_spec.rb b/spec/system/class_spec.rb new file mode 100644 index 0000000..49dfc64 --- /dev/null +++ b/spec/system/class_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper_system' + +describe "ntp class:" do + context 'should run successfully' do + pp = "class { 'ntp': }" + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + end + + context 'service_ensure => stopped:' do + pp = "class { 'ntp': service_ensure => stopped }" + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + end + + context 'service_ensure => running:' do + pp = "class { 'ntp': service_ensure => running }" + + context puppet_apply(pp) do |r| + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + end +end diff --git a/spec/system/ntp_config_spec.rb b/spec/system/ntp_config_spec.rb new file mode 100644 index 0000000..263bc9d --- /dev/null +++ b/spec/system/ntp_config_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_system' + +describe 'ntp::config class' do + let(:os) { + node.facts['osfamily'] + } + + puppet_apply(%{ + class { 'ntp': } + }) + + case node.facts['osfamily'] + when 'FreeBSD' + line = '0.freebsd.pool.ntp.org iburst maxpoll 9' + when 'Debian' + line = '0.debian.pool.ntp.org iburst' + when 'RedHat' + line = '0.centos.pool.ntp.org' + when 'SuSE' + line = '0.opensuse.pool.ntp.org' + when 'Linux' + case node.facts['operatingsystem'] + when 'ArchLinux' + line = '0.pool.ntp.org' + when 'Gentoo' + line = '0.gentoo.pool.ntp.org' + end + end + + describe file('/etc/ntp.conf') do + it { should be_file } + it { should contain line } + end + +end diff --git a/spec/system/ntp_install_spec.rb b/spec/system/ntp_install_spec.rb index 434cf58..39759c5 100644 --- a/spec/system/ntp_install_spec.rb +++ b/spec/system/ntp_install_spec.rb @@ -1,11 +1,31 @@ require 'spec_helper_system' + describe 'ntp::install class' do let(:os) { node.facts['osfamily'] } - describe package('ntp') do + case node.facts['osfamily'] + when 'FreeBSD' + packagename = 'net/ntp' + when 'Linux' + case node.facts['operatingsystem'] + when 'ArchLinux' + packagename = 'ntp' + when 'Gentoo' + packagename = 'net-misc/ntp' + end + else + packagename = 'ntp' + end + + puppet_apply(%{ + class { 'ntp': } + }) + + describe package(packagename) do it { should be_installed } end + end -- cgit v1.2.3 From f6d637e2394e8ad36a8f67aefaa4e050d2a163b4 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 16:24:55 -0400 Subject: Add service checks. --- spec/system/ntp_service_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/system/ntp_service_spec.rb diff --git a/spec/system/ntp_service_spec.rb b/spec/system/ntp_service_spec.rb new file mode 100644 index 0000000..b97e2a4 --- /dev/null +++ b/spec/system/ntp_service_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper_system' + + +describe 'ntp::service class' do + let(:os) { + node.facts['osfamily'] + } + + case node.facts['osfamily'] + when 'RedHat', 'FreeBSD', 'Linux' + servicename = 'ntpd' + else + servicename = 'ntp' + end + + puppet_apply(%{ + class { 'ntp': } + }) + + describe service(servicename) do + it { should be_enabled } + it { should be_running } + end + +end -- cgit v1.2.3 From 85f0869767311900b136b7eeeccaa00ca5b7ed9c Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 16:27:59 -0400 Subject: Fix up travis for more testing. --- .travis.yml | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index c8d205f..6cf27e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,24 +2,39 @@ branches: only: - master -notifications: - email: false language: ruby -script: 'rake spec' +bundler_args: --without development +script: "bundle exec rake spec SPEC_OPTS='--format documentation'" after_success: -- git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-releng -- .forge-releng/publish + - git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-releng + - .forge-releng/publish rvm: - 1.8.7 - 1.9.3 +- 2.0.0 env: matrix: - - PUPPET_VERSION=2.6.18 - - PUPPET_VERSION=2.7.21 - - PUPPET_VERSION=3.1.1 + - PUPPET_GEM_VERSION="~> 2.7.0" + - PUPPET_GEM_VERSION="~> 3.0.0" + - PUPPET_GEM_VERSION="~> 3.1.0" + - PUPPET_GEM_VERSION="~> 3.2.0" global: - - PUBLISHER_LOGIN=puppetlabs - - secure: |- - ZiIkYd9+CdPzpwSjFPnVkCx1FIlipxpbdyD33q94h2Tj5zXjNb1GXizVy0NR - kVxGhU5Ld8y9z8DTqKRgCI1Yymg3H//OU++PKLOQj/X5juWVR4URBNPeBOzu - IJBDl1MADKA4i1+jAZPpz4mTvTtKS4pWKErgCSmhSfsY1hs7n6c= + - PUBLISHER_LOGIN=puppetlabs + - secure: |- + MO4pB4bqBQJjm2yFHf3Mgho+y0Qv4GmMxTMhzI02tGy1V0HMtruZbR7EBN0i + n2CiR7V9V0mNR7/ymzDMF9yVBcgqyXMsp/C6u992Dd0U63ZwFpbRWkxuAeEY + ioupWBkiczjVEo+sxn+gVOnx28pcH/X8kDWbr6wFOMIjO03K66Y= +matrix: + exclude: + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 2.7.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 2.7.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.0.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.1.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 3.2.0" +notifications: + email: false -- cgit v1.2.3 From 43b484c7ab6f92c9eae165982ba127e3d3a87a2e Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 16:29:28 -0400 Subject: Fix up changelog. --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 2c45f01..f567ad1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ 2013-07-08 - Version 1.0.0 Features: - Completely refactored to split across several classes. +- rspec-puppet tests rewritten to cover more options. +- rspec-system tests added. +- autoupdate deprecated in favor of directly setting package_ensure. 2011-11-10 Dan Bode - 0.0.4 Add Amazon Linux as a supported platform -- cgit v1.2.3 From 5fd66d38ed79bb42c64ff68f26a43e71207476ef Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 16:59:43 -0400 Subject: Add panic as a new parameter in case people want to allow clock skews. --- CHANGELOG | 4 +++- README.markdown | 6 ++++++ manifests/config.pp | 1 + manifests/init.pp | 1 + manifests/params.pp | 6 ++++++ spec/classes/ntp_config_spec.rb | 26 ++++++++++++++++++++++++-- templates/ntp.conf.archlinux.erb | 6 ++++++ templates/ntp.conf.debian.erb | 2 +- templates/ntp.conf.el.erb | 2 +- templates/ntp.conf.freebsd.erb | 5 ++--- templates/ntp.conf.gentoo.erb | 5 +++++ templates/ntp.conf.suse.erb | 6 +++--- 12 files changed, 59 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f567ad1..b176e46 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,9 @@ Features: - Completely refactored to split across several classes. - rspec-puppet tests rewritten to cover more options. - rspec-system tests added. -- autoupdate deprecated in favor of directly setting package_ensure. +- parameters in `ntp` class: + - `autoupdate`: deprecated in favor of directly setting package_ensure. + - `panic`: set to false if you wish to allow large clock skews. 2011-11-10 Dan Bode - 0.0.4 Add Amazon Linux as a supported platform diff --git a/README.markdown b/README.markdown index a134838..c7b71e5 100644 --- a/README.markdown +++ b/README.markdown @@ -118,6 +118,12 @@ ntp package to be installed. This determines the name of the package to install. +####`panic` + +This determines if ntp should 'panic' in the event of a very large clock skew. +We set this to false if you're on a virtual machine by default as they don't +do a great job with keeping time. + ####`restrict` This sets the restrict options in the ntp configuration. diff --git a/manifests/config.pp b/manifests/config.pp index 80368f0..b34ef4f 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,6 +1,7 @@ class ntp::config( $config = $ntp::config, $config_template = $ntp::config_template, + $panic = $ntp::panic, $restrict = $ntp::restrict, $servers = $ntp::servers, ) inherits ntp { diff --git a/manifests/init.pp b/manifests/init.pp index 2dd9184..6d594c3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -4,6 +4,7 @@ class ntp( $config_template = $ntp::params::config_template, $package_ensure = $ntp::params::package_ensure, $package_name = $ntp::params::package_name, + $panic = $ntp::params::panic, $restrict = $ntp::params::restrict, $servers = $ntp::params::servers, $service_enable = $ntp::params::service_enable, diff --git a/manifests/params.pp b/manifests/params.pp index 7903176..3486f6f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -7,6 +7,12 @@ class ntp::params() { $service_ensure = 'running' $service_manage = true + # On virtual machines allow large clock skews. + $panic = $::is_virtual ? { + true => false, + default => true, + } + case $::osfamily { 'Debian': { $config = '/etc/ntp.conf' diff --git a/spec/classes/ntp_config_spec.rb b/spec/classes/ntp_config_spec.rb index ddb9be9..80bee42 100644 --- a/spec/classes/ntp_config_spec.rb +++ b/spec/classes/ntp_config_spec.rb @@ -90,12 +90,12 @@ describe 'ntp::config' do end - describe "for virtual machines" do + describe 'for virtual machines' do let(:params) {{}} let(:facts) {{ :operatingsystem => 'Archlinux', :osfamily => 'Linux', - :isvirtual => 'false' }} + :is_virtual => true }} it 'should not use local clock as a time source' do content = param_value(subject, 'file', '/etc/ntp.conf', 'content') @@ -104,6 +104,28 @@ describe 'ntp::config' do 'fudge 127.127.1.0 stratum 10' ] (content.split("\n") & expected_lines).should_not == expected_lines end + + it 'allows large clock skews' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ 'tinker panic 0' ] + (content.split("\n") & expected_lines).should == expected_lines + end + + end + + describe 'for physical machines' do + + let(:params) {{}} + let(:facts) {{ :operatingsystem => 'Archlinux', + :osfamily => 'Linux', + :is_virtual => false }} + + it 'disallows large clock skews' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ 'tinker panic 0' ] + (content.split("\n") & expected_lines).should_not == expected_lines + end + end describe "for operating system Archlinux" do diff --git a/templates/ntp.conf.archlinux.erb b/templates/ntp.conf.archlinux.erb index 22395d9..ef3b725 100644 --- a/templates/ntp.conf.archlinux.erb +++ b/templates/ntp.conf.archlinux.erb @@ -4,6 +4,12 @@ # - the ntp.conf man page # - http://support.ntp.org/bin/view/Support/GettingStarted # - https://wiki.archlinux.org/index.php/Network_Time_Protocol_daemon +# +<% if @panic == false -%> +# Keep ntpd from panicking in the event of a large clock skew +# # when a VM guest is suspended and resumed. +tinker panic 0 +<% end -%> # Associate to public NTP pool servers; see http://www.pool.ntp.org/ <% [@servers].flatten.each do |server| -%> diff --git a/templates/ntp.conf.debian.erb b/templates/ntp.conf.debian.erb index 7225fad..324b91c 100644 --- a/templates/ntp.conf.debian.erb +++ b/templates/ntp.conf.debian.erb @@ -1,6 +1,6 @@ # /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help -<% if @is_virtual == "true" -%> +<% if @panic == false -%> # Keep ntpd from panicking in the event of a large clock skew # when a VM guest is suspended and resumed. tinker panic 0 diff --git a/templates/ntp.conf.el.erb b/templates/ntp.conf.el.erb index 4e90569..157b28d 100644 --- a/templates/ntp.conf.el.erb +++ b/templates/ntp.conf.el.erb @@ -1,4 +1,4 @@ -<% if @is_virtual == "true" -%> +<% if @panic == false -%> # Keep ntpd from panicking in the event of a large clock skew # when a VM guest is suspended and resumed. tinker panic 0 diff --git a/templates/ntp.conf.freebsd.erb b/templates/ntp.conf.freebsd.erb index a55ba3d..7fcffb8 100644 --- a/templates/ntp.conf.freebsd.erb +++ b/templates/ntp.conf.freebsd.erb @@ -18,13 +18,12 @@ # The option `maxpoll 9' is used to prevent PLL/FLL flipping on FreeBSD. # # Managed by puppet class { "ntp": servers => [ ... ] } -<% if @is_virtual == "true" -%> - +<% if @panic == false -%> # Keep ntpd from panicking in the event of a large clock skew # when a VM guest is suspended and resumed. tinker panic 0 - <% end -%> + <% [@servers].flatten.each do |server| -%> server <%= server %> <% end -%> diff --git a/templates/ntp.conf.gentoo.erb b/templates/ntp.conf.gentoo.erb index 7b00b46..c22026a 100644 --- a/templates/ntp.conf.gentoo.erb +++ b/templates/ntp.conf.gentoo.erb @@ -6,6 +6,11 @@ # Name of the servers ntpd should sync with # Please respect the access policy as stated by the responsible person. #server ntp.example.tld iburst +<% if @panic == false -%> +# Keep ntpd from panicking in the event of a large clock skew +# # when a VM guest is suspended and resumed. +tinker panic 0 +<% end -%> # Managed by puppet class { "ntp": servers => [ ... ] } <% [@servers].flatten.each do |server| -%> diff --git a/templates/ntp.conf.suse.erb b/templates/ntp.conf.suse.erb index e44e068..1cbe6a2 100644 --- a/templates/ntp.conf.suse.erb +++ b/templates/ntp.conf.suse.erb @@ -29,21 +29,21 @@ ## # server 127.127.8.0 mode 5 prefer -<% if @is_virtual == "false" -%> +<% if @panic == true -%> ## ## Undisciplined Local Clock. This is a fake driver intended for backup ## and when no outside source of synchronized time is available. ## server 127.127.1.0 # local clock (LCL) fudge 127.127.1.0 stratum 10 # LCL is unsynchronized - <% end -%> + # Managed by puppet class { "ntp": servers => [ ... ] } <% [@servers].flatten.each do |server| -%> server <%= server %> <% end -%> -<% if @is_virtual == "true" -%> +<% if @panic == false -%> # Keep ntpd from panicking in the event of a large clock skew # when a VM guest is suspended and resumed. tinker panic 0 -- cgit v1.2.3 From b9ab67401404d13e535d815c8a3eafb78cf143fd Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 9 Jul 2013 17:08:36 -0400 Subject: Bump to rc candidate. --- Modulefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modulefile b/Modulefile index 7755b15..05eb667 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'puppetlabs-ntp' -version '0.3.0' +version '1.0.0rc1' source 'git://github.com/puppetlabs/puppetlabs-ntp' author 'Puppet Labs' license 'Apache Version 2.0' -- cgit v1.2.3