From 4fdc2e2a248339b6c6589ef5c1c98bf1e6415a92 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Sun, 7 Dec 2014 11:18:09 +0100 Subject: [PATCH] Add Puppet module timezone The module timezone is needed to make the timezone configurable in Packstack. The module is available at https://github.com/saz/puppet-timezone. This module update commit was generated by Bade. For more info please check https://github.com/paramite/bade This commit is setting modules to following state: timezone - initial commit: e82cd1b32f395217056df492e5a7dac8dc5c683a --- Puppetfile | 4 + timezone/.fixtures.yml | 7 + timezone/.gitignore | 6 + timezone/.rspec | 3 + timezone/.travis.yml | 37 +++++ timezone/Gemfile | 16 ++ timezone/LICENSE | 202 +++++++++++++++++++++++ timezone/README.md | 23 +++ timezone/Rakefile | 24 +++ timezone/manifests/init.pp | 102 ++++++++++++ timezone/manifests/params.pp | 53 ++++++ timezone/metadata.json | 52 ++++++ timezone/spec/classes/timezone_spec.rb | 9 + timezone/spec/spec_helper.rb | 8 + timezone/spec/support/debian.rb | 45 +++++ timezone/spec/support/gentoo.rb | 44 +++++ timezone/spec/support/redhat.rb | 45 +++++ timezone/spec/support/validate_params.rb | 10 ++ timezone/templates/clock.erb | 1 + timezone/templates/timezone.erb | 1 + timezone/tests/init.pp | 1 + 21 files changed, 693 insertions(+) create mode 100644 timezone/.fixtures.yml create mode 100644 timezone/.gitignore create mode 100644 timezone/.rspec create mode 100644 timezone/.travis.yml create mode 100644 timezone/Gemfile create mode 100644 timezone/LICENSE create mode 100644 timezone/README.md create mode 100644 timezone/Rakefile create mode 100644 timezone/manifests/init.pp create mode 100644 timezone/manifests/params.pp create mode 100644 timezone/metadata.json create mode 100644 timezone/spec/classes/timezone_spec.rb create mode 100644 timezone/spec/spec_helper.rb create mode 100644 timezone/spec/support/debian.rb create mode 100644 timezone/spec/support/gentoo.rb create mode 100644 timezone/spec/support/redhat.rb create mode 100644 timezone/spec/support/validate_params.rb create mode 100644 timezone/templates/clock.erb create mode 100644 timezone/templates/timezone.erb create mode 100644 timezone/tests/init.pp diff --git a/Puppetfile b/Puppetfile index 5443cd288..b914eed38 100644 --- a/Puppetfile +++ b/Puppetfile @@ -162,6 +162,10 @@ mod 'tempest', :commit => '7a3369949fc8af41e190dd8115391354a7575ecb', :git => 'https://github.com/stackforge/puppet-tempest.git' +mod 'timezone', + :commit => 'e82cd1b32f395217056df492e5a7dac8dc5c683a', + :git => 'https://github.com/saz/puppet-timezone.git' + mod 'vcsrepo', :commit => '6f7507a2a48ff0a58c7db026760a2eb84e382a77', :git => 'https://github.com/puppetlabs/puppetlabs-vcsrepo.git' diff --git a/timezone/.fixtures.yml b/timezone/.fixtures.yml new file mode 100644 index 000000000..5f2717c23 --- /dev/null +++ b/timezone/.fixtures.yml @@ -0,0 +1,7 @@ +fixtures: + repositories: + stdlib: + repo: https://github.com/puppetlabs/puppetlabs-stdlib.git + ref: 4.1.0 + symlinks: + timezone: "#{source_dir}" diff --git a/timezone/.gitignore b/timezone/.gitignore new file mode 100644 index 000000000..559171ed1 --- /dev/null +++ b/timezone/.gitignore @@ -0,0 +1,6 @@ +pkg/ +*.swp +Gemfile.lock +spec/fixtures +/coverage/ +.vagrant diff --git a/timezone/.rspec b/timezone/.rspec new file mode 100644 index 000000000..6278ec5c1 --- /dev/null +++ b/timezone/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--tty diff --git a/timezone/.travis.yml b/timezone/.travis.yml new file mode 100644 index 000000000..ef0bc9871 --- /dev/null +++ b/timezone/.travis.yml @@ -0,0 +1,37 @@ +--- +branches: + only: + - master +language: ruby +bundler_args: --without development +script: bundle exec rake test +after_success: + - git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-releng + - .forge-releng/publish +rvm: + - 1.8.7 + - 1.9.3 +env: + matrix: + - PUPPET_GEM_VERSION="~> 2.7.0" + - PUPPET_GEM_VERSION="~> 3.0.0" + - PUPPET_GEM_VERSION="~> 3.1.0" + - PUPPET_GEM_VERSION="~> 3.2.0" + - PUPPET_GEM_VERSION="~> 3.3.0" + - PUPPET_GEM_VERSION="~> 3.4.0" + global: + - PUBLISHER_LOGIN=saz + - secure: |- + XYhK2TXSAjVeXWONjNpxKrKA6ogF5kazF/81eP5i0FzRoXUI+yemSYsrlA8oIRZjL6qrfCIT + UYKBYeySBrJ4qM9K36mTiqOx1VuevAuM8GRTy4h52lx0MHa/puFvHwKbMbjkBVurhyyZg8mL + cAtGs+KU2/oehrdBgyVfgQ08M9E= +matrix: + include: + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.2.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.3.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.4.0" +notifications: + email: false diff --git a/timezone/Gemfile b/timezone/Gemfile new file mode 100644 index 000000000..d7dce9471 --- /dev/null +++ b/timezone/Gemfile @@ -0,0 +1,16 @@ +source 'https://rubygems.org' + +group :development, :test do + gem 'rake', :require => false + gem 'puppet-lint', :require => false + gem 'puppet-syntax', :require => false + gem 'rspec-puppet', :require => false, :git => 'https://github.com/rodjek/rspec-puppet.git' + gem 'rspec', '< 3.0.0', :require => false + gem 'puppetlabs_spec_helper', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end diff --git a/timezone/LICENSE b/timezone/LICENSE new file mode 100644 index 000000000..57bc88a15 --- /dev/null +++ b/timezone/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/timezone/README.md b/timezone/README.md new file mode 100644 index 000000000..246964411 --- /dev/null +++ b/timezone/README.md @@ -0,0 +1,23 @@ +# puppet-timezone [![Build Status](https://secure.travis-ci.org/saz/puppet-timezone.png)](http://travis-ci.org/saz/puppet-timezone) + +Manage timezone settings via Puppet + +## Usage + +### Set timezone to UTC +``` + class { 'timezone': + timezone => 'UTC', + } +``` + +### Set timezone to Europe/Berlin +``` + class { 'timezone': + timezone => 'Europe/Berlin', + } +``` + +## Other class parameters +* ensure: present or absent, default: present +* autoupgrade: true or false, default: false. Auto-upgrade package, if there is a newer version diff --git a/timezone/Rakefile b/timezone/Rakefile new file mode 100644 index 000000000..cf5bfdbca --- /dev/null +++ b/timezone/Rakefile @@ -0,0 +1,24 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-syntax/tasks/puppet-syntax' +require 'puppet-lint/tasks/puppet-lint' + +exclude_paths = [ + "pkg/**/*", + "vendor/**/*", + "spec/**/*", +] + +PuppetLint.configuration.send("disable_80chars") +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" +PuppetLint.configuration.fail_on_warnings = true + +PuppetLint.configuration.ignore_paths = exclude_paths +PuppetSyntax.exclude_paths = exclude_paths + +desc "Run syntax, lint, and spec tests." +task :test => [ + :syntax, + :lint, + :spec, +] diff --git a/timezone/manifests/init.pp b/timezone/manifests/init.pp new file mode 100644 index 000000000..1ee1bd074 --- /dev/null +++ b/timezone/manifests/init.pp @@ -0,0 +1,102 @@ +# Class: timezone +# +# This module manages timezone settings +# +# Parameters: +# [*timezone*] +# The name of the timezone. +# Default: UTC +# +# [*ensure*] +# Ensure if present or absent. +# Default: present +# +# [*autoupgrade*] +# Upgrade package automatically, if there is a newer version. +# Default: false +# +# [*package*] +# Name of the package. +# Only set this, if your platform is not supported or you know, what you're doing. +# Default: auto-set, platform specific +# +# [*config_file*] +# Main configuration file. +# Only set this, if your platform is not supported or you know, what you're doing. +# Default: auto-set, platform specific +# +# [*zoneinfo_dir*] +# Source directory of zoneinfo files. +# Only set this, if your platform is not supported or you know, what you're doing. +# Default: auto-set, platform specific +# +# Actions: +# Installs tzdata and configures timezone +# +# Requires: +# Nothing +# +# Sample Usage: +# class { 'timezone': +# timezone => 'Europe/Berlin', +# } +# +# [Remember: No empty lines between comments and class definition] +class timezone ( + $ensure = 'present', + $timezone = 'UTC', + $autoupgrade = false +) inherits timezone::params { + + validate_bool($autoupgrade) + + case $ensure { + /(present)/: { + if $autoupgrade == true { + $package_ensure = 'latest' + } else { + $package_ensure = 'present' + } + $localtime_ensure = 'link' + $timezone_ensure = 'file' + } + /(absent)/: { + # Leave package installed, as it is a system dependency + $package_ensure = 'present' + $localtime_ensure = 'absent' + $timezone_ensure = 'absent' + } + default: { + fail('ensure parameter must be present or absent') + } + } + + package { $timezone::params::package: + ensure => $package_ensure, + } + + if $timezone::params::timezone_file != false { + file { $timezone::params::timezone_file: + ensure => $timezone_ensure, + content => template($timezone::params::timezone_file_template), + } + if $ensure == 'present' and $timezone::params::timezone_update { + $e_command = $::osfamily ? { + /(Suse|Archlinux)/ => "${timezone::params::timezone_update} ${timezone}", + default => $timezone::params::timezone_update + } + exec { 'update_timezone': + command => $e_command, + path => '/usr/bin:/usr/sbin:/bin:/sbin', + subscribe => File[$timezone::params::timezone_file], + refreshonly => true, + } + } + } + + file { $timezone::params::localtime_file: + ensure => $localtime_ensure, + target => "${timezone::params::zoneinfo_dir}${timezone}", + require => Package[$timezone::params::package], + } +} diff --git a/timezone/manifests/params.pp b/timezone/manifests/params.pp new file mode 100644 index 000000000..3d994900b --- /dev/null +++ b/timezone/manifests/params.pp @@ -0,0 +1,53 @@ +# Class: timezone::params +# +# Defines all the variables used in the module. +# +class timezone::params { + case $::osfamily { + 'Debian': { + $package = 'tzdata' + $zoneinfo_dir = '/usr/share/zoneinfo/' + $localtime_file = '/etc/localtime' + $timezone_file = '/etc/timezone' + $timezone_file_template = 'timezone/timezone.erb' + $timezone_update = 'dpkg-reconfigure -f noninteractive tzdata' + } + 'RedHat': { + $package = 'tzdata' + $zoneinfo_dir = '/usr/share/zoneinfo/' + $localtime_file = '/etc/localtime' + $timezone_file = '/etc/sysconfig/clock' + $timezone_file_template = 'timezone/clock.erb' + $timezone_update = false + } + 'Gentoo': { + $package = 'sys-libs/timezone-data' + $zoneinfo_dir = '/usr/share/zoneinfo/' + $localtime_file = '/etc/localtime' + $timezone_file = '/etc/timezone' + $timezone_file_template = 'timezone/timezone.erb' + $timezone_update = 'emerge --config timezone-data' + } + 'Archlinux': { + $package = 'tzdata' + $zoneinfo_dir = '/usr/share/zoneinfo/' + $localtime_file = '/etc/localtime' + $timezone_file = false + $timezone_update = 'timedatectl set-timezone ' + } + 'Suse': { + $package = 'timezone' + $zoneinfo_dir = '/usr/share/zoneinfo/' + $localtime_file = '/etc/localtime' + $timezone_file = false + $timezone_update = 'zic -l ' + } + default: { + case $::operatingsystem { + default: { + fail("Unsupported platform: ${::osfamily}/${::operatingsystem}") + } + } + } + } +} diff --git a/timezone/metadata.json b/timezone/metadata.json new file mode 100644 index 000000000..1a771ebf5 --- /dev/null +++ b/timezone/metadata.json @@ -0,0 +1,52 @@ +{ + "operatingsystem_support": [ + { + "operatingsystem": "RedHat" + }, + { + "operatingsystem": "CentOS" + }, + { + "operatingsystem": "OracleLinux" + }, + { + "operatingsystem": "Scientific" + }, + { + "operatingsystem": "Debian" + }, + { + "operatingsystem": "Ubuntu" + }, + { + "operatingsystem": "Gentoo" + }, + { + "operatingsystem": "ArchLinux" + } + ], + "requirements": [ + { + "name": "pe", + "version_requirement": "3.2.x" + }, + { + "name": "puppet", + "version_requirement": "3.x" + } + ], + "name": "saz-timezone", + "version": "3.1.1", + "source": "git://github.com/saz/puppet-timezone", + "author": "saz", + "license": "Apache License, Version 2.0", + "summary": "UNKNOWN", + "description": "Manage timezone settings via Puppet", + "project_page": "https://github.com/saz/puppet-timezone", + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 2.3.0" + } + ] +} diff --git a/timezone/spec/classes/timezone_spec.rb b/timezone/spec/classes/timezone_spec.rb new file mode 100644 index 000000000..59146cf6d --- /dev/null +++ b/timezone/spec/classes/timezone_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe 'timezone' do + ['Debian','RedHat','Gentoo'].each do |osfamily| + describe "on supported osfamily: #{osfamily}" do + include_examples osfamily + end + end +end diff --git a/timezone/spec/spec_helper.rb b/timezone/spec/spec_helper.rb new file mode 100644 index 000000000..c2f9f56f9 --- /dev/null +++ b/timezone/spec/spec_helper.rb @@ -0,0 +1,8 @@ +require 'puppetlabs_spec_helper/module_spec_helper' +require 'pathname' + +dir = Pathname.new(__FILE__).parent +# Load all shared contexts and shared examples +Dir["#{dir}/support/**/*.rb"].sort.each {|f| require f} + +at_exit { RSpec::Puppet::Coverage.report! } diff --git a/timezone/spec/support/debian.rb b/timezone/spec/support/debian.rb new file mode 100644 index 000000000..23e465717 --- /dev/null +++ b/timezone/spec/support/debian.rb @@ -0,0 +1,45 @@ +shared_examples 'Debian' do + let(:facts) {{ :osfamily => "Debian" }} + + describe "when using default class parameters" do + let(:params) {{ }} + + it { should create_class('timezone') } + it { should contain_class('timezone::params') } + + it { should contain_package('tzdata').with_ensure('present') } + + it { should contain_file('/etc/timezone').with_ensure('file') } + it { should contain_file('/etc/timezone').with_content(/^UTC$/) } + it { should contain_exec('update_timezone').with_command(/^dpkg-reconfigure -f noninteractive tzdata$/) } + + it do + should contain_file('/etc/localtime').with({ + :ensure => 'link', + :target => '/usr/share/zoneinfo/UTC', + :require => "Package[tzdata]", + }) + end + + context 'when timezone => "Europe/Berlin"' do + let(:params) {{ :timezone => "Europe/Berlin" }} + + it { should contain_file('/etc/timezone').with_content(/^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 }} + it { should contain_package('tzdata').with_ensure('latest') } + end + + context 'when ensure => absent' do + let(:params) {{ :ensure => 'absent' }} + it { should contain_package('tzdata').with_ensure('present') } + it { should contain_file('/etc/timezone').with_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 new file mode 100644 index 000000000..29fb88677 --- /dev/null +++ b/timezone/spec/support/gentoo.rb @@ -0,0 +1,44 @@ +shared_examples 'Gentoo' do + let(:facts) {{ :osfamily => "Gentoo" }} + + describe "when using default class parameters" do + let(:params) {{ }} + + it { should create_class('timezone') } + it { should contain_class('timezone::params') } + + it { should contain_package('sys-libs/timezone-data').with_ensure('present') } + + it { should contain_file('/etc/timezone').with_ensure('file') } + it { should contain_file('/etc/timezone').with_content(/^UTC$/) } + it { should contain_exec('update_timezone').with_command(/^emerge --config timezone-data$/) } + it do + should contain_file('/etc/localtime').with({ + :ensure => 'link', + :target => '/usr/share/zoneinfo/UTC', + :require => "Package[sys-libs/timezone-data]", + }) + end + + context 'when timezone => "Europe/Berlin"' do + let(:params) {{ :timezone => "Europe/Berlin" }} + + it { should contain_file('/etc/timezone').with_content(/^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 }} + it { should contain_package('sys-libs/timezone-data').with_ensure('latest') } + end + + context 'when ensure => absent' do + let(:params) {{ :ensure => 'absent' }} + it { should contain_package('sys-libs/timezone-data').with_ensure('present') } + it { should contain_file('/etc/timezone').with_ensure('absent') } + it { should contain_file('/etc/localtime').with_ensure('absent') } + end + + include_examples 'validate parameters' + end +end diff --git a/timezone/spec/support/redhat.rb b/timezone/spec/support/redhat.rb new file mode 100644 index 000000000..bc1067bab --- /dev/null +++ b/timezone/spec/support/redhat.rb @@ -0,0 +1,45 @@ +shared_examples 'RedHat' do + let(:facts) {{ :osfamily => "RedHat" }} + + describe "when using default class parameters" do + let(:params) {{ }} + + it { should create_class('timezone') } + it { should contain_class('timezone::params') } + + it { should contain_package('tzdata').with_ensure('present') } + + it { should contain_file('/etc/sysconfig/clock').with_ensure('file') } + it { should contain_file('/etc/sysconfig/clock').with_content(/^ZONE="UTC"$/) } + it { should_not contain_exec('update_timezone') } + + it do + should contain_file('/etc/localtime').with({ + :ensure => 'link', + :target => '/usr/share/zoneinfo/UTC', + :require => "Package[tzdata]", + }) + end + + context 'when timezone => "Europe/Berlin"' do + let(:params) {{ :timezone => "Europe/Berlin" }} + + it { should contain_file('/etc/sysconfig/clock').with_content(/^ZONE="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 }} + it { should contain_package('tzdata').with_ensure('latest') } + end + + context 'when ensure => absent' do + let(:params) {{ :ensure => 'absent' }} + it { should contain_package('tzdata').with_ensure('present') } + it { should contain_file('/etc/sysconfig/clock').with_ensure('absent') } + it { should contain_file('/etc/localtime').with_ensure('absent') } + end + + include_examples 'validate parameters' + end +end diff --git a/timezone/spec/support/validate_params.rb b/timezone/spec/support/validate_params.rb new file mode 100644 index 000000000..a49540fb2 --- /dev/null +++ b/timezone/spec/support/validate_params.rb @@ -0,0 +1,10 @@ +shared_examples_for 'validate parameters' do + [ + 'autoupgrade', + ].each do |param| + context "with #{param} => 'foo'" do + let(:params) {{ param.to_sym => 'foo' }} + it { expect { should create_class('timezone') }.to raise_error(Puppet::Error, /is not a boolean/) } + end + end +end diff --git a/timezone/templates/clock.erb b/timezone/templates/clock.erb new file mode 100644 index 000000000..513a14ff1 --- /dev/null +++ b/timezone/templates/clock.erb @@ -0,0 +1 @@ +ZONE="<%= @timezone %>" diff --git a/timezone/templates/timezone.erb b/timezone/templates/timezone.erb new file mode 100644 index 000000000..a5606d001 --- /dev/null +++ b/timezone/templates/timezone.erb @@ -0,0 +1 @@ +<%= @timezone %> diff --git a/timezone/tests/init.pp b/timezone/tests/init.pp new file mode 100644 index 000000000..07794dc75 --- /dev/null +++ b/timezone/tests/init.pp @@ -0,0 +1 @@ +include timezone