Skip to content

Commit

Permalink
Don't add defaults if pools or peers are specified
Browse files Browse the repository at this point in the history
If someone is specifying pools or peers, they probably do not want default servers applied. So make the detection here more flexible.

Also, add rspec for this case.

Signed-off-by: seph <seph@directionless.org>
  • Loading branch information
directionless committed Dec 21, 2017
1 parent 23232a5 commit 557c207
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion attributes/default.rb
Expand Up @@ -22,7 +22,7 @@
#

# default attributes for all platforms
default['ntp']['servers'] = [] # The default recipe sets a list of common NTP servers (COOK-1170)
default['ntp']['servers'] = []
default['ntp']['peers'] = []
default['ntp']['pools'] = []
default['ntp']['restrictions'] = []
Expand Down
4 changes: 3 additions & 1 deletion recipes/default.rb
Expand Up @@ -20,7 +20,9 @@

::Chef::Resource.send(:include, Opscode::Ntp::Helper)

if node['ntp']['servers'].empty?
# If there are no specified servers, pools, or peers, set some defaults.
# See COOK-1170 for why this isn't a default attribute
if (node['ntp']['servers'] + node['ntp']['peers'] + node['ntp']['pools']).empty?
node.default['ntp']['servers'] = [
'0.pool.ntp.org',
'1.pool.ntp.org',
Expand Down
4 changes: 3 additions & 1 deletion spec/unit/recipes/default_spec.rb
Expand Up @@ -80,7 +80,7 @@
cached(:chef_run) do
runner = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04')
runner.node.normal['ntp']['pools'] = %w(0.pool.ntp.org 1.pool.ntp.org)
runner.node.normal['ntp']['servers'] = %w()
runner.node.normal['ntp']['use_cmos'] = false
runner.converge('ntp::default')
end

Expand All @@ -91,6 +91,8 @@
.with_content('pool 0.pool.ntp.org')
expect(chef_run).to render_file('/etc/ntp.conf')
.with_content('pool 1.pool.ntp.org')
expect(chef_run).not_to render_file('/etc/ntp.conf')
.with_content(/server/)
end
end

Expand Down

0 comments on commit 557c207

Please sign in to comment.