1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
|
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'
when 'Solaris'
case fact('kernelrelease')
when '5.10'
packagename = ['SUNWntp4r', 'SUNWntp4u']
when '5.11'
packagename = 'service/network/ntp'
end
else
if fact('operatingsystem') == 'SLES' && fact('operatingsystemmajrelease') == '12'
'ntpd'
else
'ntp'
end
end
keysfile = if fact('osfamily') == 'RedHat'
'/etc/ntp/keys'
elsif fact('osfamily') == 'Solaris'
'/etc/inet/ntp.keys'
else
'/etc/ntp.keys'
end
config = if fact('osfamily') == 'Solaris'
'/etc/inet/ntp.conf'
else
'/etc/ntp.conf'
end
describe 'ntp class:', unless: UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
# FM-5470, this was added to reset failed count and work around puppet 3.x
if (fact('operatingsystem') == 'SLES' && fact('operatingsystemmajrelease') == '12') || (fact('operatingsystem') == 'Scientific' && fact('operatingsystemmajrelease') == '7')
after :each do
shell('systemctl reset-failed ntpd.service')
end
end
it 'applies successfully' do
pp = "class { 'ntp': }"
apply_manifest(pp, catch_failures: true) do |r|
expect(r.stderr).not_to match(%r{error}i)
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 { is_expected.to be_file }
end
end
describe 'config_template' do
before :all do
modulepath = default['distmoduledir']
shell("mkdir -p #{modulepath}/test/templates")
# Add spurious template logic to verify the use of the correct template rendering engine
shell("echo '<% [1].each do |i| %>erbserver<%= i %><%end %>' >> #{modulepath}/test/templates/ntp.conf.erb")
end
it 'sets the ntp.conf erb template location' do
pp = "class { 'ntp': config_template => 'test/ntp.conf.erb' }"
apply_manifest(pp, catch_failures: true)
end
describe file(config.to_s) do
it { is_expected.to be_file }
its(:content) { is_expected.to match 'erbserver1' }
end
it 'sets the ntp.conf epp template location and the ntp.conf erb template location which should fail' do
pp = "class { 'ntp': config_template => 'test/ntp.conf.erb', config_epp => 'test/ntp.conf.epp' }"
expect(apply_manifest(pp, expect_failures: true).stderr).to match(%r{Cannot supply both config_epp and config_template}i)
end
end
describe 'config_epp' do
before :all do
modulepath = default['distmoduledir']
shell("mkdir -p #{modulepath}/test/templates")
# Add spurious template logic to verify the use of the correct template rendering engine
shell("echo '<% [1].each |$i| { -%>eppserver<%= $i %><% } -%>' >> #{modulepath}/test/templates/ntp.conf.epp")
end
it 'sets the ntp.conf epp template location' do
pp = "class { 'ntp': config_epp => 'test/ntp.conf.epp' }"
apply_manifest(pp, catch_failures: true)
end
describe file(config.to_s) do
it { is_expected.to be_file }
its(:content) { is_expected.to match 'eppserver1' }
end
it 'sets the ntp.conf epp template location and the ntp.conf erb template location which should fail' do
pp = "class { 'ntp': config_template => 'test/ntp.conf.erb', config_epp => 'test/ntp.conf.epp' }"
expect(apply_manifest(pp, expect_failures: true).stderr).to match(%r{Cannot supply both config_epp and config_template}i)
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(config.to_s) do
it { is_expected.to be_file }
its(:content) { is_expected.to match 'driftfile /tmp/driftfile' }
end
end
describe 'keys' do
pp = <<-MANIFEST
class { 'ntp':
keys_enable => true,
keys_controlkey => 1,
keys_requestkey => 1,
keys_trusted => [ 1, 2 ],
keys => [ '1 M AAAABBBB' ],
}
MANIFEST
it 'enables the key parameters' do
apply_manifest(pp, catch_failures: true)
end
describe file(config.to_s) do
it { is_expected.to be_file }
its(:content) { is_expected.to match "keys #{keysfile}" }
its(:content) { is_expected.to match 'controlkey 1' }
its(:content) { is_expected.to match 'requestkey 1' }
its(:content) { is_expected.to match 'trustedkey 1 2' }
end
describe file(keysfile) do
it { is_expected.to be_file }
its(:content) { is_expected.to match '1 M AAAABBBB' }
end
end
describe 'package' do
pp = <<-MANIFEST
class { 'ntp':
package_ensure => present,
package_name => #{Array(packagename).inspect},
}
MANIFEST
it 'installs the right package' do
apply_manifest(pp, catch_failures: true)
end
Array(packagename).each do |package|
describe package(package) do
it { is_expected.to be_installed }
end
end
end
describe 'panic => 0' do
pp = <<-MANIFEST
class { 'ntp':
panic => 0,
}
MANIFEST
it 'disables the tinker panic setting' do
apply_manifest(pp, catch_failures: true)
end
describe file(config.to_s) do
its(:content) { is_expected.to match 'tinker panic 0' }
end
end
describe 'panic => 1' do
pp = <<-MANIFEST
class { 'ntp':
panic => 1,
}
MANIFEST
it 'enables the tinker panic setting' do
apply_manifest(pp, catch_failures: true)
end
describe file(config.to_s) do
its(:content) { is_expected.to match 'tinker panic 1' }
end
end
describe 'udlc' do
it 'adds a udlc' do
pp = "class { 'ntp': udlc => true }"
apply_manifest(pp, catch_failures: true)
end
describe file(config.to_s) do
it { is_expected.to be_file }
its(:content) { is_expected.to match '127.127.1.0' }
end
end
describe 'udlc_stratum' do
it 'sets the stratum value when using udlc' do
pp = "class { 'ntp': udlc => true, udlc_stratum => 10 }"
apply_manifest(pp, catch_failures: true)
end
describe file(config.to_s) do
it { is_expected.to be_file }
its(:content) { is_expected.to match 'stratum 10' }
end
end
end
|