diff --git a/Puppetfile b/Puppetfile index 59b80d7ec..4c261ae6d 100644 --- a/Puppetfile +++ b/Puppetfile @@ -187,7 +187,7 @@ mod 'tempest', :git => 'https://github.com/stackforge/puppet-tempest.git' mod 'timezone', - :commit => 'e82cd1b32f395217056df492e5a7dac8dc5c683a', + :commit => '0b3e3f06c7c3c4e4ab571666cceb7f4779e69856', :git => 'https://github.com/saz/puppet-timezone.git' mod 'tripleo', diff --git a/timezone/manifests/init.pp b/timezone/manifests/init.pp index 1ee1bd074..e01435db8 100644 --- a/timezone/manifests/init.pp +++ b/timezone/manifests/init.pp @@ -30,6 +30,10 @@ # Only set this, if your platform is not supported or you know, what you're doing. # Default: auto-set, platform specific # +# [*hwutc*] +# Is the hardware clock set to UTC? (true or false) +# Default: undefined +# # Actions: # Installs tzdata and configures timezone # @@ -45,6 +49,7 @@ class timezone ( $ensure = 'present', $timezone = 'UTC', + $hwutc = '', $autoupgrade = false ) inherits timezone::params { @@ -71,8 +76,11 @@ } } - package { $timezone::params::package: - ensure => $package_ensure, + if $timezone::params::package { + package { $timezone::params::package: + ensure => $package_ensure, + before => File[$timezone::params::localtime_file], + } } if $timezone::params::timezone_file != false { @@ -95,8 +103,7 @@ } file { $timezone::params::localtime_file: - ensure => $localtime_ensure, - target => "${timezone::params::zoneinfo_dir}${timezone}", - require => Package[$timezone::params::package], + ensure => $localtime_ensure, + target => "${timezone::params::zoneinfo_dir}${timezone}", } } diff --git a/timezone/manifests/params.pp b/timezone/manifests/params.pp index 3d994900b..5aaca5c49 100644 --- a/timezone/manifests/params.pp +++ b/timezone/manifests/params.pp @@ -12,11 +12,18 @@ $timezone_file_template = 'timezone/timezone.erb' $timezone_update = 'dpkg-reconfigure -f noninteractive tzdata' } - 'RedHat': { + 'RedHat', 'Linux': { $package = 'tzdata' $zoneinfo_dir = '/usr/share/zoneinfo/' $localtime_file = '/etc/localtime' - $timezone_file = '/etc/sysconfig/clock' + case $::operatingsystemmajrelease { + '7': { + $timezone_file = false + } + default: { + $timezone_file = '/etc/sysconfig/clock' + } + } $timezone_file_template = 'timezone/clock.erb' $timezone_update = false } @@ -42,6 +49,12 @@ $timezone_file = false $timezone_update = 'zic -l ' } + 'FreeBSD': { + $package = undef + $zoneinfo_dir = '/usr/share/zoneinfo/' + $localtime_file = '/etc/localtime' + $timezone_file = false + } default: { case $::operatingsystem { default: { diff --git a/timezone/metadata.json b/timezone/metadata.json index 1a771ebf5..9a77f80ae 100644 --- a/timezone/metadata.json +++ b/timezone/metadata.json @@ -36,7 +36,7 @@ } ], "name": "saz-timezone", - "version": "3.1.1", + "version": "3.2.0", "source": "git://github.com/saz/puppet-timezone", "author": "saz", "license": "Apache License, Version 2.0", diff --git a/timezone/spec/classes/timezone_spec.rb b/timezone/spec/classes/timezone_spec.rb index 59146cf6d..31292e809 100644 --- a/timezone/spec/classes/timezone_spec.rb +++ b/timezone/spec/classes/timezone_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'timezone' do - ['Debian','RedHat','Gentoo'].each do |osfamily| + ['Debian','RedHat','Gentoo','FreeBSD'].each do |osfamily| describe "on supported osfamily: #{osfamily}" do include_examples osfamily end diff --git a/timezone/spec/support/debian.rb b/timezone/spec/support/debian.rb index 23e465717..921aa0536 100644 --- a/timezone/spec/support/debian.rb +++ b/timezone/spec/support/debian.rb @@ -7,7 +7,12 @@ it { should create_class('timezone') } it { should contain_class('timezone::params') } - it { should contain_package('tzdata').with_ensure('present') } + it do + should contain_package('tzdata').with({ + :ensure => 'present', + :before => "File[/etc/localtime]", + }) + end it { should contain_file('/etc/timezone').with_ensure('file') } it { should contain_file('/etc/timezone').with_content(/^UTC$/) } @@ -17,7 +22,6 @@ should contain_file('/etc/localtime').with({ :ensure => 'link', :target => '/usr/share/zoneinfo/UTC', - :require => "Package[tzdata]", }) end diff --git a/timezone/spec/support/freebsd.rb b/timezone/spec/support/freebsd.rb new file mode 100644 index 000000000..694801ef2 --- /dev/null +++ b/timezone/spec/support/freebsd.rb @@ -0,0 +1,34 @@ +shared_examples 'FreeBSD' do + let(:facts) {{ :osfamily => "FreeBSD" }} + + describe "when using default class parameters" do + let(:params) {{ }} + + it { should create_class('timezone') } + it { should contain_class('timezone::params') } + + it do + should contain_file('/etc/localtime').with({ + :ensure => 'link', + :target => '/usr/share/zoneinfo/UTC', + }) + end + + context 'when timezone => "Europe/Berlin"' do + let(:params) {{ :timezone => "Europe/Berlin" }} + + it { should contain_file('/etc/localtime').with_target('/usr/share/zoneinfo/Europe/Berlin') } + end + + context 'when autoupgrade => true' do + let(:params) {{ :autoupgrade => true }} + end + + context 'when ensure => absent' do + let(:params) {{ :ensure => 'absent' }} + it { should contain_file('/etc/localtime').with_ensure('absent') } + end + + include_examples 'validate parameters' + end +end diff --git a/timezone/spec/support/gentoo.rb b/timezone/spec/support/gentoo.rb index 29fb88677..eaf81923a 100644 --- a/timezone/spec/support/gentoo.rb +++ b/timezone/spec/support/gentoo.rb @@ -7,7 +7,12 @@ it { should create_class('timezone') } it { should contain_class('timezone::params') } - it { should contain_package('sys-libs/timezone-data').with_ensure('present') } + it do + should contain_package('sys-libs/timezone-data').with({ + :ensure => 'present', + :before => 'File[/etc/localtime]', + }) + end it { should contain_file('/etc/timezone').with_ensure('file') } it { should contain_file('/etc/timezone').with_content(/^UTC$/) } @@ -16,7 +21,6 @@ should contain_file('/etc/localtime').with({ :ensure => 'link', :target => '/usr/share/zoneinfo/UTC', - :require => "Package[sys-libs/timezone-data]", }) end diff --git a/timezone/spec/support/redhat.rb b/timezone/spec/support/redhat.rb index bc1067bab..d24ce99f6 100644 --- a/timezone/spec/support/redhat.rb +++ b/timezone/spec/support/redhat.rb @@ -1,5 +1,5 @@ shared_examples 'RedHat' do - let(:facts) {{ :osfamily => "RedHat" }} + let(:facts) {{ :osfamily => "RedHat", :operatingsystemmajrelease => '6' }} describe "when using default class parameters" do let(:params) {{ }} @@ -7,7 +7,13 @@ it { should create_class('timezone') } it { should contain_class('timezone::params') } - it { should contain_package('tzdata').with_ensure('present') } + it do + should contain_package('tzdata').with({ + :ensure => 'present', + :before => 'File[/etc/localtime]', + }) + end + it { should contain_file('/etc/sysconfig/clock').with_ensure('file') } it { should contain_file('/etc/sysconfig/clock').with_content(/^ZONE="UTC"$/) } @@ -17,7 +23,6 @@ should contain_file('/etc/localtime').with({ :ensure => 'link', :target => '/usr/share/zoneinfo/UTC', - :require => "Package[tzdata]", }) end @@ -40,6 +45,11 @@ it { should contain_file('/etc/localtime').with_ensure('absent') } end + context 'when RHEL 7' do + let(:facts) {{ :osfamily => "RedHat", :operatingsystemmajrelease => '7' }} + it { should_not contain_file('/etc/sysconfig/clock').with_ensure('file') } + end + include_examples 'validate parameters' end end diff --git a/timezone/templates/clock.erb b/timezone/templates/clock.erb index 513a14ff1..3c8b18373 100644 --- a/timezone/templates/clock.erb +++ b/timezone/templates/clock.erb @@ -1 +1,5 @@ +# Managed by puppet - do not modify ZONE="<%= @timezone %>" +<% if !@hwutc.empty? -%> +UTC=<%= @hwutc %> +<% end -%> diff --git a/timezone/templates/timezone.erb b/timezone/templates/timezone.erb index a5606d001..51ccdb217 100644 --- a/timezone/templates/timezone.erb +++ b/timezone/templates/timezone.erb @@ -1 +1,2 @@ +# Managed by puppet - do not modify <%= @timezone %>