Skip to content

Commit faa2cba

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

File tree

5 files changed

+47
-36
lines changed

5 files changed

+47
-36
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

spec/unit/provider/postgresql_conf/parsed_spec.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121

2222
describe 'simple configuration that should be allowed' do
2323
it 'parses a simple ini line' do
24-
expect(provider.parse_line("listen_addreses = '*'")).to eq(
25-
name: 'listen_addreses', value: '*', comment: nil, record_type: :parsed,
24+
expect(provider.parse_line("listen_addresses = '*'")).to eq(
25+
key: 'listen_addresses', value: '*', comment: nil, record_type: :parsed,
2626
)
2727
end
2828

2929
it 'parses a simple ini line (2)' do
30-
expect(provider.parse_line(" listen_addreses = '*'")).to eq(
31-
name: 'listen_addreses', value: '*', comment: nil, record_type: :parsed,
30+
expect(provider.parse_line(" listen_addresses = '*'")).to eq(
31+
key: 'listen_addresses', value: '*', comment: nil, record_type: :parsed,
3232
)
3333
end
3434

3535
it 'parses a simple ini line (3)' do
36-
expect(provider.parse_line("listen_addreses = '*' # dont mind me")).to eq(
37-
name: 'listen_addreses', value: '*', comment: 'dont mind me', record_type: :parsed,
36+
expect(provider.parse_line("listen_addresses = '*' # dont mind me")).to eq(
37+
key: 'listen_addresses', value: '*', comment: 'dont mind me', record_type: :parsed,
3838
)
3939
end
4040

@@ -52,13 +52,13 @@
5252

5353
it 'allows includes' do
5454
expect(provider.parse_line('include puppetextra')).to eq(
55-
name: 'include', value: 'puppetextra', comment: nil, record_type: :parsed,
55+
key: 'include', value: 'puppetextra', comment: nil, record_type: :parsed,
5656
)
5757
end
5858

5959
it 'allows numbers through without quotes' do
6060
expect(provider.parse_line('wal_keep_segments = 32')).to eq(
61-
name: 'wal_keep_segments', value: '32', comment: nil, record_type: :parsed,
61+
key: 'wal_keep_segments', value: '32', comment: nil, record_type: :parsed,
6262
)
6363
end
6464

@@ -70,7 +70,7 @@
7070

7171
it 'parses keys with dots' do
7272
expect(provider.parse_line('auto_explain.log_min_duration = 1ms')).to eq(
73-
name: 'auto_explain.log_min_duration', value: '1ms', comment: nil, record_type: :parsed,
73+
key: 'auto_explain.log_min_duration', value: '1ms', comment: nil, record_type: :parsed,
7474
)
7575
end
7676
end
@@ -89,61 +89,61 @@
8989
end
9090

9191
it 'sets simple configuration' do
92-
expect(provider.to_line(name: 'listen_addresses', value: '*', comment: nil, record_type: :parsed)).to eq(
92+
expect(provider.to_line(key: 'listen_addresses', value: '*', comment: nil, record_type: :parsed)).to eq(
9393
"listen_addresses = '*'",
9494
)
9595
end
9696

9797
it 'sets simple configuration with period in name' do
98-
expect(provider.to_line(name: 'auto_explain.log_min_duration', value: '100ms', comment: nil, record_type: :parsed)).to eq(
98+
expect(provider.to_line(key: 'auto_explain.log_min_duration', value: '100ms', comment: nil, record_type: :parsed)).to eq(
9999
'auto_explain.log_min_duration = 100ms',
100100
)
101101
end
102102

103103
it 'sets simple configuration even with comments' do
104-
expect(provider.to_line(name: 'listen_addresses', value: '*', comment: 'dont mind me', record_type: :parsed)).to eq(
104+
expect(provider.to_line(key: 'listen_addresses', value: '*', comment: 'dont mind me', record_type: :parsed)).to eq(
105105
"listen_addresses = '*' # dont mind me",
106106
)
107107
end
108108

109109
it 'quotes includes' do
110-
expect(provider.to_line(name: 'include', value: 'puppetextra', comment: nil, record_type: :parsed)).to eq(
110+
expect(provider.to_line(key: 'include', value: 'puppetextra', comment: nil, record_type: :parsed)).to eq(
111111
"include 'puppetextra'",
112112
)
113113
end
114114

115115
it 'quotes multiple words' do
116-
expect(provider.to_line(name: 'archive_command', value: 'rsync up', comment: nil, record_type: :parsed)).to eq(
116+
expect(provider.to_line(key: 'archive_command', value: 'rsync up', comment: nil, record_type: :parsed)).to eq(
117117
"archive_command = 'rsync up'",
118118
)
119119
end
120120

121121
it 'does not quote numbers' do
122-
expect(provider.to_line(name: 'wal_segments', value: '32', comment: nil, record_type: :parsed)).to eq(
122+
expect(provider.to_line(key: 'wal_segments', value: '32', comment: nil, record_type: :parsed)).to eq(
123123
'wal_segments = 32',
124124
)
125125
end
126126

127127
it 'allows numbers' do
128-
expect(provider.to_line(name: 'integer', value: 42, comment: nil, record_type: :parsed)).to eq(
128+
expect(provider.to_line(key: 'integer', value: 42, comment: nil, record_type: :parsed)).to eq(
129129
'integer = 42',
130130
)
131131
end
132132

133133
it 'allows floats' do
134-
expect(provider.to_line(name: 'float', value: 2.71828182845, comment: nil, record_type: :parsed)).to eq(
134+
expect(provider.to_line(key: 'float', value: 2.71828182845, comment: nil, record_type: :parsed)).to eq(
135135
'float = 2.71828182845',
136136
)
137137
end
138138

139139
it 'quotes single string address' do
140-
expect(provider.to_line(name: 'listen_addresses', value: '0.0.0.0', comment: nil, record_type: :parsed)).to eq(
140+
expect(provider.to_line(key: 'listen_addresses', value: '0.0.0.0', comment: nil, record_type: :parsed)).to eq(
141141
"listen_addresses = '0.0.0.0'",
142142
)
143143
end
144144

145145
it 'quotes an array of addresses' do
146-
expect(provider.to_line(name: 'listen_addresses', value: ['0.0.0.0', '127.0.0.1'], comment: nil, record_type: :parsed)).to eq(
146+
expect(provider.to_line(key: 'listen_addresses', value: ['0.0.0.0', '127.0.0.1'], comment: nil, record_type: :parsed)).to eq(
147147
"listen_addresses = '0.0.0.0, 127.0.0.1'",
148148
)
149149
end

0 commit comments

Comments
 (0)