summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Penney <apenney@gmail.com>2013-07-09 14:10:19 -0700
committerAshley Penney <apenney@gmail.com>2013-07-09 14:10:19 -0700
commit75776217283ba2531d9025b34db567dc06f2ff65 (patch)
treed1e45b40789bb77cf88ca38c03ba1a3841d20229
parent451c93a46c42c9659cc0930a301746cf103dbeb2 (diff)
parentb9ab67401404d13e535d815c8a3eafb78cf143fd (diff)
Merge pull request #66 from apenney/refactor-round-1
WIP: Refactoring of NTP module
-rw-r--r--.nodeset.yml35
-rw-r--r--.travis.yml41
-rw-r--r--CHANGELOG9
-rw-r--r--Gemfile9
-rw-r--r--Modulefile4
-rw-r--r--README.markdown199
-rw-r--r--Rakefile2
-rw-r--r--manifests/config.pp17
-rw-r--r--manifests/init.pp203
-rw-r--r--manifests/install.pp11
-rw-r--r--manifests/params.pp99
-rw-r--r--manifests/service.pp22
-rw-r--r--spec/classes/ntp_config_spec.rb183
-rw-r--r--spec/classes/ntp_install_spec.rb72
-rw-r--r--spec/classes/ntp_service_spec.rb73
-rw-r--r--spec/classes/ntp_spec.rb155
-rw-r--r--spec/fixtures/manifests/site.pp0
-rw-r--r--spec/spec_helper_system.rb26
-rw-r--r--spec/system/basic_spec.rb13
-rw-r--r--spec/system/class_spec.rb39
-rw-r--r--spec/system/ntp_config_spec.rb35
-rw-r--r--spec/system/ntp_install_spec.rb31
-rw-r--r--spec/system/ntp_service_spec.rb25
-rw-r--r--templates/ntp.conf.archlinux.erb8
-rw-r--r--templates/ntp.conf.debian.erb4
-rw-r--r--templates/ntp.conf.el.erb4
-rw-r--r--templates/ntp.conf.freebsd.erb7
-rw-r--r--templates/ntp.conf.gentoo.erb59
-rw-r--r--templates/ntp.conf.suse.erb8
29 files changed, 973 insertions, 420 deletions
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/.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
diff --git a/CHANGELOG b/CHANGELOG
index 261fc01..b176e46 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,12 @@
+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.
+- 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 <dan@puppetlabs.com> - 0.0.4
Add Amazon Linux as a supported platform
Add unit tests
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/Modulefile b/Modulefile
index 3b18895..05eb667 100644
--- a/Modulefile
+++ b/Modulefile
@@ -1,10 +1,10 @@
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'
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/README.markdown b/README.markdown
index 3a84185..c7b71e5 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,110 +1,179 @@
-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.
+
+####`package_ensure`
-####`enable`
+This can be set to 'present' or 'latest' or a specific version to choose the
+ntp package to be installed.
-This parameter allows you to choose whether to automatically start ntp daemon on boot.
+####`package_name`
-####`template`
+This determines the name of the package to install.
-This parameter allows you to explicitly override the template used.
+####`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.
-Limitations
-------------
+####`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.
-This module has been built and tested using Puppet 2.6.x, 2.7, and 3.x.
+####`service_manage`
+
+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.
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/manifests/config.pp b/manifests/config.pp
new file mode 100644
index 0000000..b34ef4f
--- /dev/null
+++ b/manifests/config.pp
@@ -0,0 +1,17 @@
+class ntp::config(
+ $config = $ntp::config,
+ $config_template = $ntp::config_template,
+ $panic = $ntp::panic,
+ $restrict = $ntp::restrict,
+ $servers = $ntp::servers,
+) inherits ntp {
+
+ file { $config:
+ ensure => file,
+ owner => 0,
+ group => 0,
+ mode => '0644',
+ content => template($config_template),
+ }
+
+}
diff --git a/manifests/init.pp b/manifests/init.pp
index af1f8d5..6d594c3 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -1,182 +1,33 @@
-# Class: ntp
-#
-# This module manages the ntp service.
-#
-# Jeff McCune <jeff@puppetlabs.com>
-# 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($servers='UNSET',
- $ensure='running',
- $enable=true,
- $restrict=true,
- $config_template=undef,
- $autoupdate=false
-) {
-
- if ! ($ensure in [ 'running', 'stopped' ]) {
- fail('ensure parameter must be running or stopped')
- }
-
- if $autoupdate == true {
- $package_ensure = latest
- } elsif $autoupdate == false {
- $package_ensure = present
- } else {
- fail('autoupdate parameter must be true or false')
- }
-
- 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")
- }
+class ntp(
+ $autoupdate = $ntp::params::autoupdate,
+ $config = $ntp::params::config,
+ $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,
+ $service_ensure = $ntp::params::service_ensure,
+ $service_manage = $ntp::params::service_manage,
+ $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.')
}
- if ($config_template == undef) {
- $template_real = "${module_name}/${config_tpl}"
- } else {
- $template_real = $config_template
- }
+ include '::ntp::install'
+ include '::ntp::config'
+ include '::ntp::service'
- package { 'ntp':
- ensure => $package_ensure,
- name => $pkg_name,
- }
+ # 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': }
- file { $config:
- ensure => file,
- owner => 0,
- group => 0,
- mode => '0644',
- content => template($template_real),
- require => Package[$pkg_name],
- }
+ Anchor['ntp::begin'] -> Class['::ntp::install'] -> Class['::ntp::config']
+ ~> Class['::ntp::service'] -> Anchor['ntp::end']
- service { 'ntp':
- ensure => $ensure,
- enable => $enable,
- name => $svc_name,
- hasstatus => true,
- hasrestart => true,
- subscribe => [ Package[$pkg_name], File[$config] ],
- }
}
diff --git a/manifests/install.pp b/manifests/install.pp
new file mode 100644
index 0000000..95d225b
--- /dev/null
+++ b/manifests/install.pp
@@ -0,0 +1,11 @@
+class ntp::install(
+ $package_ensure = $ntp::package_ensure,
+ $package_name = $ntp::package_name,
+) inherits ntp {
+
+ package { 'ntp':
+ ensure => $package_ensure,
+ name => $package_name,
+ }
+
+}
diff --git a/manifests/params.pp b/manifests/params.pp
new file mode 100644
index 0000000..3486f6f
--- /dev/null
+++ b/manifests/params.pp
@@ -0,0 +1,99 @@
+class ntp::params() {
+
+ $autoupdate = false
+ $package_ensure = 'present'
+ $restrict = true
+ $service_enable = true
+ $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'
+ $config_template = 'ntp/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/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/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/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/ntp.conf.archlinux.erb'
+ $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.")
+ }
+ }
+ }
+ default: {
+ fail("The ${module_name} module is not supported on an ${::osfamily} based system.")
+ }
+ }
+}
diff --git a/manifests/service.pp b/manifests/service.pp
new file mode 100644
index 0000000..741e65b
--- /dev/null
+++ b/manifests/service.pp
@@ -0,0 +1,22 @@
+class ntp::service (
+ $service_enable = $ntp::service_enable,
+ $service_ensure = $ntp::service_ensure,
+ $service_manage = $ntp::service_manage,
+ $service_name = $ntp::service_name,
+) inherits ntp {
+
+ if ! ($service_ensure in [ 'running', 'stopped' ]) {
+ fail('service_ensure parameter must be running or stopped')
+ }
+
+ if $service_manage == true {
+ service { 'ntp':
+ ensure => $service_ensure,
+ enable => $service_enable,
+ name => $service_name,
+ hasstatus => true,
+ hasrestart => true,
+ }
+ }
+
+}
diff --git a/spec/classes/ntp_config_spec.rb b/spec/classes/ntp_config_spec.rb
new file mode 100644
index 0000000..80bee42
--- /dev/null
+++ b/spec/classes/ntp_config_spec.rb
@@ -0,0 +1,183 @@
+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',
+ :is_virtual => true }}
+
+ 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
+
+ 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
+
+ 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 a29c4e4..4ffd817 100644
--- a/spec/classes/ntp_spec.rb
+++ b/spec/classes/ntp_spec.rb
@@ -1,156 +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 unsupported based systems/
- )}
- 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
-
-
- ['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] = 'stopped'
- subject.should contain_service('ntp').with_ensure('stopped')
- end
- it 'should allow package ensure to be overridden' do
- params[:autoupdate] = true
- 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
diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp
deleted file mode 100644
index e69de29..0000000
--- a/spec/fixtures/manifests/site.pp
+++ /dev/null
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
diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb
new file mode 100644
index 0000000..7b717a0
--- /dev/null
+++ b/spec/system/basic_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper_system'
+
+# 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
new file mode 100644
index 0000000..39759c5
--- /dev/null
+++ b/spec/system/ntp_install_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper_system'
+
+
+describe 'ntp::install class' do
+ let(:os) {
+ node.facts['osfamily']
+ }
+
+ 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
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
diff --git a/templates/ntp.conf.archlinux.erb b/templates/ntp.conf.archlinux.erb
index 5e27334..ef3b725 100644
--- a/templates/ntp.conf.archlinux.erb
+++ b/templates/ntp.conf.archlinux.erb
@@ -4,9 +4,15 @@
# - 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_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..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
@@ -26,7 +26,7 @@ filegen clockstats file clockstats type day enable
# 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.el.erb b/templates/ntp.conf.el.erb
index 77c731a..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
@@ -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..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_real].flatten.each do |server| -%>
+
+<% [@servers].flatten.each do |server| -%>
server <%= server %>
<% end -%>
diff --git a/templates/ntp.conf.gentoo.erb b/templates/ntp.conf.gentoo.erb
new file mode 100644
index 0000000..c22026a
--- /dev/null
+++ b/templates/ntp.conf.gentoo.erb
@@ -0,0 +1,59 @@
+# 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
+<% 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| -%>
+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
diff --git a/templates/ntp.conf.suse.erb b/templates/ntp.conf.suse.erb
index 4ce6205..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_real].flatten.each do |server| -%>
+<% [@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