Skip to content

Commit ad3731a

Browse files
implement key parameter for config_entry defined resource
* postgres instances require unique resource titles
1 parent 1706fb3 commit ad3731a

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

manifests/server/config_entry.pp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# @summary Manage a postgresql.conf entry.
22
#
33
# @param ensure Removes an entry if set to 'absent'.
4+
# @param key Defines the key/name for the setting. Defaults to $name
45
# @param value Defines the value for the setting.
56
# @param path Path for postgresql.conf
67
#
78
define postgresql::server::config_entry (
89
Enum['present', 'absent'] $ensure = 'present',
10+
String[1] $key = $name,
911
Optional[Variant[String[1], Numeric, Array[String[1]]]] $value = undef,
1012
Variant[Boolean, String[1]] $path = false
1113
) {
@@ -70,9 +72,9 @@
7072
'max_pred_locks_per_transaction' => undef,
7173
}
7274

73-
if ! ($name in $requires_restart_until and (
74-
! $requires_restart_until[$name] or
75-
versioncmp($postgresql::server::_version, $requires_restart_until[$name]) < 0
75+
if ! ($key in $requires_restart_until and (
76+
! $requires_restart_until[$key] or
77+
versioncmp($postgresql::server::_version, $requires_restart_until[$key]) < 0
7678
)) {
7779
Postgresql_conf {
7880
notify => Class['postgresql::server::reload'],
@@ -90,6 +92,7 @@
9092
postgresql_conf { $name:
9193
ensure => $ensure,
9294
target => $target,
95+
name => $key,
9396
value => $value,
9497
require => Class['postgresql::server::initdb'],
9598
}

manifests/server/instance/config.pp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@
149149
}
150150

151151
if $listen_addresses {
152-
postgresql::server::config_entry { 'listen_addresses':
152+
postgresql::server::config_entry { "listen_addresses_for_instance_${name}":
153+
key => 'listen_addresses',
153154
value => $listen_addresses,
154155
}
155156
}
@@ -182,37 +183,42 @@
182183
exec { "/usr/sbin/semanage port -a -t postgresql_port_t -p tcp ${port}":
183184
command => $exec_command,
184185
unless => $exec_unless,
185-
before => Postgresql::Server::Config_entry['port'],
186+
before => Postgresql::Server::Config_entry["port_for_instance_${name}"],
186187
require => Package[$package_name],
187188
}
188189
}
189190

190-
postgresql::server::config_entry { 'port':
191+
postgresql::server::config_entry { "port_for_instance_${name}":
192+
key => 'port',
191193
value => $port,
192194
}
193195

194196
if ($password_encryption) and (versioncmp($version, '10') >= 0) {
195-
postgresql::server::config_entry { 'password_encryption':
197+
postgresql::server::config_entry { "password_encryption_for_instance_${name}":
198+
key => 'password_encryption',
196199
value => $password_encryption,
197200
}
198201
}
199202

200-
postgresql::server::config_entry { 'data_directory':
203+
postgresql::server::config_entry { "data_directory_for_instance_${name}":
204+
key => 'data_directory',
201205
value => $datadir,
202206
}
203207
if $timezone {
204-
postgresql::server::config_entry { 'timezone':
208+
postgresql::server::config_entry { "timezone_for_instance_${name}":
209+
key => 'timezone',
205210
value => $timezone,
206211
}
207212
}
208213
if $logdir {
209-
postgresql::server::config_entry { 'log_directory':
214+
postgresql::server::config_entry { "log_directory for instance ${name}":
210215
value => $logdir,
211216
}
212217
}
213218
# Allow timestamps in log by default
214219
if $log_line_prefix {
215-
postgresql::server::config_entry { 'log_line_prefix':
220+
postgresql::server::config_entry { "log_line_prefix_for_instance_${name}":
221+
key => 'log_line_prefix',
216222
value => $log_line_prefix,
217223
}
218224
}

spec/classes/server/config_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

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

@@ -60,7 +60,7 @@ class { 'postgresql::server': }
6060

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

@@ -105,7 +105,7 @@ class { 'postgresql::server': }
105105

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

@@ -150,7 +150,7 @@ class { 'postgresql::server': }
150150

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

spec/classes/server_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class { 'postgresql::globals':
114114
it { is_expected.to contain_class('postgresql::server') }
115115

116116
it {
117-
expect(subject).not_to contain_Postgresql_conf('data_directory').that_notifies('Class[postgresql::server::service]')
117+
expect(subject).not_to contain_Postgresql_conf('data_directory_for_instance_main').that_notifies('Class[postgresql::server::service]')
118118
}
119119

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

131131
it {
132-
expect(subject).to contain_Postgresql_conf('data_directory').that_notifies('Class[postgresql::server::service]')
132+
expect(subject).to contain_Postgresql_conf('data_directory_for_instance_main').that_notifies('Class[postgresql::server::service]')
133133
}
134134

135+
it { is_expected.to contain_postgresql__server__config_entry('data_directory_for_instance_main') }
136+
135137
it 'validates connection' do
136138
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running')
137139
end

0 commit comments

Comments
 (0)