Skip to content

Commit 995e198

Browse files
committed
Add param for specifying validate connection script.
* Add param `validcon_path` in `postgresql::client` (defaults to previous hard coded value). * Add tests for this new parameter. All tests runs successfully on Scientific Linux 6.4 ``` $ bundle exec rake spec SPEC_OPTS='--format documentation' [...] Finished in 2 minutes 10.5 seconds (files took 1.4 seconds to load) 201 examples, 0 failures ```
1 parent a189ed7 commit 995e198

File tree

7 files changed

+54
-3
lines changed

7 files changed

+54
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ This value defaults to `true`. Whether or not manage the pg_ident.conf. If set t
394394

395395
This class installs postgresql client software. Alter the following parameters if you have a custom version you would like to install (Note: don't forget to make sure to add any necessary yum or apt repositories if specifying a custom version):
396396

397+
####`validcon_script_path`
398+
Path to validate connection script. Defaults to `/usr/local/bin/validate_postgresql_connection.sh`.
399+
397400
####`package_name`
398401
The name of the postgresql client package.
399402

manifests/client.pp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Install client cli tool. See README.md for more details.
22
class postgresql::client (
33
$file_ensure = 'file',
4+
$validcon_script_path = $postgresql::params::validcon_script_path,
45
$package_name = $postgresql::params::client_package_name,
56
$package_ensure = 'present'
67
) inherits postgresql::params {
8+
validate_absolute_path($validcon_script_path)
79
validate_string($package_name)
810

911
package { 'postgresql-client':
@@ -12,7 +14,7 @@
1214
tag => 'postgresql',
1315
}
1416

15-
file { '/usr/local/bin/validate_postgresql_connection.sh':
17+
file { $validcon_script_path:
1618
ensure => $file_ensure,
1719
source => 'puppet:///modules/postgresql/validate_postgresql_connection.sh',
1820
owner => 0,

manifests/globals.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
$service_status = undef,
1717
$default_database = undef,
1818

19+
$validcon_script_path = undef,
20+
1921
$initdb_path = undef,
2022
$createdb_path = undef,
2123
$psql_path = undef,

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
}
245245
}
246246

247+
$validcon_script_path = pick($validcon_script_path, '/usr/local/bin/validate_postgresql_connection.sh')
247248
$initdb_path = pick($initdb_path, "${bindir}/initdb")
248249
$createdb_path = pick($createdb_path, "${bindir}/createdb")
249250
$pg_hba_conf_path = pick($pg_hba_conf_path, "${confdir}/pg_hba.conf")

manifests/validate_db_connection.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
include postgresql::params
1919

2020
$psql_path = $postgresql::params::psql_path
21+
$validcon_script_path = $postgresql::client::validcon_script_path
2122

2223
$cmd_init = "${psql_path} --tuples-only --quiet "
2324
$cmd_host = $database_host ? {
@@ -41,7 +42,7 @@
4142
default => "PGPASSWORD=${database_password}",
4243
}
4344
$cmd = join([$cmd_init, $cmd_host, $cmd_user, $cmd_port, $cmd_dbname], ' ')
44-
$validate_cmd = "/usr/local/bin/validate_postgresql_connection.sh ${sleep} ${tries} '${cmd}'"
45+
$validate_cmd = "${validcon_script_path} ${sleep} ${tries} '${cmd}'"
4546

4647
# This is more of a safety valve, we add a little extra to compensate for the
4748
# time it takes to run each psql command.

spec/unit/classes/client_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
describe 'with parameters' do
1313
let :params do
1414
{
15+
:validcon_script_path => '/opt/bin/my-validate-con.sh',
1516
:package_ensure => 'absent',
16-
:package_name => 'mypackage',
17+
:package_name => 'mypackage',
18+
:file_ensure => 'file'
1719
}
1820
end
1921

@@ -24,6 +26,15 @@
2426
:tag => 'postgresql',
2527
})
2628
end
29+
30+
it 'should have specified validate connexion' do
31+
should contain_file('/opt/bin/my-validate-con.sh').with({
32+
:ensure => 'file',
33+
:owner => 0,
34+
:group => 0,
35+
:mode => '0755'
36+
})
37+
end
2738
end
2839

2940
describe 'with no parameters' do

spec/unit/defines/validate_db_connection_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,36 @@
3131
}
3232
end
3333
it { is_expected.to contain_postgresql__validate_db_connection('test') }
34+
35+
it 'should have proper path for validate command' do
36+
is_expected.to contain_exec('validate postgres connection for test@test:5432/test').with({
37+
:unless => %r'^/usr/local/bin/validate_postgresql_connection.sh\s+\d+'
38+
})
39+
end
3440
end
41+
42+
describe 'should work while specifying validate_connection in postgresql::client' do
43+
44+
let :params do
45+
{
46+
:database_host => 'test',
47+
:database_name => 'test',
48+
:database_password => 'test',
49+
:database_username => 'test',
50+
:database_port => 5432
51+
}
52+
end
53+
54+
let :pre_condition do
55+
"class { 'postgresql::client': validcon_script_path => '/opt/something/validate.sh' }"
56+
end
57+
58+
it 'should have proper path for validate command' do
59+
is_expected.to contain_exec('validate postgres connection for test@test:5432/test').with({
60+
:unless => %r'^/opt/something/validate.sh\s+\d+'
61+
})
62+
end
63+
64+
end
65+
3566
end

0 commit comments

Comments
 (0)