From 5c1164ca093f105d7a3d1f643dee7b0e675f31f7 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 29 Jul 2013 17:25:36 -0400 Subject: Add preferred_servers feature. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds: `preferred_servers` [Array]: The servers to prefer. As requested by Erik Dalén! --- spec/classes/ntp_config_spec.rb | 89 ++++++++++++++++++++++------------- spec/system/ntp_config_spec.rb | 8 ++-- spec/system/preferred_servers_spec.rb | 20 ++++++++ 3 files changed, 80 insertions(+), 37 deletions(-) create mode 100644 spec/system/preferred_servers_spec.rb (limited to 'spec') 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 -- cgit v1.2.3