summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAshley Penney <ashley.penney@puppetlabs.com>2013-07-29 17:25:36 -0400
committerAshley Penney <ashley.penney@puppetlabs.com>2013-07-29 19:00:38 -0400
commit5c1164ca093f105d7a3d1f643dee7b0e675f31f7 (patch)
tree4b46cbe0042e25de5623b3b83c645d1adb4a9975 /spec
parent56df86a9a2838ef11bd07928709b04667f9b305f (diff)
Add preferred_servers feature.
This adds: `preferred_servers` [Array]: The servers to prefer. As requested by Erik Dalén!
Diffstat (limited to 'spec')
-rw-r--r--spec/classes/ntp_config_spec.rb89
-rw-r--r--spec/system/ntp_config_spec.rb8
-rw-r--r--spec/system/preferred_servers_spec.rb20
3 files changed, 80 insertions, 37 deletions
diff --git a/spec/classes/ntp_config_spec.rb b/spec/classes/ntp_config_spec.rb
index 53836a0..51db491 100644
--- a/spec/classes/ntp_config_spec.rb
+++ b/spec/classes/ntp_config_spec.rb
@@ -167,62 +167,85 @@ describe 'ntp::config' do
(content.split("\n") & expected_lines).should == expected_lines
end
end
- end
- ['Debian', 'RedHat','SuSE', 'FreeBSD', 'Archlinux'].each do |osfamily|
- describe "keys for osfamily #{osfamily}" do
+ ['Debian', 'RedHat','SuSE', 'FreeBSD', 'Archlinux'].each do |osfamily|
+
+ describe "keys for osfamily #{osfamily}" do
+ context "when enabled" do
+ let(:facts) {{ :osfamily => osfamily }}
+ 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 enabled" do
+ context "when disabled" do
let(:facts) {{ :osfamily => osfamily }}
let(:params) {{
- :keys_enable => true,
+ :keys_enable => false,
:keys_file => '/etc/ntp/ntp.keys',
:keys_trusted => ['1', '2', '3'],
:keys_controlkey => '2',
:keys_requestkey => '3',
}}
- it { should contain_file('/etc/ntp').with({
+ it { should_not contain_file('/etc/ntp').with({
'ensure' => 'directory'})
}
- it { should contain_file('/etc/ntp.conf').with({
+ it { should_not contain_file('/etc/ntp.conf').with({
'content' => /trustedkey 1 2 3/})
}
- it { should contain_file('/etc/ntp.conf').with({
+ it { should_not contain_file('/etc/ntp.conf').with({
'content' => /controlkey 2/})
}
- it { should contain_file('/etc/ntp.conf').with({
+ it { should_not contain_file('/etc/ntp.conf').with({
'content' => /requestkey 3/})
}
end
end
- context "when disabled" do
- let(:facts) {{ :osfamily => osfamily }}
- let(:params) {{
- :keys_enable => false,
- :keys_file => '/etc/ntp/ntp.keys',
- :keys_trusted => ['1', '2', '3'],
- :keys_controlkey => '2',
- :keys_requestkey => '3',
- }}
+ describe 'preferred servers' do
+ context "when set" do
+ let(:facts) {{ :osfamily => osfamily }}
+ 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(:facts) {{ :osfamily => osfamily }}
+ let(:params) {{
+ :servers => ['a', 'b', 'c', 'd'],
+ :preferred_servers => []
+ }}
- 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/})
- }
+ it { should_not contain_file('/etc/ntp.conf').with({
+ 'content' => /server a prefer/})
+ }
+ end
end
end
-
-
-
end
+
end
diff --git a/spec/system/ntp_config_spec.rb b/spec/system/ntp_config_spec.rb
index 263bc9d..194cdf1 100644
--- a/spec/system/ntp_config_spec.rb
+++ b/spec/system/ntp_config_spec.rb
@@ -27,9 +27,9 @@ describe 'ntp::config class' do
end
end
- describe file('/etc/ntp.conf') do
- it { should be_file }
- it { should contain line }
- end
+ describe file('/etc/ntp.conf') do
+ it { should be_file }
+ it { should contain line }
+ end
end
diff --git a/spec/system/preferred_servers_spec.rb b/spec/system/preferred_servers_spec.rb
new file mode 100644
index 0000000..686861b
--- /dev/null
+++ b/spec/system/preferred_servers_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper_system'
+
+describe 'preferred servers' do
+ it 'applies cleanly' do
+ puppet_apply(%{
+ class { '::ntp':
+ servers => ['a', 'b', 'c', 'd'],
+ preferred_servers => ['c', 'd'],
+ }
+ })
+ 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