Skip to content

Commit 6601779

Browse files
make resources unique to allow multiple instances
1 parent 9132800 commit 6601779

File tree

13 files changed

+47
-40
lines changed

13 files changed

+47
-40
lines changed

manifests/server/instance/initdb.pp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175

176176
# This runs the initdb command, we use the existance of the PG_VERSION
177177
# file to ensure we don't keep running this command.
178-
exec { 'postgresql_initdb':
178+
exec { "postgresql_initdb_instance_${name}":
179179
command => $initdb_command,
180180
creates => "${datadir}/PG_VERSION",
181181
user => $user,
@@ -185,6 +185,13 @@
185185
cwd => $module_workdir,
186186
}
187187
} elsif $encoding != undef {
188-
include postgresql::server::late_initdb
188+
postgresql::server::instance::late_initdb { $name:
189+
encoding => $encoding,
190+
user => $user,
191+
group => $group,
192+
psql_path => $psql_path,
193+
port => $port,
194+
module_workdir => $module_workdir,
195+
}
189196
}
190197
}

manifests/server/instance/passwd.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# the default for pg_hba.conf.
4343
$escaped = postgresql::postgresql_escape($real_postgres_password)
4444
$exec_command = "${stdlib::shell_escape($psql_path)}${_dboption} -c \"ALTER ROLE \\\"${stdlib::shell_escape($user)}\\\" PASSWORD \${NEWPASSWD_ESCAPED}\"" # lint:ignore:140chars
45-
exec { 'set_postgres_postgrespw':
45+
exec { "set_postgres_postgrespw_${name}":
4646
# This command works w/no password because we run it as postgres system
4747
# user
4848
command => $exec_command,

manifests/server/instance/reload.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
String[1] $service_status = $postgresql::server::service_status,
77
String[1] $service_reload = $postgresql::server::service_reload,
88
) {
9-
exec { 'postgresql_reload':
9+
exec { "postgresql_reload_${name}":
1010
path => '/usr/bin:/usr/sbin:/bin:/sbin',
1111
command => $service_reload,
1212
onlyif => $service_status,

manifests/server/instance/service.pp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
anchor { "postgresql::server::service::begin::${name}": }
3434

3535
if $service_manage {
36-
service { 'postgresqld':
36+
service { "postgresqld_instance_${name}":
3737
ensure => $service_ensure,
3838
enable => $service_enable,
3939
name => $service_name,
@@ -48,18 +48,18 @@
4848
#
4949
# Without it, we may continue doing more work before the database is
5050
# prepared leading to a nasty race condition.
51-
postgresql_conn_validator { 'validate_service_is_running':
51+
postgresql_conn_validator { "validate_service_is_running_instance_${name}":
5252
run_as => $user,
5353
db_name => $default_database,
5454
port => $port,
5555
connect_settings => $connect_settings,
5656
sleep => 1,
5757
tries => 60,
5858
psql_path => $psql_path,
59-
require => Service['postgresqld'],
59+
require => Service["postgresqld_instance_${name}"],
6060
before => Anchor["postgresql::server::service::end::${name}"],
6161
}
62-
Postgresql::Server::Database <| title == $default_database |> -> Postgresql_conn_validator['validate_service_is_running']
62+
Postgresql::Server::Database <| title == $default_database |> -> Postgresql_conn_validator["validate_service_is_running_instance_${name}"]
6363
}
6464
}
6565

spec/classes/server/initdb_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class { 'postgresql::server': }
6565
end
6666

6767
it 'contains exec with specified working directory' do
68-
expect(subject).to contain_exec('postgresql_initdb').with(
68+
expect(subject).to contain_exec('postgresql_initdb_instance_main').with(
6969
cwd: '/var/tmp',
7070
)
7171
end
@@ -82,7 +82,7 @@ class { 'postgresql::server': }
8282
end
8383

8484
it 'contains exec with default working directory' do
85-
expect(subject).to contain_exec('postgresql_initdb').with(
85+
expect(subject).to contain_exec('postgresql_initdb_instance_main').with(
8686
cwd: '/tmp',
8787
)
8888
end

spec/classes/server/service_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
end
1111

1212
it { is_expected.to contain_class('postgresql::server::service') }
13-
it { is_expected.to contain_service('postgresqld').with_name('postgresql').with_status('systemctl status postgresql') }
13+
it { is_expected.to contain_service('postgresqld_instance_main').with_name('postgresql').with_status('systemctl status postgresql') }
1414
end

spec/classes/server_spec.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
it { is_expected.to contain_file('/var/lib/postgresql/13/main') }
1212

1313
it {
14-
expect(subject).to contain_exec('postgresql_reload').with('command' => 'systemctl reload postgresql')
14+
expect(subject).to contain_exec('postgresql_reload_main').with('command' => 'systemctl reload postgresql')
1515
}
1616

1717
it 'validates connection' do
18-
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running')
18+
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running_instance_main')
1919
end
2020
end
2121

@@ -61,14 +61,14 @@ class { 'postgresql::globals':
6161
it { is_expected.to contain_class('postgresql::server::passwd') }
6262

6363
it 'validates connection' do
64-
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running')
64+
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running_instance_main')
6565
end
6666

6767
it 'sets postgres password' do
68-
expect(subject).to contain_exec('set_postgres_postgrespw').with('command' => '/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"',
69-
'user' => 'postgres',
70-
'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'],
71-
'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null")
68+
expect(subject).to contain_exec('set_postgres_postgrespw_main').with('command' => '/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"',
69+
'user' => 'postgres',
70+
'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'],
71+
'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null")
7272
end
7373
end
7474

@@ -85,14 +85,14 @@ class { 'postgresql::globals':
8585
it { is_expected.to contain_class('postgresql::server::passwd') }
8686

8787
it 'validates connection' do
88-
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running')
88+
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running_instance_main')
8989
end
9090

9191
it 'sets postgres password' do
92-
expect(subject).to contain_exec('set_postgres_postgrespw').with('command' => ['/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"'],
93-
'user' => 'postgres',
94-
'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'],
95-
'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null")
92+
expect(subject).to contain_exec('set_postgres_postgrespw_main').with('command' => ['/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"'],
93+
'user' => 'postgres',
94+
'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'],
95+
'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null")
9696
end
9797
end
9898

@@ -103,7 +103,7 @@ class { 'postgresql::globals':
103103
it { is_expected.to contain_class('postgresql::server') }
104104

105105
it 'shouldnt validate connection' do
106-
expect(subject).not_to contain_postgresql_conn_validator('validate_service_is_running')
106+
expect(subject).not_to contain_postgresql_conn_validator('validate_service_is_running_instance_main')
107107
end
108108
end
109109

@@ -118,7 +118,7 @@ class { 'postgresql::globals':
118118
}
119119

120120
it 'validates connection' do
121-
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running')
121+
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running_instance_main')
122122
end
123123
end
124124

@@ -135,7 +135,7 @@ class { 'postgresql::globals':
135135
it { is_expected.to contain_postgresql__server__config_entry('data_directory_for_instance_main') }
136136

137137
it 'validates connection' do
138-
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running')
138+
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running_instance_main')
139139
end
140140
end
141141

@@ -146,27 +146,27 @@ class { 'postgresql::globals':
146146
it { is_expected.to contain_class('postgresql::server') }
147147

148148
it {
149-
expect(subject).to contain_exec('postgresql_reload').with('command' => '/bin/true')
149+
expect(subject).to contain_exec('postgresql_reload_main').with('command' => '/bin/true')
150150
}
151151

152152
it 'validates connection' do
153-
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running')
153+
expect(subject).to contain_postgresql_conn_validator('validate_service_is_running_instance_main')
154154
end
155155
end
156156

157157
describe 'service_manage => true' do
158158
let(:params) { { service_manage: true } }
159159

160-
it { is_expected.to contain_service('postgresqld') }
160+
it { is_expected.to contain_service('postgresqld_instance_main') }
161161
end
162162

163163
describe 'service_manage => false' do
164164
let(:params) { { service_manage: false } }
165165

166-
it { is_expected.not_to contain_service('postgresqld') }
166+
it { is_expected.not_to contain_service('postgresqld_instance_main') }
167167

168168
it 'shouldnt validate connection' do
169-
expect(subject).not_to contain_postgresql_conn_validator('validate_service_is_running')
169+
expect(subject).not_to contain_postgresql_conn_validator('validate_service_is_running_instance_main')
170170
end
171171
end
172172

@@ -182,7 +182,7 @@ class { 'postgresql::globals':
182182
end
183183

184184
it 'stills enable the service' do
185-
expect(subject).to contain_service('postgresqld').with(ensure: 'running')
185+
expect(subject).to contain_service('postgresqld_instance_main').with(ensure: 'running')
186186
end
187187
end
188188

@@ -194,7 +194,7 @@ class { 'postgresql::globals':
194194
end
195195

196196
it 'contains proper initdb exec' do
197-
expect(subject).to contain_exec('postgresql_initdb')
197+
expect(subject).to contain_exec('postgresql_initdb_instance_main')
198198
end
199199
end
200200

spec/defines/server/database_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
end
1414

1515
it { is_expected.to contain_postgresql__server__database('test') }
16-
it { is_expected.to contain_postgresql_psql('CREATE DATABASE "test"').that_requires('Service[postgresqld]') }
16+
it { is_expected.to contain_postgresql_psql('CREATE DATABASE "test"').that_requires('Service[postgresqld_instance_main]') }
1717

1818
context "with comment set to 'test comment'" do
1919
let(:params) { { comment: 'test comment' } }

spec/defines/server/default_privileges_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class {'postgresql::server':}
337337

338338
it do
339339
expect(subject).to contain_postgresql_psql('default_privileges:test') \
340-
.that_requires(['Service[postgresqld]', 'Postgresql::Server::Role[test]'])
340+
.that_requires(['Service[postgresqld_instance_main]', 'Postgresql::Server::Role[test]'])
341341
end
342342
end
343343

spec/defines/server/grant_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class {'postgresql::server':}
207207

208208
it do
209209
expect(subject).to contain_postgresql_psql('grant:test') \
210-
.that_requires(['Service[postgresqld]', 'Postgresql::Server::Role[test]'])
210+
.that_requires(['Service[postgresqld_instance_main]', 'Postgresql::Server::Role[test]'])
211211
end
212212
end
213213

spec/defines/server/reassign_owned_by_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ class {'postgresql::server':}
3131
expect(subject).to contain_postgresql_psql('reassign_owned_by:test:REASSIGN OWNED BY "test_old_role" TO "test_new_role"')
3232
.with_command('REASSIGN OWNED BY "test_old_role" TO "test_new_role"')
3333
.with_onlyif(%r{SELECT tablename FROM pg_catalog.pg_tables WHERE\s*schemaname NOT IN \('pg_catalog', 'information_schema'\) AND\s*tableowner = 'test_old_role'.*}m)
34-
.that_requires('Service[postgresqld]')
34+
.that_requires('Service[postgresqld_instance_main]')
3535
}
3636
end

spec/defines/server/role_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
'PGUSER' => 'login-user',
106106
'PGPASSWORD' => 'login-pass'
107107
},
108-
).that_requires('Service[postgresqld]')
108+
).that_requires('Service[postgresqld_instance_main]')
109109
end
110110

111111
it 'has alter role for "test" user with password as ****' do
@@ -364,7 +364,7 @@ class { 'postgresql::server':
364364
end
365365

366366
it 'has drop role for "test" user if ensure absent' do
367-
expect(subject).to contain_postgresql_psql('DROP ROLE "test"').that_requires('Service[postgresqld]')
367+
expect(subject).to contain_postgresql_psql('DROP ROLE "test"').that_requires('Service[postgresqld_instance_main]')
368368
end
369369
end
370370

spec/defines/server/tablespace_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
it { is_expected.to contain_file('/srv/data/foo').with_ensure('directory') }
2323
it { is_expected.to contain_postgresql__server__tablespace('test') }
24-
it { is_expected.to contain_postgresql_psql('CREATE TABLESPACE "test"').that_requires('Service[postgresqld]') }
24+
it { is_expected.to contain_postgresql_psql('CREATE TABLESPACE "test"').that_requires('Service[postgresqld_instance_main]') }
2525

2626
context 'with different owner' do
2727
let :params do

0 commit comments

Comments
 (0)