Commit bcc01536 authored by Helen Campbell's avatar Helen Campbell Committed by David Schmitt

Use EPP templates

After this change, the module uses, and can accept EPP templates through the config_epp and step_tickers_epp parameters. ERB templates are still valid through the config_template and step_tickers_template parameters.
Backwards-Compatibility-Saved-By: 's avatarWilson McCoubrey <wilson@puppet.com>
parent ad29f640
......@@ -109,7 +109,7 @@ class { '::ntp':
servers => [ 'ntp1.corp.com', 'ntp2.corp.com' ],
restrict => ['127.0.0.1'],
service_manage => false,
config_template => 'different/module/custom.template.erb',
config_epp => 'different/module/custom.template.epp',
}
```
......@@ -154,7 +154,11 @@ Specifies a file mode for the ntp configuration file. Valid options: string cont
####`config_template`
Specifies a file to act as a template for the config file. Valid options: string containing a path (absolute, or relative to the module path). Default value: 'ntp/ntp.conf.erb'
Specifies a file to act as a ERB template for the config file. Valid options: string containing a path (absolute, or relative to the module path). Example value: 'ntp/ntp.conf.erb'. Validation error will be thrown if this param is supplied as well as the `config_epp` param.
####`config_epp`
Specifies a file to act as a EPP template for the config file. Valid options: string containing a path (absolute, or relative to the module path). Example value: 'ntp/ntp.conf.epp'. Validation error will be thrown if this param is supplied as well as the `config_template` param.
####`disable_auth`
......@@ -319,7 +323,11 @@ Location of the step tickers file on the managed system. Default value: varies b
####`step_tickers_template`
Location of the step tickers template file. Default value: varies by operating system
Location of the step tickers ERB template file. Default value: varies by operating system. Validation error will be thrown if this is specified as well as the `step_tickers_epp` param.
####`step_tickers_epp`
Location of the step tickers EPP template file. Default value: varies by operating system. Validation error will be thrown if this is specified as well as the `step_tickers_template` param.
####`stepout`
......
......@@ -4,8 +4,9 @@ ntp::autoupdate: false
ntp::broadcastclient: false
ntp::config_dir: ~
ntp::config_file_mode: '0644'
ntp::config_template: 'ntp/ntp.conf.erb'
ntp::config: '/etc/ntp.conf'
ntp::config_template: ~
ntp::config_epp: ~
ntp::disable_auth: false
ntp::disable_dhclient: false
ntp::disable_kernel: false
......@@ -44,7 +45,8 @@ ntp::service_name: ntpd
ntp::service_provider: ~
ntp::stepout: ~
ntp::step_tickers_file: ~
ntp::step_tickers_template: 'ntp/step-tickers.erb'
ntp::step_tickers_template: ~
ntp::step_tickers_epp: ~
ntp::tinker: ~
ntp::tos_ceiling: '15'
ntp::tos_cohort: '0'
......
......@@ -27,25 +27,50 @@ class ntp::config inherits ntp {
owner => 0,
group => 0,
mode => '0644',
content => template('ntp/keys.erb'),
content => epp('ntp/keys.epp'),
}
}
#If both epp and erb are defined, throw validation error.
#Otherwise use the defined erb/epp template, or use default
if $ntp::config_epp and $ntp::config_template {
fail('Cannot supply both config_epp and config_template templates for ntp config file.')
} elsif $ntp::config_template {
$config_content = template($ntp::config_template)
} elsif $ntp::config_epp {
$config_content = epp($ntp::config_epp)
} else {
$config_content = epp('ntp/ntp.conf.epp')
}
file { $ntp::config:
ensure => file,
owner => 0,
group => 0,
mode => $::ntp::config_file_mode,
content => template($ntp::config_template),
content => $config_content,
}
#If both epp and erb are defined, throw validation error.
#Otherwise use the defined erb/epp template, or use default
if $::ntp::step_tickers_file {
if $::ntp::step_tickers_template and $::ntp::step_tickers_epp {
fail('Cannot supply both step_tickers_file and step_tickers_epp templates for step ticker file')
} elsif $::ntp::step_tickers_template {
$step_ticker_content = template($ntp::step_tickers_template)
} elsif $::ntp::step_tickers_epp {
$step_ticker_content = epp($::ntp::step_tickers_epp)
} else{
$step_ticker_content = epp('ntp/step-tickers.epp')
}
file { $::ntp::step_tickers_file:
ensure => file,
owner => 0,
group => 0,
mode => $::ntp::config_file_mode,
content => template($ntp::step_tickers_template),
content => $step_ticker_content,
}
}
......
......@@ -4,6 +4,7 @@ class ntp (
Stdlib::Compat::Absolute_path $config,
Variant[Any, Undef, Stdlib::Compat::Absolute_path] $config_dir,
$config_file_mode,
Optional[String] $config_epp,
Stdlib::Compat::String $config_template,
Stdlib::Compat::Bool $disable_auth,
Stdlib::Compat::Bool $disable_dhclient,
......@@ -39,6 +40,7 @@ class ntp (
Variant[Optional[String], Any] $service_provider,
Variant[Boolean, Undef, Stdlib::Compat::Numeric] $stepout,
Variant[Boolean, Undef, Stdlib::Compat::String] $step_tickers_file,
Optional[String] $step_tickers_epp,
Variant[Any, Undef, Stdlib::Compat::String] $step_tickers_template,
Optional[Stdlib::Compat::Bool] $tinker,
Stdlib::Compat::Bool $tos,
......
......@@ -81,20 +81,50 @@ describe "ntp class:", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily'
end
describe 'config_template' do
it 'sets up template' do
before :all do
modulepath = default['distmoduledir']
shell("mkdir -p #{modulepath}/test/templates")
shell("echo 'testcontent' >> #{modulepath}/test/templates/ntp.conf")
# Add spurious template logic to verify the use of the correct template rendering engine
shell("echo '<% [1].each do |i| %>erbserver<%= i %><%end %>' >> #{modulepath}/test/templates/ntp.conf.erb")
end
it 'sets the ntp.conf location' do
pp = "class { 'ntp': config_template => 'test/ntp.conf' }"
it 'sets the ntp.conf erb template location' do
pp = "class { 'ntp': config_template => 'test/ntp.conf.erb' }"
apply_manifest(pp, :catch_failures => true)
end
describe file("#{config}") do
it { should be_file }
its(:content) { should match 'testcontent' }
its(:content) { should match 'erbserver1' }
end
it 'sets the ntp.conf epp template location and the ntp.conf erb template location which should fail' do
pp = "class { 'ntp': config_template => 'test/ntp.conf.erb', config_epp => 'test/ntp.conf.epp' }"
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Cannot supply both config_epp and config_template/i)
end
end
describe 'config_epp' do
before :all do
modulepath = default['distmoduledir']
shell("mkdir -p #{modulepath}/test/templates")
# Add spurious template logic to verify the use of the correct template rendering engine
shell("echo '<% [1].each |$i| { -%>eppserver<%= $i %><% } -%>' >> #{modulepath}/test/templates/ntp.conf.epp")
end
it 'sets the ntp.conf epp template location' do
pp = "class { 'ntp': config_epp => 'test/ntp.conf.epp' }"
apply_manifest(pp, :catch_failures => true)
end
describe file("#{config}") do
it { should be_file }
its(:content) { should match 'eppserver1' }
end
it 'sets the ntp.conf epp template location and the ntp.conf erb template location which should fail' do
pp = "class { 'ntp': config_template => 'test/ntp.conf.erb', config_epp => 'test/ntp.conf.epp' }"
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Cannot supply both config_epp and config_template/i)
end
end
......
......@@ -30,11 +30,14 @@ describe 'ntp' do
it { should contain_file('/var/run/ntp/servers-netconfig').with_ensure_absent }
end
describe 'allows template to be overridden' do
describe 'allows template to be overridden with erb template' do
let(:params) {{ :config_template => 'my_ntp/ntp.conf.erb' }}
it { should contain_file('/etc/ntp.conf').with({
'content' => /server foobar/})
}
it { should contain_file('/etc/ntp.conf').with_content(/erbserver1/) }
end
describe 'allows template to be overridden with epp template' do
let(:params) {{ :config_epp => 'my_ntp/ntp.conf.epp' }}
it { should contain_file('/etc/ntp.conf').with_content(/eppserver1/) }
end
describe 'keys' do
......
# EPP template
<% [1].each |$i| { -%>eppserver<%= $i %><% } -%>
#my uber ntp config
#
server foobar
# ERB template
<% [1].each do |i| %>erbserver<%= i %><%end %>
# THIS FILE IS MANAGED BY PUPPET
<% $ntp::keys.each |$key| { -%>
<%= $key %>
<% } -%>
# THIS FILE IS MANAGED BY PUPPET
<% if @keys != [] -%>
<% @keys.flatten.each do |keys| -%>
<%= keys %>
<% end -%>
<% end -%>
# ntp.conf: Managed by puppet.
#
<% if @_tinker == true and (@_panic or @stepout) -%>
# Enable next tinker options:
# panic - keep ntpd from panicking in the event of a large clock skew
# when a VM guest is suspended and resumed;
# stepout - allow ntpd change offset faster
tinker<% if @_panic -%> panic <%= @_panic %><% end %><% if @stepout -%> stepout <%= @stepout %><% end %>
<% end -%>
<% if $ntp::_tinker and ($ntp::_panic or $ntp::stepout) {-%>
tinker<% if $ntp::_panic { %> panic <%= $ntp::_panic %><% } %><%if $ntp::stepout { %> stepout <%=$ntp::stepout %><% } %>
<% } -%>
<% if @disable_monitor == true -%>
<% if $ntp::disable_monitor {-%>
disable monitor
<% end -%>
<% if @disable_auth == true -%>
<% } -%>
<% if $ntp::disable_auth {-%>
disable auth
<% end -%>
<% if @disable_kernel == true -%>
<% } -%>
<% if $ntp::disable_kernel {-%>
disable kernel
<% end -%>
<% } -%>
<% if @restrict != [] -%>
<% unless $ntp::restrict.empty {-%>
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
<% @restrict.flatten.each do |restrict| -%>
restrict <%= restrict %>
<% end -%>
<% end -%>
<% $ntp::restrict.each |$restrict| {-%>
restrict <%= $restrict %>
<% } -%>
<% } -%>
<% if @interfaces != [] -%>
<% if @interfaces_ignore != [] -%>
<% @interfaces_ignore.flatten.each do |interface| -%>
interface ignore <%= interface %>
<% end -%>
<% else -%>
<% unless $ntp::interfaces.empty {-%>
<% if $ntp::interfaces_ignore.empty {-%>
# Ignore wildcard interface and only listen on the following specified
# interfaces
interface ignore wildcard
<% end -%>
<% @interfaces.flatten.each do |interface| -%>
interface listen <%= interface %>
<% end -%>
<% end -%>
<% } else {-%>
<% $ntp::interfaces_ignore.each |$interface| {-%>
interface ignore <%= $interface %>
<% } -%>
<% } -%>
<% $ntp::interfaces.each |$interface| {-%>
interface listen <%= $interface %>
<% } -%>
<% } -%>
<% if @broadcastclient == true -%>
<% if $ntp::broadcastclient {-%>
broadcastclient
<% end -%>
<% } -%>
# Set up servers for ntpd with next options:
# server - IP address or DNS name of upstream NTP server
......@@ -51,64 +51,63 @@ broadcastclient
# prefer - select preferrable server
# minpoll - set minimal update frequency
# maxpoll - set maximal update frequency
<% [@servers].flatten.each do |server| -%>
server <%= server %><% if @iburst_enable == true -%> iburst<% end %><% if @preferred_servers.include?(server) -%> prefer<% end %><% if @minpoll -%> minpoll <%= @minpoll %><% end %><% if @maxpoll -%> maxpoll <%= @maxpoll %><% end %>
<% end -%>
<% $ntp::servers.each |$server| {-%>
server <%= $server %><% if $ntp::iburst_enable == true {%> iburst<% } %><% if ($ntp::preferred_servers).member($server) { %> prefer<% } %><% if $ntp::minpoll { %> minpoll <%= $ntp::minpoll %><% } %><% if $ntp::maxpoll { %> maxpoll <%= $ntp::maxpoll %><% } %>
<% } -%>
<% if @udlc -%>
<% if $ntp::udlc {-%>
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server 127.127.1.0
fudge 127.127.1.0 stratum <%= @udlc_stratum %>
fudge 127.127.1.0 stratum <%= $ntp::udlc_stratum %>
restrict 127.127.1.0
<% end -%>
<% } -%>
# Driftfile.
driftfile <%= @driftfile %>
driftfile <%= $ntp::driftfile %>
<% unless @logfile.nil? -%>
<% if $ntp::logfile {-%>
# Logfile
logfile <%= @logfile %>
<% end -%>
logfile <%= $ntp::logfile %>
<% } -%>
<% unless @ntpsigndsocket.nil? -%>
<% if $ntp::ntpsigndsocket {-%>
# Enable signed packets
ntpsigndsocket <%= @ntpsigndsocket %>
<% end -%>
ntpsigndsocket <%= $ntp::ntpsigndsocket %>
<% } -%>
<% unless @peers.empty? -%>
<% unless $ntp::peers.empty {-%>
# Peers
<% [@peers].flatten.each do |peer| -%>
peer <%= peer %>
<% end -%>
<% end -%>
<% $ntp::peers.each |$peer| {-%>
peer <%= $peer %>
<% } -%>
<% } -%>
<% if @keys_enable -%>
keys <%= @keys_file %>
<% unless @keys_trusted.empty? -%>
trustedkey <%= @keys_trusted.join(' ') %>
<% end -%>
<% if @keys_requestkey != '' -%>
requestkey <%= @keys_requestkey %>
<% end -%>
<% if @keys_controlkey != '' -%>
controlkey <%= @keys_controlkey %>
<% end -%>
<% if $ntp::keys_enable {-%>
keys <%= $ntp::keys_file %>
<% unless $ntp::keys_trusted.empty {-%>
trustedkey <%= $ntp::keys_trusted.join(' ') %>
<% } -%>
<% if $ntp::keys_requestkey != '' {-%>
requestkey <%= $ntp::keys_requestkey %>
<% } -%>
<% if $ntp::keys_controlkey != '' {-%>
controlkey <%= $ntp::keys_controlkey %>
<% } -%>
<% } -%>
<% $ntp::fudge.each |$entry| {-%>
fudge <%= $entry %>
<% } -%>
<% end -%>
<% [@fudge].flatten.each do |entry| -%>
fudge <%= entry %>
<% end -%>
<% unless @leapfile.nil? -%>
<% if $ntp::leapfile {-%>
# Leapfile
leapfile <%= @leapfile %>
<% end -%>
leapfile <%= $ntp::leapfile %>
<% } -%>
<% if @tos == true -%>
tos <% if @tos_minclock -%> minclock <%= @tos_minclock %><% end %><% if @tos_minsane -%> minsane <%= @tos_minsane %><% end %><% if @tos_floor -%> floor <%= @tos_floor %><% end %><% if @tos_ceiling -%> ceiling <%= @tos_ceiling %><% end %><% if @tos_cohort -%> cohort <%= @tos_cohort %><% end %>
<% end %>
<% if $ntp::tos {-%>
tos <% if $ntp::tos_minclock {-%> minclock <%= $ntp::tos_minclock %><% } %><% if $ntp::tos_minsane {-%> minsane <%= $ntp::tos_minsane %><% } %><% if $ntp::tos_floor {-%> floor <%= $ntp::tos_floor %><% } %><% if $ntp::tos_ceiling {-%> ceiling <%= $ntp::tos_ceiling %><% } %><% if $ntp::tos_cohort {-%> cohort <%= $ntp::tos_cohort %><% } %>
<% } %>
<% unless @authprov.nil? -%>
authprov <%= @authprov %>
<% end -%>
<% if $ntp::authprov {-%>
authprov <%= $ntp::authprov %>
<% } -%>
# List of NTP servers used by the ntpdate service.
<% $ntp::servers.each |$server| { -%>
<% if $ntp::preferred_servers.size() == 0 or $ntp::preferred_servers.member($server) { -%>
<%= $server %>
<% } -%>
<% } -%>
# List of NTP servers used by the ntpdate service.
<% if @preferred_servers.empty? -%>
<% [@servers].flatten.each do |server| -%>
<%= server %>
<% end -%>
<% else -%>
<% [@servers].flatten.each do |server| -%>
<% if @preferred_servers.include?(server) -%>
<%= server %>
<% end -%>
<% end -%>
<% end -%>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment