Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new driftfile, hwtimestamps, rtcsync, and dumpdir parameters #82

Merged
merged 5 commits into from
Jul 11, 2020
Merged
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
40 changes: 40 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ This sets the file to write chrony keys into.

Default value: $chrony::params::config_keys

##### `driftfile`

Data type: `Stdlib::Unixpath`

The file for chrony to record clock drift in.

Default value: '/var/lib/chrony/drift'

##### `config_keys_manage`

Data type: `Boolean`
Expand Down Expand Up @@ -473,3 +481,35 @@ See [clientloglimit](https://chrony.tuxfamily.org/doc/3.4/chrony.conf.html#clien

Default value: `undef`

##### `rtcsync`

Data type: Boolean

Periodically sync system time to RTC

Default value: `true'

##### `rtconutc`

Data type: Boolean

Keep RTC in UTC instead of local time.

Default value: $chrony::params::rtconutc

##### `hwtimestamps`

Data type: `Variant[Hash,Array[String]]`

This selects interfaces to enable hardware timestamps on. It can be an array of interfaces
or a hash of interfaces to their respective options.

Default value: []

##### `dumpdir`

Data type: Optional[Stdlib::Unixpath]

Directory for chrony to store measurement in on exit.

Default value: $chrony::params::dumpdir
13 changes: 13 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
# Specify unix mode of chrony keys files, defaults to 0644 on ArchLinux and 0640 on Redhat.
# @param keys
# An array of key lines. These are printed as-is into the chrony key file.
# @param driftfile
# A file for chrony to record clock drift in.
# @param local_stratum
# Override the stratum of the server which will be reported to clients
# when the local reference is active.
Expand Down Expand Up @@ -166,10 +168,17 @@
# When set, specifies the maximum amount of memory in bytes that chronyd is allowed to allocate for logging of client accesses.
# If not set, chrony's, default will be used. In modern versions this is 524288 bytes. Older versions defaulted to have no limit.
# See [clientloglimit](https://chrony.tuxfamily.org/doc/3.4/chrony.conf.html#clientloglimit)
# @param rtcsync
# Sync system clock to RTC periodically
# @param rtconutc
# Keep RTC in UTC instead of local time.
# If not set, chrony's, default will be used. On Arch Linux the default is true instead.
# See [rtconutc](https://chrony.tuxfamily.org/doc/3.4/chrony.conf.html#rtconutc)
# @param hwtimestamps
# This selects interfaces to enable hardware timestamps on. It can be an array of
# interfaces or a hash of interfaces to their respective options.
# @param dumpdir
# Directory to store measurement history in on exit.
class chrony (
Array[String] $bindcmdaddress = ['127.0.0.1', '::1'],
Array[String] $cmdacl = $chrony::params::cmdacl,
Expand All @@ -185,6 +194,7 @@
Stdlib::Filemode $config_keys_mode = $chrony::params::config_keys_mode,
Boolean $config_keys_manage = true,
Array[String[1]] $keys = [],
Stdlib::Unixpath $driftfile = '/var/lib/chrony/drift',
Integer[1,15] $local_stratum = 10,
Optional[String[1]] $log_options = undef,
String[1] $package_ensure = 'present',
Expand Down Expand Up @@ -218,7 +228,10 @@
Optional[String] $leapsectz = undef,
Optional[Float] $maxslewrate = undef,
Optional[Numeric] $stratumweight = undef,
Boolean $rtcsync = true,
Boolean $rtconutc = $chrony::params::rtconutc,
Variant[Hash,Array[String]] $hwtimestamps = [],
Optional[Stdlib::Unixpath] $dumpdir = $chrony::params::dumpdir,
) inherits chrony::params {

if ! $config_keys_manage and $chrony_password != 'unset' {
Expand Down
4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$service_name = 'chrony'
$clientlog = true
$rtconutc = true
$dumpdir = '/var/log/chrony'
}
'Gentoo' : {
$package_name = 'net-misc/chrony'
Expand All @@ -26,6 +27,7 @@
$service_name = 'chronyd'
$clientlog = true
$rtconutc = true
$dumpdir = undef
}
'Suse', 'RedHat' : {
$package_name = 'chrony'
Expand All @@ -38,6 +40,7 @@
$service_name = 'chronyd'
$clientlog = false
$rtconutc = false
$dumpdir = undef
}
'Debian' : {
$package_name = 'chrony'
Expand All @@ -50,6 +53,7 @@
$service_name = 'chrony'
$clientlog = false
$rtconutc = false
$dumpdir = undef
}

default : {
Expand Down
40 changes: 40 additions & 0 deletions spec/classes/chrony_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*server #{s} iburst$}) }
end
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*rtconutc$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*driftfile /var/lib/chrony/drift$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*rtcsync$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*dumpdir /var/log/chrony$}) }
it { is_expected.to contain_file('/etc/chrony.keys').with_mode('0644') }
it { is_expected.to contain_file('/etc/chrony.keys').with_owner('0') }
it { is_expected.to contain_file('/etc/chrony.keys').with_group('0') }
Expand All @@ -45,6 +48,9 @@
['0.pool.ntp.org', '1.pool.ntp.org', '2.pool.ntp.org', '3.pool.ntp.org'].each do |s|
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*server #{s} iburst$}) }
end
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*driftfile /var/lib/chrony/drift$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*rtcsync$}) }
it { is_expected.to contain_file('/etc/chrony.conf').without_content(%r{^\s*dumpdir}) }
it { is_expected.to contain_file('/etc/chrony.keys').with_mode('0640') }
it { is_expected.to contain_file('/etc/chrony.keys').with_owner('0') }
it { is_expected.to contain_file('/etc/chrony.keys').with_group('chrony') }
Expand All @@ -59,6 +65,9 @@
['0.pool.ntp.org', '1.pool.ntp.org', '2.pool.ntp.org', '3.pool.ntp.org'].each do |s|
it { is_expected.to contain_file('/etc/chrony/chrony.conf').with_content(%r{^\s*server #{s} iburst$}) }
end
it { is_expected.to contain_file('/etc/chrony/chrony.conf').with_content(%r{^\s*driftfile /var/lib/chrony/drift$}) }
it { is_expected.to contain_file('/etc/chrony/chrony.conf').with_content(%r{^\s*rtcsync$}) }
it { is_expected.to contain_file('/etc/chrony/chrony.conf').without_content(%r{^\s*dumpdir}) }
it { is_expected.to contain_file('/etc/chrony/chrony.keys').with_mode('0640') }
it { is_expected.to contain_file('/etc/chrony/chrony.keys').with_owner('0') }
it { is_expected.to contain_file('/etc/chrony/chrony.keys').with_group('0') }
Expand Down Expand Up @@ -86,6 +95,10 @@
maxslewrate: 1000.0,
smoothtime: '400 0.001 leaponly',
rtconutc: true,
hwtimestamps: ['eth0'],
driftfile: '/var/tmp/chrony.drift',
rtcsync: false,
dumpdir: '/var/tmp',
}
end

Expand All @@ -99,6 +112,10 @@
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*cmddeny 1\.2\.3$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*cmdallow all 1\.2$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*rtconutc$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*hwtimestamp eth0$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*driftfile /var/tmp/chrony.drift$}) }
it { is_expected.to contain_file('/etc/chrony.conf').without_content(%r{^\s*rtcsync$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*dumpdir /var/tmp$}) }
it { is_expected.to contain_file('/etc/chrony.keys').with_mode('0123') }
it { is_expected.to contain_file('/etc/chrony.keys').with_owner('steve') }
it { is_expected.to contain_file('/etc/chrony.keys').with_group('mrt') }
Expand All @@ -120,6 +137,10 @@
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*cmddeny 1\.2\.3$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*cmdallow all 1\.2$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*rtconutc$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*hwtimestamp eth0$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*driftfile /var/tmp/chrony.drift$}) }
it { is_expected.to contain_file('/etc/chrony.conf').without_content(%r{^\s*rtcsync$}) }
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*dumpdir /var/tmp$}) }
it { is_expected.to contain_file('/etc/chrony.keys').with_mode('0123') }
it { is_expected.to contain_file('/etc/chrony.keys').with_owner('steve') }
it { is_expected.to contain_file('/etc/chrony.keys').with_group('mrt') }
Expand All @@ -140,6 +161,10 @@
it { is_expected.to contain_file('/etc/chrony/chrony.conf').with_content(%r{^\s*cmddeny 1\.2\.3$}) }
it { is_expected.to contain_file('/etc/chrony/chrony.conf').with_content(%r{^\s*cmdallow all 1\.2$}) }
it { is_expected.to contain_file('/etc/chrony/chrony.conf').with_content(%r{^\s*rtconutc$}) }
it { is_expected.to contain_file('/etc/chrony/chrony.conf').with_content(%r{^\s*hwtimestamp eth0$}) }
it { is_expected.to contain_file('/etc/chrony/chrony.conf').with_content(%r{^\s*driftfile /var/tmp/chrony.drift$}) }
it { is_expected.to contain_file('/etc/chrony/chrony.conf').without_content(%r{^\s*rtcsync$}) }
it { is_expected.to contain_file('/etc/chrony/chrony.conf').with_content(%r{^\s*dumpdir /var/tmp$}) }
it { is_expected.to contain_file('/etc/chrony/chrony.keys').with_mode('0123') }
it { is_expected.to contain_file('/etc/chrony/chrony.keys').with_owner('steve') }
it { is_expected.to contain_file('/etc/chrony/chrony.keys').with_group('mrt') }
Expand Down Expand Up @@ -204,6 +229,21 @@
end
end

context 'hwtimestamps as hash' do
let(:params) do
{
hwtimestamps: { 'eth0' => ['minpoll 1', 'maxpoll 7'] },
}
end

case facts[:osfamily]
when 'Archlinux', 'Redhat'
it { is_expected.to contain_file('/etc/chrony.conf').with_content(%r{^\s*hwtimestamp eth0 minpoll 1 maxpoll 7$}) }
when 'Debian'
it { is_expected.to contain_file('/etc/chrony/chrony.conf').with_content(%r{^\s*hwtimestamp eth0 minpoll 1 maxpoll 7$}) }
end
end

context 'unmanaged chrony.keys file and password' do
let(:params) do
{
Expand Down
19 changes: 18 additions & 1 deletion templates/chrony.conf.epp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ stratumweight <%= $chrony::stratumweight %>
<% } -%>

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
driftfile <%= $chrony::driftfile %>
<% if $chrony::rtcsync { -%>

# Enable kernel RTC synchronization.
rtcsync
<% } -%>
<% if $chrony::makestep_seconds and $chrony::makestep_updates { -%>

# In first <%= $chrony::makestep_updates %> updates step the system clock instead of slew
Expand Down Expand Up @@ -59,6 +61,12 @@ local stratum <%= $chrony::local_stratum %>

keyfile <%= $chrony::config_keys %>
<% } -%>
<% if $chrony::dumpdir { -%>

# Save the measurement history for the servers to files on exit.
dumponexit
dumpdir <%= $chrony::dumpdir %>
<% } -%>
<% if ! $chrony::clientlog { -%>

# Disable logging of client accesses.
Expand Down Expand Up @@ -120,3 +128,12 @@ smoothtime <%= $chrony::smoothtime %>
# https://chrony.tuxfamily.org/doc/3.4/chrony.conf.html#rtconutc
rtconutc
<% } -%>
<% if ! $chrony::hwtimestamps.empty { -%>
Copy link
Member

Choose a reason for hiding this comment

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

Would unless be more readable than if !?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting that you should mention that. I myself prefer unless before if ! in any language that supports it. But, I know people that hates unless. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are more 'if !' in the template, I can add a separate PR later that changes them all to unless, and se if someone else objects.


# Enable hardware timestamping of NTP packets sent to and received from the specified
# network interface. If the specified interface is *, chronyd will try to enable HW
# timestamping on all available interfaces.
<% $chrony::hwtimestamps.each |$interface| { -%>
hwtimestamp <%= $interface.flatten.join(' ') %>
<% } -%>
<% } -%>