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

added support for FreeBSD #6

Merged
merged 2 commits into from
Jun 13, 2016
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
/spec/fixtures/manifests
/spec/fixtures/modules

*.swp
*.swo

# https://tickets.puppetlabs.com/browse/PUP-3444
vendor/**
.bundle/
4 changes: 2 additions & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
file { $openntp::config_file:
ensure => $ensure_config,
content => template($real_template),
owner => 'root',
group => 'root',
owner => $openntp::rootuser,
group => $openntp::rootgroup,
mode => '0644',
}
}
15 changes: 13 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
$server = suffix(range('0', '3'), '.debian.pool.ntp.org')
$package_name = 'openntpd'
$service_name = 'openntpd'
$service_restart = '/usr/local/sbin/restart-openntpd'
$config_file = '/etc/openntpd/ntpd.conf'
$service_restart = $::osfamily ? {
'Debian' => '/usr/local/sbin/restart-openntpd',
default => undef
}
$config_file = $::osfamily ? {
'FreeBSD' => '/usr/local/etc/ntpd.conf',
default => '/etc/openntpd/ntpd.conf'
}
$rootuser = 'root'
$rootgroup = $::osfamily ? {
'FreeBSD' => 'wheel',
default => 'root'
}
}
32 changes: 17 additions & 15 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@
default => false,
}

if $openntp::service_restart == $openntp::params::service_restart {
# The restart script does not properly check if the service is actually stopped; hence, the start command can fail
# to start the service because it is still running. This script checks the status and issues the start command as
# soon as the service is actually stopped.
if $openntp::service_restart != undef {
if $openntp::service_restart == $openntp::params::service_restart {
Copy link
Owner

Choose a reason for hiding this comment

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

Would it make sense to merge both if conditions into one if block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I separated the two if blocks for other variants of openntp::service_restart to come, but the two blocks can certainly be merged.

Copy link
Owner

Choose a reason for hiding this comment

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

hmm k. Looks like YAGNI to me but I'm happy to roll with it for the moment.

# The restart script does not properly check if the service is actually stopped; hence, the start command can fail
# to start the service because it is still running. This script checks the status and issues the start command as
# soon as the service is actually stopped.

$file_ensure = $openntp::ensure ? {
absent => absent,
default => file,
}
$file_ensure = $openntp::ensure ? {
absent => absent,
default => file,
}

file { $openntp::params::service_restart:
ensure => $file_ensure,
content => template('openntp/restart.sh.erb'),
owner => 'root',
group => 'root',
mode => '0555',
before => Service[$openntp::service_name]
file { $openntp::params::service_restart:
ensure => $file_ensure,
content => template('openntp/restart.sh.erb'),
owner => $openntp::rootuser,
group => $openntp::rootgroup,
mode => '0555',
before => Service[$openntp::service_name]
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"12.04",
"14.04"
]
},
{
"operatingsystem": "FreeBSD",
"operatingsystemrelease": [
"10"
]
}
],
"requirements": [
Expand Down
49 changes: 40 additions & 9 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,46 @@
describe 'by default' do
let(:params) { { } }

it { should contain_package('openntpd').with_ensure('installed') }
it { should contain_service('openntpd').with_ensure('running').with_enable(true) }
it { should contain_file(config_file) }
it { should contain_file(config_file).with_ensure('file') }
it { should contain_file(config_file).without_content(/listen on/) }
it { should contain_file(config_file).with_content(/server 0.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 1.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 2.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 3.debian.pool.ntp.org/) }
shared_examples 'a default setup' do
it { should contain_package('openntpd').with_ensure('installed') }
it { should contain_service('openntpd').with_ensure('running').with_enable(true) }
it { should contain_file(config_file) }
it { should contain_file(config_file).with_ensure('file') }
it { should contain_file(config_file).with_owner('root') }
it { should contain_file(config_file).without_content(/listen on/) }
it { should contain_file(config_file).with_content(/server 0.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 1.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 2.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 3.debian.pool.ntp.org/) }
end

it_behaves_like 'a default setup'
it { should_not contain_file('/usr/local/sbin/restart-openntpd') }

describe 'on Debian' do
let(:facts) { {
:concat_basedir => '/path/to/dir',
:osfamily => 'Debian'
} }

it_behaves_like 'a default setup'

it { should contain_file(config_file).with_group('root') }
it { should contain_file('/usr/local/sbin/restart-openntpd') }
end

describe 'on FreeBSD' do
let(:facts) { {
:concat_basedir => '/path/to/dir',
:osfamily => 'FreeBSD'
} }
let(:config_file) { '/usr/local/etc/ntpd.conf' }

it_behaves_like 'a default setup'

it { should contain_file(config_file).with_group('wheel') }
it { should_not contain_file('/usr/local/sbin/restart-openntpd') }
end
end

describe 'with custom version' do
Expand Down