Skip to content

Commit 767da95

Browse files
authored
Merge pull request #851 from teluq-pbrideau/fix/database-install
use provided database port in pgpass
2 parents 0c4bd78 + 8d4eda5 commit 767da95

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

manifests/database/postgresql.pp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
$database_user = '',
1919
$database_password = '',
2020
$database_host = '',
21-
Optional[Stdlib::Port::Unprivileged] $database_port = undef,
21+
Stdlib::Port::Unprivileged $database_port = 5432,
2222
$database_path = $zabbix::params::database_path,
2323
) inherits zabbix::params {
2424
assert_private()
@@ -45,33 +45,27 @@
4545
$schema_path = $database_schema_path
4646
}
4747

48-
if $database_port != undef {
49-
$port = "-p ${database_port} "
50-
} else {
51-
$port = ''
52-
}
53-
5448
case $zabbix_type {
5549
'proxy': {
5650
$zabbix_proxy_create_sql = versioncmp($zabbix_version, '6.0') >= 0 ? {
57-
true => "cd ${schema_path} && psql -h '${database_host}' -U '${database_user}' ${port}-d '${database_name}' -f proxy.sql && touch /etc/zabbix/.schema.done",
58-
false => "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' ${port}-d '${database_name}' -f schema.sql && touch /etc/zabbix/.schema.done"
51+
true => "cd ${schema_path} && psql -h '${database_host}' -U '${database_user}' -p ${database_port} -d '${database_name}' -f proxy.sql && touch /etc/zabbix/.schema.done",
52+
false => "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' -p ${database_port} -d '${database_name}' -f schema.sql && touch /etc/zabbix/.schema.done"
5953
}
6054
}
6155
default: {
6256
$zabbix_server_create_sql = versioncmp($zabbix_version, '6.0') >= 0 ? {
63-
true => "cd ${schema_path} && if [ -f server.sql.gz ]; then gunzip -f server.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' ${port}-d '${database_name}' -f server.sql && touch /etc/zabbix/.schema.done",
64-
false => "cd ${schema_path} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' ${port}-d '${database_name}' -f create.sql && touch /etc/zabbix/.schema.done"
57+
true => "cd ${schema_path} && if [ -f server.sql.gz ]; then gunzip -f server.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' -p ${database_port} -d '${database_name}' -f server.sql && touch /etc/zabbix/.schema.done",
58+
false => "cd ${schema_path} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' -p ${database_port} -d '${database_name}' -f create.sql && touch /etc/zabbix/.schema.done"
6559
}
6660
$zabbix_server_images_sql = 'touch /etc/zabbix/.images.done'
6761
$zabbix_server_data_sql = 'touch /etc/zabbix/.data.done'
6862
}
6963
}
7064

7165
exec { 'update_pgpass':
72-
command => "echo ${database_host}:5432:${database_name}:${database_user}:${database_password} >> /root/.pgpass",
66+
command => "echo ${database_host}:${database_port}:${database_name}:${database_user}:${database_password} >> /root/.pgpass",
7367
path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}",
74-
unless => "grep \"${database_host}:5432:${database_name}:${database_user}:${database_password}\" /root/.pgpass",
68+
unless => "grep \"${database_host}:${database_port}:${database_name}:${database_user}:${database_password}\" /root/.pgpass",
7569
require => File['/root/.pgpass'],
7670
}
7771

spec/classes/database_postgresql_spec.rb

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,29 @@
8484

8585
it { is_expected.to compile.with_all_deps }
8686
it { is_expected.to contain_exec('update_pgpass').with_command('echo node01.example.com:5432:zabbix-server:zabbix-server:zabbix-server >> /root/.pgpass') }
87-
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path} && if [ -f #{sql_server}.gz ]; then gunzip -f #{sql_server}.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -d 'zabbix-server' -f #{sql_server} && touch /etc/zabbix/.schema.done") }
87+
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path} && if [ -f #{sql_server}.gz ]; then gunzip -f #{sql_server}.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -p 5432 -d 'zabbix-server' -f #{sql_server} && touch /etc/zabbix/.schema.done") }
88+
it { is_expected.to contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
89+
it { is_expected.to contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
90+
it { is_expected.to contain_file('/root/.pgpass') }
91+
it { is_expected.to contain_class('zabbix::params') }
92+
end
93+
94+
describe "when zabbix_type is server and version is #{zabbix_version} and custom port is defined" do
95+
let :params do
96+
{
97+
database_name: 'zabbix-server',
98+
database_user: 'zabbix-server',
99+
database_password: 'zabbix-server',
100+
database_host: 'node01.example.com',
101+
database_port: 6432,
102+
zabbix_type: 'server',
103+
zabbix_version: zabbix_version
104+
}
105+
end
106+
107+
it { is_expected.to compile.with_all_deps }
108+
it { is_expected.to contain_exec('update_pgpass').with_command('echo node01.example.com:6432:zabbix-server:zabbix-server:zabbix-server >> /root/.pgpass') }
109+
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path} && if [ -f #{sql_server}.gz ]; then gunzip -f #{sql_server}.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -p 6432 -d 'zabbix-server' -f #{sql_server} && touch /etc/zabbix/.schema.done") }
88110
it { is_expected.to contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
89111
it { is_expected.to contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
90112
it { is_expected.to contain_file('/root/.pgpass') }
@@ -131,9 +153,9 @@
131153
it { is_expected.to contain_exec('update_pgpass').with_command('echo node01.example.com:5432:zabbix-proxy:zabbix-proxy:zabbix-proxy >> /root/.pgpass') }
132154

133155
if Puppet::Util::Package.versioncmp(zabbix_version, '6.0') < 0
134-
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-proxy' -d 'zabbix-proxy' -f schema.sql && touch /etc/zabbix/.schema.done") }
156+
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-proxy' -p 5432 -d 'zabbix-proxy' -f schema.sql && touch /etc/zabbix/.schema.done") }
135157
else
136-
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && psql -h 'node01.example.com' -U 'zabbix-proxy' -d 'zabbix-proxy' -f proxy.sql && touch /etc/zabbix/.schema.done") }
158+
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && psql -h 'node01.example.com' -U 'zabbix-proxy' -p 5432 -d 'zabbix-proxy' -f proxy.sql && touch /etc/zabbix/.schema.done") }
137159
end
138160

139161
it { is_expected.to contain_class('zabbix::params') }

0 commit comments

Comments
 (0)