-
-
Notifications
You must be signed in to change notification settings - Fork 230
/
database_postgresql_spec.rb
144 lines (126 loc) · 6.89 KB
/
database_postgresql_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# frozen_string_literal: true
require 'spec_helper'
describe 'zabbix::database::postgresql' do
let :node do
'rspec.puppet.com'
end
let :pre_condition do
'include postgresql::server'
end
on_supported_os(baseline_os_hash).each do |os, facts|
next if facts[:os]['name'] == 'windows'
context "on #{os}" do
let :facts do
facts
end
supported_versions.each do |zabbix_version|
path = case facts[:os]['name']
when 'CentOS', 'RedHat', 'OracleLinux', 'VirtuozzoLinux'
# Path on RedHat
if Puppet::Util::Package.versioncmp(zabbix_version, '6.0') >= 0
'/usr/share/zabbix-sql-scripts/postgresql/'
elsif Puppet::Util::Package.versioncmp(zabbix_version, '5.4') >= 0
'/usr/share/doc/zabbix-sql-scripts/postgresql/'
else
"/usr/share/doc/zabbix-*-pgsql-#{zabbix_version}*/"
end
else
# Path on Debian
if Puppet::Util::Package.versioncmp(zabbix_version, '6.0') >= 0
'/usr/share/zabbix-sql-scripts/postgresql/'
elsif Puppet::Util::Package.versioncmp(zabbix_version, '5.4') >= 0
'/usr/share/doc/zabbix-sql-scripts/postgresql/'
else
'/usr/share/doc/zabbix-*-pgsql'
end
end
sql_server = case zabbix_version
when '6.0'
'server.sql'
else
'create.sql'
end
describe "when zabbix_type is server and version is #{zabbix_version}" do
let :params do
{
database_name: 'zabbix-server',
database_user: 'zabbix-server',
database_password: 'zabbix-server',
database_host: 'node01.example.com',
database_port: 5432,
zabbix_type: 'server',
zabbix_version: zabbix_version
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('update_pgpass').with_command('echo node01.example.com:5432:zabbix-server:zabbix-server:zabbix-server >> /root/.pgpass') }
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") }
it { is_expected.to contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
it { is_expected.to contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
it { is_expected.to contain_file('/root/.pgpass') }
it { is_expected.to contain_class('zabbix::params') }
end
describe "when zabbix_type is server and version is #{zabbix_version} and no port is defined" do
let :params do
{
database_name: 'zabbix-server',
database_user: 'zabbix-server',
database_password: 'zabbix-server',
database_host: 'node01.example.com',
zabbix_type: 'server',
zabbix_version: zabbix_version
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('update_pgpass').with_command('echo node01.example.com:5432:zabbix-server:zabbix-server:zabbix-server >> /root/.pgpass') }
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") }
it { is_expected.to contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
it { is_expected.to contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
it { is_expected.to contain_file('/root/.pgpass') }
it { is_expected.to contain_class('zabbix::params') }
end
describe "when zabbix_type is proxy and version is #{zabbix_version}" do
let :params do
{
database_name: 'zabbix-proxy',
database_user: 'zabbix-proxy',
database_password: 'zabbix-proxy',
database_host: 'node01.example.com',
database_port: 5432,
zabbix_type: 'proxy',
zabbix_version: zabbix_version
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('update_pgpass').with_command('echo node01.example.com:5432:zabbix-proxy:zabbix-proxy:zabbix-proxy >> /root/.pgpass') }
if Puppet::Util::Package.versioncmp(zabbix_version, '6.0') < 0
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") }
else
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") }
end
it { is_expected.to contain_class('zabbix::params') }
end
describe "when zabbix_type is proxy and version is #{zabbix_version} and no port is defined" do
let :params do
{
database_name: 'zabbix-proxy',
database_user: 'zabbix-proxy',
database_password: 'zabbix-proxy',
database_host: 'node01.example.com',
zabbix_type: 'proxy',
zabbix_version: zabbix_version
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('update_pgpass').with_command('echo node01.example.com:5432:zabbix-proxy:zabbix-proxy:zabbix-proxy >> /root/.pgpass') }
if Puppet::Util::Package.versioncmp(zabbix_version, '6.0') < 0
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") }
else
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") }
end
it { is_expected.to contain_class('zabbix::params') }
end
end
end
end
end