Skip to content

implement key parameter for config_entry defined resource #1454

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

Merged
merged 1 commit into from
Jul 3, 2023
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
9 changes: 6 additions & 3 deletions manifests/server/config_entry.pp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# @summary Manage a postgresql.conf entry.
#
# @param ensure Removes an entry if set to 'absent'.
# @param key Defines the key/name for the setting. Defaults to $name
# @param value Defines the value for the setting.
# @param path Path for postgresql.conf
#
define postgresql::server::config_entry (
Enum['present', 'absent'] $ensure = 'present',
String[1] $key = $name,
Optional[Variant[String[1], Numeric, Array[String[1]]]] $value = undef,
Variant[Boolean, String[1]] $path = false
) {
Expand Down Expand Up @@ -70,9 +72,9 @@
'max_pred_locks_per_transaction' => undef,
}

if ! ($name in $requires_restart_until and (
! $requires_restart_until[$name] or
versioncmp($postgresql::server::_version, $requires_restart_until[$name]) < 0
if ! ($key in $requires_restart_until and (
! $requires_restart_until[$key] or
versioncmp($postgresql::server::_version, $requires_restart_until[$key]) < 0
)) {
Postgresql_conf {
notify => Class['postgresql::server::reload'],
Expand All @@ -90,6 +92,7 @@
postgresql_conf { $name:
ensure => $ensure,
target => $target,
name => $key,
value => $value,
require => Class['postgresql::server::initdb'],
}
Expand Down
22 changes: 14 additions & 8 deletions manifests/server/instance/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@
}

if $listen_addresses {
postgresql::server::config_entry { 'listen_addresses':
postgresql::server::config_entry { "listen_addresses_for_instance_${name}":
key => 'listen_addresses',
value => $listen_addresses,
}
}
Expand Down Expand Up @@ -182,37 +183,42 @@
exec { "/usr/sbin/semanage port -a -t postgresql_port_t -p tcp ${port}":
command => $exec_command,
unless => $exec_unless,
before => Postgresql::Server::Config_entry['port'],
before => Postgresql::Server::Config_entry["port_for_instance_${name}"],
require => Package[$package_name],
}
}

postgresql::server::config_entry { 'port':
postgresql::server::config_entry { "port_for_instance_${name}":
key => 'port',
value => $port,
}

if ($password_encryption) and (versioncmp($version, '10') >= 0) {
postgresql::server::config_entry { 'password_encryption':
postgresql::server::config_entry { "password_encryption_for_instance_${name}":
key => 'password_encryption',
value => $password_encryption,
}
}

postgresql::server::config_entry { 'data_directory':
postgresql::server::config_entry { "data_directory_for_instance_${name}":
key => 'data_directory',
value => $datadir,
}
if $timezone {
postgresql::server::config_entry { 'timezone':
postgresql::server::config_entry { "timezone_for_instance_${name}":
key => 'timezone',
value => $timezone,
}
}
if $logdir {
postgresql::server::config_entry { 'log_directory':
postgresql::server::config_entry { "log_directory for instance ${name}":
value => $logdir,
}
}
# Allow timestamps in log by default
if $log_line_prefix {
postgresql::server::config_entry { 'log_line_prefix':
postgresql::server::config_entry { "log_line_prefix_for_instance_${name}":
key => 'log_line_prefix',
value => $log_line_prefix,
}
}
Expand Down
8 changes: 4 additions & 4 deletions spec/classes/server/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

expect(subject).to contain_exec('/usr/sbin/semanage port -a -t postgresql_port_t -p tcp 5432')
.with(unless: '/usr/sbin/semanage port -l | grep -qw 5432')
.that_comes_before('Postgresql::Server::Config_entry[port]')
.that_comes_before('Postgresql::Server::Config_entry[port_for_instance_main]')
.that_requires('Package[policycoreutils-python]')
end

Expand Down Expand Up @@ -60,7 +60,7 @@ class { 'postgresql::server': }

expect(subject).to contain_exec('/usr/sbin/semanage port -a -t postgresql_port_t -p tcp 5432')
.with(unless: '/usr/sbin/semanage port -l | grep -qw 5432')
.that_comes_before('Postgresql::Server::Config_entry[port]')
.that_comes_before('Postgresql::Server::Config_entry[port_for_instance_main]')
.that_requires('Package[policycoreutils-python-utils]')
end

Expand Down Expand Up @@ -105,7 +105,7 @@ class { 'postgresql::server': }

expect(subject).to contain_exec('/usr/sbin/semanage port -a -t postgresql_port_t -p tcp 5432')
.with(unless: '/usr/sbin/semanage port -l | grep -qw 5432')
.that_comes_before('Postgresql::Server::Config_entry[port]')
.that_comes_before('Postgresql::Server::Config_entry[port_for_instance_main]')
.that_requires('Package[policycoreutils-python-utils]')
end

Expand Down Expand Up @@ -150,7 +150,7 @@ class { 'postgresql::server': }

expect(subject).to contain_exec('/usr/sbin/semanage port -a -t postgresql_port_t -p tcp 5432')
.with(unless: '/usr/sbin/semanage port -l | grep -qw 5432')
.that_comes_before('Postgresql::Server::Config_entry[port]')
.that_comes_before('Postgresql::Server::Config_entry[port_for_instance_main]')
.that_requires('Package[policycoreutils]')
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class { 'postgresql::globals':
it { is_expected.to contain_class('postgresql::server') }

it {
expect(subject).not_to contain_Postgresql_conf('data_directory').that_notifies('Class[postgresql::server::service]')
expect(subject).not_to contain_Postgresql_conf('data_directory_for_instance_main').that_notifies('Class[postgresql::server::service]')
}

it 'validates connection' do
Expand All @@ -129,9 +129,11 @@ class { 'postgresql::globals':
it { is_expected.to contain_class('postgresql::server') }

it {
expect(subject).to contain_Postgresql_conf('data_directory').that_notifies('Class[postgresql::server::service]')
expect(subject).to contain_Postgresql_conf('data_directory_for_instance_main').that_notifies('Class[postgresql::server::service]')
}

it { is_expected.to contain_postgresql__server__config_entry('data_directory_for_instance_main') }

it 'validates connection' do
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running')
end
Expand Down