ntp_parameters_spec.rb 6.56 KB
Newer Older
1 2
require 'spec_helper_acceptance'

3 4 5 6 7 8 9 10 11 12 13 14 15 16
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'
17
when 'Solaris'
18
  case fact('kernelrelease')
Cody Herriges's avatar
Cody Herriges committed
19
  when '5.10'
20
    packagename = ['SUNWntp4r', 'SUNWntp4u']
Cody Herriges's avatar
Cody Herriges committed
21 22 23
  when '5.11'
    packagename = 'service/network/ntp'
  end
24
else
25 26
  if fact('operatingsystem') == 'SLES' && fact('operatingsystemmajrelease') == '12'
    'ntpd'
27
  else
28
    'ntp'
29
  end
30 31
end

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
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
47
  # FM-5470, this was added to reset failed count and work around puppet 3.x
48
  if (fact('operatingsystem') == 'SLES' && fact('operatingsystemmajrelease') == '12') || (fact('operatingsystem') == 'Scientific' && fact('operatingsystemmajrelease') == '7')
49 50 51 52 53
    after :each do
      shell('systemctl reset-failed ntpd.service')
    end
  end

54 55 56
  it 'applies successfully' do
    pp = "class { 'ntp': }"

57 58
    apply_manifest(pp, catch_failures: true) do |r|
      expect(r.stderr).not_to match(%r{error}i)
59 60 61 62 63 64
    end
  end

  describe 'config' do
    it 'sets the ntp.conf location' do
      pp = "class { 'ntp': config => '/etc/antp.conf' }"
65
      apply_manifest(pp, catch_failures: true)
66 67 68
    end

    describe file('/etc/antp.conf') do
69
      it { is_expected.to be_file }
70 71 72 73
    end
  end

  describe 'config_template' do
Helen Campbell's avatar
Helen Campbell committed
74
    before :all do
75 76
      modulepath = default['distmoduledir']
      shell("mkdir -p #{modulepath}/test/templates")
Helen Campbell's avatar
Helen Campbell committed
77 78
      # 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")
79 80
    end

Helen Campbell's avatar
Helen Campbell committed
81 82
    it 'sets the ntp.conf erb template location' do
      pp = "class { 'ntp': config_template => 'test/ntp.conf.erb' }"
83
      apply_manifest(pp, catch_failures: true)
84 85
    end

86 87 88
    describe file(config.to_s) do
      it { is_expected.to be_file }
      its(:content) { is_expected.to match 'erbserver1' }
Helen Campbell's avatar
Helen Campbell committed
89 90 91 92
    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' }"
93
      expect(apply_manifest(pp, expect_failures: true).stderr).to match(%r{Cannot supply both config_epp and config_template}i)
Helen Campbell's avatar
Helen Campbell committed
94 95 96 97 98 99 100 101 102 103 104 105 106
    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' }"
107
      apply_manifest(pp, catch_failures: true)
Helen Campbell's avatar
Helen Campbell committed
108 109
    end

110 111 112
    describe file(config.to_s) do
      it { is_expected.to be_file }
      its(:content) { is_expected.to match 'eppserver1' }
Helen Campbell's avatar
Helen Campbell committed
113 114 115 116
    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' }"
117
      expect(apply_manifest(pp, expect_failures: true).stderr).to match(%r{Cannot supply both config_epp and config_template}i)
118 119 120 121 122 123
    end
  end

  describe 'driftfile' do
    it 'sets the driftfile location' do
      pp = "class { 'ntp': driftfile => '/tmp/driftfile' }"
124
      apply_manifest(pp, catch_failures: true)
125 126
    end

127 128 129
    describe file(config.to_s) do
      it { is_expected.to be_file }
      its(:content) { is_expected.to match 'driftfile /tmp/driftfile' }
130 131 132 133
    end
  end

  describe 'keys' do
134
    pp = <<-MANIFEST
135 136 137 138 139 140 141
    class { 'ntp':
      keys_enable     => true,
      keys_controlkey => 1,
      keys_requestkey => 1,
      keys_trusted    => [ 1, 2 ],
      keys            => [ '1 M AAAABBBB' ],
    }
142
    MANIFEST
143

144
    it 'enables the key parameters' do
145 146 147 148 149 150 151 152 153
      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' }
154
    end
155

156
    describe file(keysfile) do
157 158
      it { is_expected.to be_file }
      its(:content) { is_expected.to match '1 M AAAABBBB' }
159
    end
160 161 162
  end

  describe 'package' do
163
    pp = <<-MANIFEST
164 165 166 167
    class { 'ntp':
      package_ensure => present,
      package_name   => #{Array(packagename).inspect},
    }
168
    MANIFEST
169

170
    it 'installs the right package' do
171
      apply_manifest(pp, catch_failures: true)
172 173
    end

Hunter Haugen's avatar
Hunter Haugen committed
174 175
    Array(packagename).each do |package|
      describe package(package) do
176
        it { is_expected.to be_installed }
Hunter Haugen's avatar
Hunter Haugen committed
177
      end
178 179 180
    end
  end

181
  describe 'panic => 0' do
182
    pp = <<-MANIFEST
183 184 185
    class { 'ntp':
      panic => 0,
    }
186
    MANIFEST
187

188
    it 'disables the tinker panic setting' do
189
      apply_manifest(pp, catch_failures: true)
190 191
    end

192 193
    describe file(config.to_s) do
      its(:content) { is_expected.to match 'tinker panic 0' }
194 195 196
    end
  end

197
  describe 'panic => 1' do
198
    pp = <<-MANIFEST
199 200 201
    class { 'ntp':
      panic => 1,
    }
202
    MANIFEST
203

204
    it 'enables the tinker panic setting' do
205
      apply_manifest(pp, catch_failures: true)
206 207
    end

208 209
    describe file(config.to_s) do
      its(:content) { is_expected.to match 'tinker panic 1' }
210 211 212 213 214 215
    end
  end

  describe 'udlc' do
    it 'adds a udlc' do
      pp = "class { 'ntp': udlc => true }"
216
      apply_manifest(pp, catch_failures: true)
217 218
    end

219 220 221
    describe file(config.to_s) do
      it { is_expected.to be_file }
      its(:content) { is_expected.to match '127.127.1.0' }
222 223 224
    end
  end

225 226 227
  describe 'udlc_stratum' do
    it 'sets the stratum value when using udlc' do
      pp = "class { 'ntp': udlc => true, udlc_stratum => 10 }"
228
      apply_manifest(pp, catch_failures: true)
229 230
    end

231 232 233
    describe file(config.to_s) do
      it { is_expected.to be_file }
      its(:content) { is_expected.to match 'stratum 10' }
234 235
    end
  end
236
end