summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-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
11 files changed, 504 insertions, 148 deletions
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