Added modules

This commit is contained in:
Ciaby 2014-07-11 13:30:23 -05:00
parent c53c931217
commit 59ec520742
646 changed files with 35182 additions and 0 deletions

View file

@ -0,0 +1,37 @@
require 'spec_helper_acceptance'
describe 'ntp class:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
it 'should run successfully' do
pp = "class { 'ntp': }"
# Apply twice to ensure no errors the second time.
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).not_to match(/error/i)
end
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).not_to eq(/error/i)
expect(r.exit_code).to be_zero
end
end
context 'service_ensure => stopped:' do
it 'runs successfully' do
pp = "class { 'ntp': service_ensure => stopped }"
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).not_to match(/error/i)
end
end
end
context 'service_ensure => running:' do
it 'runs successfully' do
pp = "class { 'ntp': service_ensure => running }"
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).not_to match(/error/i)
end
end
end
end

View file

@ -0,0 +1,30 @@
require 'spec_helper_acceptance'
describe "ntp class with disable_monitor:", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'should run successfully' do
pp = "class { 'ntp': disable_monitor => true }"
it 'runs twice' do
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file('/etc/ntp.conf') do
it { should contain('disable monitor') }
end
end
context 'should run successfully' do
pp = "class { 'ntp': disable_monitor => false }"
it 'runs twice' do
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file('/etc/ntp.conf') do
it { should_not contain('disable monitor') }
end
end
end

View file

@ -0,0 +1,12 @@
HOSTS:
centos-64-x64:
roles:
- master
- database
- dashboard
platform: el-6-x86_64
box : centos-64-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: pe

View file

@ -0,0 +1,10 @@
HOSTS:
centos-64-x64:
roles:
- master
platform: el-6-x86_64
box : centos-64-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
centos-65-x64:
roles:
- master
platform: el-6-x86_64
box : centos-65-x64-vbox436-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
centos-64-x64:
roles:
- master
platform: el-6-x86_64
box : centos-64-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
fedora-18-x64:
roles:
- master
platform: fedora-18-x86_64
box : fedora-18-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
sles-11-x64.local:
roles:
- master
platform: sles-11-x64
box : sles-11sp1-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/sles-11sp1-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
ubuntu-server-10044-x64:
roles:
- master
platform: ubuntu-10.04-amd64
box : ubuntu-server-10044-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,10 @@
HOSTS:
ubuntu-server-12042-x64:
roles:
- master
platform: ubuntu-12.04-amd64
box : ubuntu-server-12042-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,36 @@
require 'spec_helper_acceptance'
case fact('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 'Gentoo'
line = '0.gentoo.pool.ntp.org'
when 'Linux'
case fact('operatingsystem')
when 'ArchLinux'
line = '0.pool.ntp.org'
when 'Gentoo'
line = '0.gentoo.pool.ntp.org'
end
when 'AIX'
line = '0.debian.pool.ntp.org iburst'
end
describe 'ntp::config class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
it 'sets up ntp.conf' do
apply_manifest(%{
class { 'ntp': }
}, :catch_failures => true)
end
describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain line }
end
end

View file

@ -0,0 +1,31 @@
require 'spec_helper_acceptance'
case fact('osfamily')
when 'FreeBSD'
packagename = 'net/ntp'
when 'Gentoo'
packagename = 'net-misc/ntp'
when 'Linux'
case fact('operatingsystem')
when 'ArchLinux'
packagename = 'ntp'
when 'Gentoo'
packagename = 'net-misc/ntp'
end
when 'AIX'
packagename = 'bos.net.tcp.client'
else
packagename = 'ntp'
end
describe 'ntp::install class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
it 'installs the package' do
apply_manifest(%{
class { 'ntp': }
}, :catch_failures => true)
end
describe package(packagename) do
it { should be_installed }
end
end

View file

@ -0,0 +1,165 @@
require 'spec_helper_acceptance'
case fact('osfamily')
when 'FreeBSD'
packagename = 'net/ntp'
when 'Gentoo'
packagename = 'net-misc/ntp'
when 'Linux'
case fact('operatingsystem')
when 'ArchLinux'
packagename = 'ntp'
when 'Gentoo'
packagename = 'net-misc/ntp'
end
when 'AIX'
packagename = 'bos.net.tcp.client'
else
packagename = 'ntp'
end
describe "ntp class:", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
it 'applies successfully' do
pp = "class { 'ntp': }"
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).not_to match(/error/i)
end
end
describe 'autoconfig' do
it 'raises a deprecation warning' do
pp = "class { 'ntp': autoupdate => true }"
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/autoupdate parameter has been deprecated and replaced with package_ensure/)
end
end
end
describe 'config' do
it 'sets the ntp.conf location' do
pp = "class { 'ntp': config => '/etc/antp.conf' }"
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/antp.conf') do
it { should be_file }
end
end
describe 'config_template' do
it 'sets up template' do
modulepath = default['distmoduledir']
shell("mkdir -p #{modulepath}/test/templates")
shell("echo 'testcontent' >> #{modulepath}/test/templates/ntp.conf")
end
it 'sets the ntp.conf location' do
pp = "class { 'ntp': config_template => 'test/ntp.conf' }"
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain 'testcontent' }
end
end
describe 'driftfile' do
it 'sets the driftfile location' do
pp = "class { 'ntp': driftfile => '/tmp/driftfile' }"
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain 'driftfile /tmp/driftfile' }
end
end
describe 'keys' do
it 'enables the key parameters' do
pp = <<-EOS
class { 'ntp':
keys_enable => true,
keys_file => '/etc/ntp/keys',
keys_controlkey => '/etc/ntp/controlkey',
keys_requestkey => '1',
keys_trusted => [ '1', '2' ],
}
EOS
# Rely on a shell command instead of a file{} here to avoid loops
# within puppet when it tries to manage /etc/ntp/keys before /etc/ntp.
shell("mkdir -p /etc/ntp && echo '1 M AAAABBBB' >> /etc/ntp/keys")
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain 'keys /etc/ntp/keys' }
it { should contain 'controlkey /etc/ntp/controlkey' }
it { should contain 'requestkey 1' }
it { should contain 'trustedkey 1 2' }
end
end
describe 'package' do
it 'installs the right package' do
pp = <<-EOS
class { 'ntp':
package_ensure => present,
package_name => ['#{packagename}'],
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe package(packagename) do
it { should be_installed }
end
end
describe 'panic => false' do
it 'enables the tinker panic setting' do
pp = <<-EOS
class { 'ntp':
panic => false,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/ntp.conf') do
it { should contain 'tinker panic' }
end
end
describe 'panic => true' do
it 'disables the tinker panic setting' do
pp = <<-EOS
class { 'ntp':
panic => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/ntp.conf') do
it { should_not contain 'tinker panic 0' }
end
end
describe 'udlc' do
it 'adds a udlc' do
pp = "class { 'ntp': udlc => true }"
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain '127.127.1.0' }
end
end
end

View file

@ -0,0 +1,63 @@
require 'spec_helper_acceptance'
case fact('osfamily')
when 'RedHat', 'FreeBSD', 'Linux', 'Gentoo'
servicename = 'ntpd'
when 'AIX'
servicename = 'xntpd'
else
servicename = 'ntp'
end
describe 'ntp::service class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
describe 'basic test' do
it 'sets up the service' do
apply_manifest(%{
class { 'ntp': }
}, :catch_failures => true)
end
describe service(servicename) do
it { should be_enabled }
it { should be_running }
end
end
describe 'service parameters' do
it 'starts the service' do
pp = <<-EOS
class { 'ntp':
service_enable => true,
service_ensure => running,
service_manage => true,
service_name => '#{servicename}'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe service(servicename) do
it { should be_running }
it { should be_enabled }
end
end
describe 'service is unmanaged' do
it 'shouldnt stop the service' do
pp = <<-EOS
class { 'ntp':
service_enable => false,
service_ensure => stopped,
service_manage => false,
service_name => '#{servicename}'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe service(servicename) do
it { should be_running }
it { should be_enabled }
end
end
end

View file

@ -0,0 +1,24 @@
require 'spec_helper_acceptance'
describe 'preferred servers', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
pp = <<-EOS
class { '::ntp':
servers => ['a', 'b', 'c', 'd'],
preferred_servers => ['c', 'd'],
}
EOS
it 'applies cleanly' do
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).not_to match(/error/i)
end
end
describe file('/etc/ntp.conf') do
it { should be_file }
it { should contain 'server a' }
it { should contain 'server b' }
it { should contain 'server c prefer' }
it { should contain 'server d prefer' }
end
end

View file

@ -0,0 +1,20 @@
require 'spec_helper_acceptance'
describe "ntp class with restrict:", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'should run successfully' do
pp = "class { 'ntp': restrict => ['test restrict']}"
it 'runs twice' do
2.times do
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).not_to match(/error/i)
end
end
end
end
describe file('/etc/ntp.conf') do
it { should contain('test restrict') }
end
end

View file

@ -0,0 +1,10 @@
require 'spec_helper_acceptance'
describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
it 'should fail' do
pp = <<-EOS
class { 'ntp': }
EOS
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/is not supported on an/i)
end
end

View file

@ -0,0 +1,272 @@
require 'spec_helper'
describe 'ntp' do
['Debian', 'RedHat','SuSE', 'FreeBSD', 'Archlinux', 'Gentoo', 'Gentoo (Facter < 1.7)'].each do |system|
if system == 'Gentoo (Facter < 1.7)'
let(:facts) {{ :osfamily => 'Linux', :operatingsystem => 'Gentoo' }}
else
let(:facts) {{ :osfamily => system }}
end
it { should contain_class('ntp::install') }
it { should contain_class('ntp::config') }
it { should contain_class('ntp::service') }
describe "ntp::config on #{system}" do
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') }
describe 'allows template to be overridden' do
let(:params) {{ :config_template => 'my_ntp/ntp.conf.erb' }}
it { should contain_file('/etc/ntp.conf').with({
'content' => /server foobar/})
}
end
describe "keys for osfamily #{system}" do
context "when enabled" do
let(:params) {{
:keys_enable => true,
:keys_file => '/etc/ntp/ntp.keys',
:keys_trusted => ['1', '2', '3'],
:keys_controlkey => '2',
:keys_requestkey => '3',
}}
it { should contain_file('/etc/ntp').with({
'ensure' => 'directory'})
}
it { should contain_file('/etc/ntp.conf').with({
'content' => /trustedkey 1 2 3/})
}
it { should contain_file('/etc/ntp.conf').with({
'content' => /controlkey 2/})
}
it { should contain_file('/etc/ntp.conf').with({
'content' => /requestkey 3/})
}
end
end
context "when disabled" do
let(:params) {{
:keys_enable => false,
:keys_file => '/etc/ntp/ntp.keys',
:keys_trusted => ['1', '2', '3'],
:keys_controlkey => '2',
:keys_requestkey => '3',
}}
it { should_not contain_file('/etc/ntp').with({
'ensure' => 'directory'})
}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /trustedkey 1 2 3/})
}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /controlkey 2/})
}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /requestkey 3/})
}
end
describe 'preferred servers' do
context "when set" do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:preferred_servers => ['a', 'b']
}}
it { should contain_file('/etc/ntp.conf').with({
'content' => /server a prefer\nserver b prefer\nserver c\nserver d/})
}
end
context "when not set" do
let(:params) {{
:servers => ['a', 'b', 'c', 'd'],
:preferred_servers => []
}}
it { should_not contain_file('/etc/ntp.conf').with({
'content' => /server a prefer/})
}
end
end
describe "ntp::install on #{system}" do
let(:params) {{ :package_ensure => 'present', :package_name => ['ntp'], }}
it { should contain_package('ntp').with(
:ensure => 'present',
:name => 'ntp'
)}
describe 'should allow package ensure to be overridden' do
let(:params) {{ :package_ensure => 'latest', :package_name => ['ntp'] }}
it { should contain_package('ntp').with_ensure('latest') }
end
describe 'should allow the package name to be overridden' do
let(:params) {{ :package_ensure => 'present', :package_name => ['hambaby'] }}
it { should contain_package('ntp').with_name('hambaby') }
end
end
describe 'ntp::service' do
let(:params) {{
:service_manage => true,
:service_enable => true,
:service_ensure => 'running',
:service_name => 'ntp'
}}
describe 'with defaults' do
it { should contain_service('ntp').with(
:enable => true,
:ensure => 'running',
:name => 'ntp'
)}
end
describe 'service_ensure' do
describe 'when overridden' do
let(:params) {{ :service_name => 'ntp', :service_ensure => 'stopped' }}
it { should contain_service('ntp').with_ensure('stopped') }
end
end
describe 'service_manage' do
let(:params) {{
:service_manage => false,
:service_enable => true,
:service_ensure => 'running',
:service_name => 'ntpd',
}}
it 'when set to false' do
should_not contain_service('ntp').with({
'enable' => true,
'ensure' => 'running',
'name' => 'ntpd'
})
end
end
end
end
context 'ntp::config' do
describe "for operating system Gentoo (Facter < 1.7)" do
let(:facts) {{ :operatingsystem => 'Gentoo',
:osfamily => 'Linux' }}
it 'uses the NTP pool servers by default' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.gentoo.pool.ntp.org/,
})
end
end
describe "on osfamily Gentoo" do
let(:facts) {{ :osfamily => 'Gentoo' }}
it 'uses the NTP pool servers by default' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.gentoo.pool.ntp.org/,
})
end
end
describe "on osfamily Debian" do
let(:facts) {{ :osfamily => 'debian' }}
it 'uses the debian ntp servers by default' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.debian.pool.ntp.org iburst/,
})
end
end
describe "on osfamily RedHat" do
let(:facts) {{ :osfamily => 'RedHat' }}
it 'uses the redhat ntp servers by default' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.centos.pool.ntp.org/,
})
end
end
describe "on osfamily SuSE" do
let(:facts) {{ :osfamily => 'SuSE' }}
it 'uses the opensuse ntp servers by default' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.opensuse.pool.ntp.org/,
})
end
end
describe "on osfamily FreeBSD" do
let(:facts) {{ :osfamily => 'FreeBSD' }}
it 'uses the freebsd ntp servers by default' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.freebsd.pool.ntp.org iburst maxpoll 9/,
})
end
end
describe "on osfamily ArchLinux" do
let(:facts) {{ :osfamily => 'ArchLinux' }}
it 'uses the NTP pool servers by default' do
should contain_file('/etc/ntp.conf').with({
'content' => /server \d.pool.ntp.org/,
})
end
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(:facts) {{ :osfamily => 'Archlinux',
:is_virtual => 'true' }}
it 'should not use local clock as a time source' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /server.*127.127.1.0.*fudge.*127.127.1.0 stratum 10/,
})
end
it 'allows large clock skews' do
should contain_file('/etc/ntp.conf').with({
'content' => /tinker panic 0/,
})
end
end
describe 'for physical machines' do
let(:facts) {{ :osfamily => 'Archlinux',
:is_virtual => 'false' }}
it 'disallows large clock skews' do
should_not contain_file('/etc/ntp.conf').with({
'content' => /tinker panic 0/,
})
end
end
end
end

View file

@ -0,0 +1,4 @@
#my uber ntp config
#
server foobar

View file

@ -0,0 +1,6 @@
--format
s
--colour
--loadby
mtime
--backtrace

View file

@ -0,0 +1 @@
require 'puppetlabs_spec_helper/module_spec_helper'

View file

@ -0,0 +1,32 @@
require 'beaker-rspec'
UNSUPPORTED_PLATFORMS = [ 'windows', 'Solaris' ]
unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
if hosts.first.is_pe?
install_pe
else
install_puppet
end
hosts.each do |host|
on hosts, "mkdir -p #{host['distmoduledir']}"
end
end
RSpec.configure do |c|
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
# Readable test descriptions
c.formatter = :documentation
# Configure all nodes in nodeset
c.before :suite do
# Install module and dependencies
puppet_module_install(:source => proj_root, :module_name => 'ntp')
hosts.each do |host|
shell("/bin/touch #{default['puppetpath']}/hiera.yaml")
shell('puppet module install puppetlabs-stdlib', :acceptable_exit_codes => [0,1])
end
end
end

View file

@ -0,0 +1,4 @@
Provider Specs
==============
Define specs for your providers under this directory.

View file

@ -0,0 +1,4 @@
Resource Type Specs
===================
Define specs for your resource types in this directory.