From 8d0efec9fb5a5df42ed64375c71a11d8b6f90b4c Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 16 Feb 2021 14:12:59 +0100 Subject: [PATCH] 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. --- manifests/dnfmodule.pp | 20 ++++++++++++++++ manifests/globals.pp | 11 +++++++++ manifests/params.pp | 2 +- spec/unit/classes/client_spec.rb | 12 ++++++++++ spec/unit/classes/server_spec.rb | 41 ++++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 manifests/dnfmodule.pp diff --git a/manifests/dnfmodule.pp b/manifests/dnfmodule.pp new file mode 100644 index 0000000000..a1cb4b9a1f --- /dev/null +++ b/manifests/dnfmodule.pp @@ -0,0 +1,20 @@ +# @summary Manage the DNF module +# +# 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. +# +# @api private +class postgresql::dnfmodule ( + String[1] $ensure = 'installed', + String[1] $module = 'postgresql', +) { + package { 'postgresql dnf module': + ensure => $ensure, + name => $module, + enable_only => true, + provider => 'dnfmodule', + } + + Package['postgresql dnf module'] -> Package<|tag == 'puppetlabs-postgresql'|> +} diff --git a/manifests/globals.pp b/manifests/globals.pp index b4d73a2aa9..db39f1c9f5 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -86,6 +86,10 @@ # @param manage_xlogdir Set to false if you have file{ $xlogdir: } already defined # # @param manage_package_repo Sets up official PostgreSQL repositories on your host if set to true. +# @param manage_dnf_module +# Manage the DNF module. This only makes sense on distributions that use DNF +# package manager, such as EL8 or Fedora. It also requires Puppet 5.5.20+ or +# Puppet 6.15.0+ since they ship the dnfmodule provider. # @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. # # @@ -153,6 +157,7 @@ $manage_selinux = undef, $manage_package_repo = undef, + Boolean $manage_dnf_module = false, $module_workdir = undef, ) { # We are determining this here, because it is needed by the package repo @@ -265,4 +270,10 @@ baseurl => $repo_baseurl, } } + + if $manage_dnf_module { + class { 'postgresql::dnfmodule': + ensure => $globals_version, + } + } } diff --git a/manifests/params.pp b/manifests/params.pp index de3eccf40b..f557b27046 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -41,7 +41,7 @@ $version_parts = split($version, '[.]') $package_version = "${version_parts[0]}${version_parts[1]}" - if $version == $postgresql::globals::default_version and $facts['os']['name'] != 'Amazon' { + if $version == $postgresql::globals::default_version and $facts['os']['name'] != 'Amazon' or $postgresql::globals::manage_dnf_module { $client_package_name = pick($client_package_name, 'postgresql') $server_package_name = pick($server_package_name, 'postgresql-server') $contrib_package_name = pick($contrib_package_name,'postgresql-contrib') diff --git a/spec/unit/classes/client_spec.rb b/spec/unit/classes/client_spec.rb index 5ee4dbc1e2..a01311f9c7 100644 --- a/spec/unit/classes/client_spec.rb +++ b/spec/unit/classes/client_spec.rb @@ -43,6 +43,18 @@ end end + describe 'with manage_dnf_module true' do + let(:pre_condition) do + <<-PUPPET + class { 'postgresql::globals': + manage_dnf_module => true, + } + PUPPET + end + + it { is_expected.to contain_package('postgresql dnf module').that_comes_before('Package[postgresql-client]') } + end + describe 'with client package name explicitly set undef' do let :params do { diff --git a/spec/unit/classes/server_spec.rb b/spec/unit/classes/server_spec.rb index 29240ed300..a44c96f924 100644 --- a/spec/unit/classes/server_spec.rb +++ b/spec/unit/classes/server_spec.rb @@ -35,6 +35,47 @@ end end + describe 'with manage_dnf_module true' do + let(:facts) do + { + os: { + family: 'RedHat', + name: 'RedHat', + release: { 'full' => '8.3', 'major' => '8' }, + selinux: { + enabled: true, + } + }, + osfamily: 'RedHat', + } + end + + let(:pre_condition) do + <<-PUPPET + class { 'postgresql::globals': + manage_dnf_module => true, + } + PUPPET + end + + it { is_expected.to contain_package('postgresql dnf module').with_ensure('10').that_comes_before('Package[postgresql-server]') } + it { is_expected.to contain_package('postgresql-server').with_name('postgresql-server') } + + describe 'with version set' do + let(:pre_condition) do + <<-PUPPET + class { 'postgresql::globals': + manage_dnf_module => true, + version => '12', + } + PUPPET + end + + it { is_expected.to contain_package('postgresql dnf module').with_ensure('12').that_comes_before('Package[postgresql-server]') } + it { is_expected.to contain_package('postgresql-server').with_name('postgresql-server') } + end + end + describe 'service_ensure => running' do let(:params) do {