Skip to content

Commit 2b15ddf

Browse files
service name should be unique to allow instances
1 parent 9430519 commit 2b15ddf

File tree

10 files changed

+37
-27
lines changed

10 files changed

+37
-27
lines changed

lib/puppet/type/postgresql_psql.rb

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
Puppet::Type.newtype(:postgresql_psql) do
3+
Puppet::Type.newtype(:postgresql_psql) do # rubocop:disable Metrics/BlockLength
44
newparam(:name) do
55
desc 'An arbitrary tag for your own reference; the name of the message.'
66
isnamevar
@@ -122,15 +122,25 @@ def matches(value)
122122
newvalues(:true, :false)
123123
end
124124

125+
newparam(:instance) do
126+
desc 'The postgresql instance under which the psql command should be executed.'
127+
defaultto('main')
128+
end
129+
125130
newparam(:sensitive, boolean: true) do
126131
desc "If 'true', then the executed command will not be echoed into the log. Use this to protect sensitive information passing through."
127132

128133
defaultto(:false)
129134
newvalues(:true, :false)
130135
end
131136

132-
autorequire(:anchor) { ['postgresql::server::service::begin'] }
133-
autorequire(:service) { ['postgresqld'] }
137+
autorequire(:anchor) do
138+
["postgresql::server::service::begin::#{self[:instance]}"]
139+
end
140+
141+
autorequire(:service) do
142+
["postgresqld_instance_#{self[:instance]}"]
143+
end
134144

135145
def should_run_sql(refreshing = false)
136146
onlyif_param = @parameters[:onlyif]
@@ -148,7 +158,7 @@ def refresh
148158

149159
private
150160

151-
def set_sensitive_parameters(sensitive_parameters) # rubocop:disable Style/AccessorMethodName
161+
def set_sensitive_parameters(sensitive_parameters) # rubocop:disable Naming/AccessorMethodName
152162
# Respect sensitive commands
153163
if sensitive_parameters.include?(:unless)
154164
sensitive_parameters.delete(:unless)

manifests/server/instance/service.pp

+4-4
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/service_spec.rb

+1-1
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

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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,7 +61,7 @@ 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
@@ -85,7 +85,7 @@ 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
@@ -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

@@ -150,23 +150,23 @@ class { 'postgresql::globals':
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

spec/defines/server/database_spec.rb

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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)