Skip to content

Commit 8d0efec

Browse files
committed
Add DNF module management
On EL8 and Fedora DNF can manage modules. This is a method of providing multiple versions on the same OS. Only one DNF module can be active at the same time.
1 parent 25b816e commit 8d0efec

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

manifests/dnfmodule.pp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# @summary Manage the DNF module
2+
#
3+
# On EL8 and Fedora DNF can manage modules. This is a method of providing
4+
# multiple versions on the same OS. Only one DNF module can be active at the
5+
# same time.
6+
#
7+
# @api private
8+
class postgresql::dnfmodule (
9+
String[1] $ensure = 'installed',
10+
String[1] $module = 'postgresql',
11+
) {
12+
package { 'postgresql dnf module':
13+
ensure => $ensure,
14+
name => $module,
15+
enable_only => true,
16+
provider => 'dnfmodule',
17+
}
18+
19+
Package['postgresql dnf module'] -> Package<|tag == 'puppetlabs-postgresql'|>
20+
}

manifests/globals.pp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
# @param manage_xlogdir Set to false if you have file{ $xlogdir: } already defined
8787
#
8888
# @param manage_package_repo Sets up official PostgreSQL repositories on your host if set to true.
89+
# @param manage_dnf_module
90+
# Manage the DNF module. This only makes sense on distributions that use DNF
91+
# package manager, such as EL8 or Fedora. It also requires Puppet 5.5.20+ or
92+
# Puppet 6.15.0+ since they ship the dnfmodule provider.
8993
# @param module_workdir Specifies working directory under which the psql command should be executed. May need to specify if '/tmp' is on volume mounted with noexec option.
9094
#
9195
#
@@ -153,6 +157,7 @@
153157
$manage_selinux = undef,
154158

155159
$manage_package_repo = undef,
160+
Boolean $manage_dnf_module = false,
156161
$module_workdir = undef,
157162
) {
158163
# We are determining this here, because it is needed by the package repo
@@ -265,4 +270,10 @@
265270
baseurl => $repo_baseurl,
266271
}
267272
}
273+
274+
if $manage_dnf_module {
275+
class { 'postgresql::dnfmodule':
276+
ensure => $globals_version,
277+
}
278+
}
268279
}

manifests/params.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
$version_parts = split($version, '[.]')
4242
$package_version = "${version_parts[0]}${version_parts[1]}"
4343

44-
if $version == $postgresql::globals::default_version and $facts['os']['name'] != 'Amazon' {
44+
if $version == $postgresql::globals::default_version and $facts['os']['name'] != 'Amazon' or $postgresql::globals::manage_dnf_module {
4545
$client_package_name = pick($client_package_name, 'postgresql')
4646
$server_package_name = pick($server_package_name, 'postgresql-server')
4747
$contrib_package_name = pick($contrib_package_name,'postgresql-contrib')

spec/unit/classes/client_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@
4343
end
4444
end
4545

46+
describe 'with manage_dnf_module true' do
47+
let(:pre_condition) do
48+
<<-PUPPET
49+
class { 'postgresql::globals':
50+
manage_dnf_module => true,
51+
}
52+
PUPPET
53+
end
54+
55+
it { is_expected.to contain_package('postgresql dnf module').that_comes_before('Package[postgresql-client]') }
56+
end
57+
4658
describe 'with client package name explicitly set undef' do
4759
let :params do
4860
{

spec/unit/classes/server_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,47 @@
3535
end
3636
end
3737

38+
describe 'with manage_dnf_module true' do
39+
let(:facts) do
40+
{
41+
os: {
42+
family: 'RedHat',
43+
name: 'RedHat',
44+
release: { 'full' => '8.3', 'major' => '8' },
45+
selinux: {
46+
enabled: true,
47+
}
48+
},
49+
osfamily: 'RedHat',
50+
}
51+
end
52+
53+
let(:pre_condition) do
54+
<<-PUPPET
55+
class { 'postgresql::globals':
56+
manage_dnf_module => true,
57+
}
58+
PUPPET
59+
end
60+
61+
it { is_expected.to contain_package('postgresql dnf module').with_ensure('10').that_comes_before('Package[postgresql-server]') }
62+
it { is_expected.to contain_package('postgresql-server').with_name('postgresql-server') }
63+
64+
describe 'with version set' do
65+
let(:pre_condition) do
66+
<<-PUPPET
67+
class { 'postgresql::globals':
68+
manage_dnf_module => true,
69+
version => '12',
70+
}
71+
PUPPET
72+
end
73+
74+
it { is_expected.to contain_package('postgresql dnf module').with_ensure('12').that_comes_before('Package[postgresql-server]') }
75+
it { is_expected.to contain_package('postgresql-server').with_name('postgresql-server') }
76+
end
77+
end
78+
3879
describe 'service_ensure => running' do
3980
let(:params) do
4081
{

0 commit comments

Comments
 (0)