Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,9 @@ logfile
Log file name

- *Default*: none

ignore_local_clock
------------------
Boolean to ignore the local clock. By setting this to true it ensures local clock is not referenced, useful if local clock drifts.

- *Default*: false
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
$enable_stats = false,
$statsdir = '/var/log/ntpstats/',
$logfile = 'UNSET',
$ignore_local_clock = false,
) {

# validate type and convert string to boolean if necessary
Expand Down Expand Up @@ -89,6 +90,13 @@
$service_enable = false
}

if type($ignore_local_clock) == 'string' {
$my_ignore_local_clock = str2bool($ignore_local_clock)
} else {
$my_ignore_local_clock = $ignore_local_clock
}
validate_bool($my_ignore_local_clock)

case $::osfamily {
'Debian': {
$default_package_name = [ 'ntp' ]
Expand Down
35 changes: 25 additions & 10 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) }
it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) }
it { should contain_file('ntp_conf').with_content(/^keys \/etc\/ntp\/keys$/) }
it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) }
it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) }

Expand Down Expand Up @@ -81,7 +81,7 @@
it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) }
it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) }
it { should contain_file('ntp_conf').with_content(/^keys \/etc\/ntp\/keys$/) }
it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) }
it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) }

Expand Down Expand Up @@ -126,7 +126,7 @@
it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) }
it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) }
it { should contain_file('ntp_conf').with_content(/^keys \/etc\/ntp\/keys$/) }
it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) }
it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) }

Expand Down Expand Up @@ -213,7 +213,7 @@
it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) }
it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) }
it { should contain_file('ntp_conf').with_content(/^keys \/etc\/inet\/ntp.keys$/) }
it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) }
it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) }

Expand Down Expand Up @@ -277,7 +277,7 @@
it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) }
it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) }
it { should contain_file('ntp_conf').with_content(/^keys \/etc\/inet\/ntp.keys$/) }
it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) }
it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) }

Expand Down Expand Up @@ -335,7 +335,7 @@
it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) }
it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) }
it { should contain_file('ntp_conf').with_content(/^keys \/etc\/inet\/ntp.keys$/) }
it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) }
it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) }

Expand Down Expand Up @@ -395,7 +395,7 @@
it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) }
it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) }
it { should contain_file('ntp_conf').with_content(/^keys \/etc\/inet\/ntp.keys$/) }
it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }

it { should_not contain_file('admin_file') }

Expand Down Expand Up @@ -445,7 +445,7 @@
it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) }
it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) }
it { should contain_file('ntp_conf').with_content(/^keys \/etc\/inet\/ntp.keys$/) }
it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }

it {
should contain_file('admin_file').with({
Expand Down Expand Up @@ -501,7 +501,7 @@
it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) }
it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) }
it { should_not contain_file('ntp_conf').with_content(/^keys \/etc\/ntp\/keys$/) }
it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) }
it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) }

Expand Down Expand Up @@ -555,7 +555,7 @@
it { should contain_file('ntp_conf').with_content(/# Statistics are not being logged/) }
it { should contain_file('ntp_conf').with_content(/server 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org/) }
it { should_not contain_file('ntp_conf').with_content(/^keys \/etc\/ntp\/keys$/) }
it { should contain_file('ntp_conf').with_content(/fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }
it { should contain_file('ntp_conf').with_content(/^restrict -4 default kod notrap nomodify nopeer noquery$/) }
it { should contain_file('ntp_conf').with_content(/^restrict -6 default kod notrap nomodify nopeer noquery$/) }

Expand Down Expand Up @@ -747,5 +747,20 @@
end
end

describe 'with ignore_local_clock set' do
let(:facts) { { :osfamily => 'RedHat' } }

context 'to true' do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an array of ['true',true] to test both the boolean and the stringified boolean.

Here's an example

https://github.com/ghoneycutt/puppet-module-ssh/blob/master/spec/classes/init_spec.rb#L1646-1675

let(:params) { { :ignore_local_clock => true } }

it { should contain_file('ntp_conf').with_content(/^#fudge 127.127.1.0 stratum 10/) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of commenting it out, the line should be removed. The test would then be

it { should contain_file('ntp_conf').without_content(/^\s*fudge/) }

end

context 'to false' do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with ['false',false]

let(:params) { { :ignore_local_clock => false } }

it { should contain_file('ntp_conf').with_content(/^fudge 127.127.1.0 stratum 10/) }
end
end

end
5 changes: 5 additions & 0 deletions templates/ntp.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ restrict ::1

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
<% if @my_ignore_local_clock == true -%>
#server 127.127.1.0 # local clock
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the commented out lines and the else statement. This seems to be the reverse of your logic since the default you specify is false, so these lines would not be there. I think your logic should likely be <% if @my_ignore_local_clock == false -%>

#fudge 127.127.1.0 stratum <%= @fudge_stratum %>
<% else %>
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum <%= @fudge_stratum %>
<% end -%>

<% if @keys_real -%>
# Key file containing the keys and key identifiers used when operating
Expand Down