Skip to content

Commit a142cad

Browse files
committed
Update dns_rfc2136 plugin package handling
This makes it a parameter and updates it for more distributions. Also fixes the unit tests and adds acceptance tests.
1 parent dea27d5 commit a142cad

File tree

6 files changed

+134
-64
lines changed

6 files changed

+134
-64
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Example:
156156

157157
```puppet
158158
class { 'letsencrypt::plugin::dns_rfc2136':
159-
server => '1.2.3.4',
159+
server => '192.0.2.1',
160160
key_name => 'certbot',
161161
key_secret => '[...]==',
162162
}

manifests/params.pp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,41 @@
2121
$package_name = 'certbot'
2222
$package_command = 'certbot'
2323
$config_dir = '/etc/letsencrypt'
24+
$dns_rfc2136_package_name = 'python3-certbot-dns-rfc2136'
2425
} elsif $facts['osfamily'] == 'RedHat' {
2526
$install_method = 'package'
2627
$package_name = 'certbot'
2728
$package_command = 'certbot'
2829
$config_dir = '/etc/letsencrypt'
30+
if $facts['operatingsystemmajrelease'] == '7' {
31+
$dns_rfc2136_package_name = 'python2-certbot-dns-rfc2136'
32+
} else {
33+
$dns_rfc2136_package_name = 'python3-certbot-dns-rfc2136'
34+
}
2935
} elsif $facts['osfamily'] == 'Gentoo' {
3036
$install_method = 'package'
3137
$package_name = 'app-crypt/certbot'
3238
$package_command = 'certbot'
3339
$config_dir = '/etc/letsencrypt'
40+
$dns_rfc2136_package_name = undef
3441
} elsif $facts['osfamily'] == 'OpenBSD' {
3542
$install_method = 'package'
3643
$package_name = 'certbot'
3744
$package_command = 'certbot'
3845
$config_dir = '/etc/letsencrypt'
46+
$dns_rfc2136_package_name = undef
3947
} elsif $facts['osfamily'] == 'FreeBSD' {
4048
$install_method = 'package'
4149
$package_name = 'py27-certbot'
4250
$package_command = 'certbot'
4351
$config_dir = '/usr/local/etc/letsencrypt'
52+
$dns_rfc2136_package_name = undef
4453
} else {
4554
$install_method = 'vcs'
4655
$package_name = 'letsencrypt'
4756
$package_command = 'letsencrypt'
4857
$config_dir = '/etc/letsencrypt'
58+
$dns_rfc2136_package_name = undef
4959
}
5060

5161
$config_file = "${config_dir}/cli.ini"

manifests/plugin/dns_rfc2136.pp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,25 @@
1919
# Number of seconds to wait for the DNS server to propagate the DNS-01 challenge.
2020
# [*manage_package*]
2121
# Manage the plugin package.
22+
# [*package_name*]
23+
# The name of the package to install when $manage_package is true.
2224
# [*config_dir*]
2325
# The path to the configuration directory.
2426
#
2527
class letsencrypt::plugin::dns_rfc2136 (
2628
Stdlib::Host $server,
2729
String[1] $key_name,
2830
String[1] $key_secret,
29-
String[1] $key_algorithm = $letsencrypt::params::dns_rfc2136_algorithm,
30-
Stdlib::Port $port = $letsencrypt::params::dns_rfc2136_port,
31-
Integer $propagation_seconds = $letsencrypt::params::dns_rfc2136_propagation_seconds,
31+
String[1] $key_algorithm = $letsencrypt::dns_rfc2136_algorithm,
32+
Stdlib::Port $port = $letsencrypt::dns_rfc2136_port,
33+
Integer $propagation_seconds = $letsencrypt::dns_rfc2136_propagation_seconds,
3234
Stdlib::Absolutepath $config_dir = $letsencrypt::config_dir,
33-
Boolean $manage_package = $letsencrypt::params::dns_rfc2136_manage_package,
35+
Boolean $manage_package = $letsencrypt::dns_rfc2136_manage_package,
36+
String $package_name = $letsencrypt::dns_rfc2136_package_name,
3437
) {
3538

36-
if ($manage_package) {
37-
package { 'python2-certbot-dns-rfc2136':
39+
if $manage_package {
40+
package { $package_name:
3841
ensure => installed,
3942
}
4043
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'letsencrypt::plugin::dns_rfc2136' do
4+
supported = case fact('os.family')
5+
when 'Debian'
6+
# Debian 9 has it in backports, Ubuntu started shipping in Bionic
7+
fact('os.release.major') != '9' && fact('os.release.major') != '16.04'
8+
when 'RedHat'
9+
true
10+
else
11+
false
12+
end
13+
14+
context 'with defaults values' do
15+
pp = <<-PUPPET
16+
class { 'letsencrypt' :
17+
email => '[email protected]',
18+
config => {
19+
'server' => 'https://acme-staging.api.letsencrypt.org/directory',
20+
},
21+
}
22+
class { 'letsencrypt::plugin::dns_rfc2136':
23+
server => '192.0.2.1',
24+
key_name => 'certbot',
25+
key_secret => 'secret',
26+
}
27+
PUPPET
28+
29+
if supported
30+
it 'installs letsencrypt and dns rfc2136 plugin without error' do
31+
apply_manifest(pp, catch_failures: true)
32+
end
33+
it 'installs letsencrypt and dns rfc2136 idempotently' do
34+
apply_manifest(pp, catch_changes: true)
35+
end
36+
37+
describe file('/etc/letsencrypt/dns-rfc2136.ini') do
38+
it { is_expected.to be_file }
39+
it { is_expected.to be_owned_by 'root' }
40+
it { is_expected.to be_grouped_into 'root' }
41+
it { is_expected.to be_mode 400 }
42+
end
43+
else
44+
it 'fails to install' do
45+
apply_manifest(pp, expect_failures: true)
46+
end
47+
end
48+
end
49+
end

spec/classes/plugin/dns_rfc2136_spec.rb

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,71 @@
22

33
describe 'letsencrypt::plugin::dns_rfc2136' do
44
on_supported_os.each do |os, facts|
5-
let(:facts) do
6-
facts
7-
end
8-
9-
let(:params) { default_params.merge(required_params).merge(additional_params) }
10-
let(:default_params) do
11-
{ key_algorithm: 'HMAC-SHA512',
12-
port: 53,
13-
manage_package: true,
14-
config_dir: '/etc/letsencrypt',
15-
propagation_seconds: 10 }
16-
end
17-
let(:required_params) { {} }
18-
let(:additional_params) { {} }
19-
20-
context 'without required parameters' do
21-
it { is_expected.not_to compile }
22-
end
23-
245
context "on #{os} based operating systems" do
25-
let(:required_params) do
26-
{ server: '1.2.3.4',
27-
key_name: 'certbot',
28-
key_secret: 'secret' }
29-
end
6+
let(:facts) { facts }
7+
let(:params) { {} }
308
let(:pre_condition) do
31-
"class { letsencrypt:
32-
email => '[email protected]',
33-
config_dir => '/etc/letsencrypt',
34-
package_command => 'letsencrypt',
35-
}"
9+
<<-PUPPET
10+
class { 'letsencrypt':
11+
email => '[email protected]',
12+
}
13+
PUPPET
14+
end
15+
let(:package_name) do
16+
case facts[:osfamily]
17+
when 'Debian'
18+
'python3-certbot-dns-rfc2136'
19+
when 'RedHat'
20+
facts[:operatingsystem] == 'Fedora' ? 'python3-certbot-dns-rfc2136' : 'python2-certbot-dns-rfc2136'
21+
end
3622
end
3723

38-
it { is_expected.to compile.with_all_deps }
24+
context 'without required parameters' do
25+
it { is_expected.not_to compile }
26+
end
3927

40-
describe 'with manage_package => true' do
41-
let(:additional_params) { { manage_package: true } }
28+
context 'with required parameters' do
29+
let(:params) do
30+
super().merge(
31+
server: '192.0.2.1',
32+
key_name: 'certbot',
33+
key_secret: 'secret'
34+
)
35+
end
4236

43-
it { is_expected.to contain_package('python2-certbot-dns-rfc2136').with_ensure('installed') }
44-
end
37+
it do
38+
if package_name.nil?
39+
is_expected.not_to compile
40+
else
41+
is_expected.to compile.with_all_deps
4542

46-
describe 'with manage_package => false' do
47-
let(:additional_params) { { manage_package: false } }
43+
is_expected.to contain_file('/etc/letsencrypt/dns-rfc2136.ini').
44+
with_ensure('file').
45+
with_owner('root').
46+
with_group('root').
47+
with_mode('0400').
48+
with_content(%r{^.*dns_rfc2136_server.*$})
49+
end
50+
end
4851

49-
it { is_expected.not_to contain_package('python2-certbot-dns-rfc2136') }
50-
end
52+
describe 'with manage_package => true' do
53+
let(:params) { super().merge(manage_package: true) }
54+
55+
it do
56+
if package_name.nil?
57+
is_expected.not_to compile
58+
else
59+
is_expected.to contain_class('letsencrypt::plugin::dns_rfc2136').with_package_name(package_name)
60+
is_expected.to contain_package(package_name).with_ensure('installed')
61+
end
62+
end
63+
end
64+
65+
describe 'with manage_package => false' do
66+
let(:params) { super().merge(manage_package: false, package_name: 'dns-rfc2136-package') }
5167

52-
it do
53-
is_expected.to contain_file('/etc/letsencrypt/dns-rfc2136.ini').with(
54-
ensure: 'file',
55-
owner: 'root',
56-
group: 'root',
57-
mode: '0400'
58-
).with_content(%r{^.*dns_rfc2136_server.*$})
68+
it { is_expected.not_to contain_package('dns-rfc2136-package') }
69+
end
5970
end
6071
end
6172
end

spec/defines/letsencrypt_certonly_spec.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,20 @@
105105

106106
context 'with dns-rfc2136 plugin' do
107107
let(:title) { 'foo.example.com' }
108-
let(:params) { { plugin: 'dns-rfc2136', letsencrypt_command: "letsencrypt" } }
108+
let(:params) { { plugin: 'dns-rfc2136', letsencrypt_command: 'letsencrypt' } }
109109
let(:pre_condition) do
110-
"class { 'letsencrypt':
110+
<<-PUPPET
111+
class { 'letsencrypt':
111112
email => '[email protected]',
112113
config_dir => '/etc/letsencrypt',
113-
venv_path => '/opt/letsencrypt/.venv',
114114
}
115115
class { 'letsencrypt::plugin::dns_rfc2136':
116-
server => '1.2.3.4',
117-
key_name => 'certbot',
118-
key_secret => 'secret',
119-
key_algorithm => 'HMAC-SHA512',
120-
port => 53,
121-
manage_package => true,
122-
config_dir => '/etc/letsencrypt',
123-
propagation_seconds => 10,
124-
}"
116+
server => '192.0.2.1',
117+
key_name => 'certbot',
118+
key_secret => 'secret',
119+
package_name => 'irrelevant',
120+
}
121+
PUPPET
125122
end
126123

127124
it { is_expected.to compile.with_all_deps }

0 commit comments

Comments
 (0)