spec: Add all versions of server/proxy for databases
MODIFY
spec/classes/database_mysql_spec.rb
spec/classes/database_mysql_spec.rb
@@ -67,7 +67,9 @@ describe 'zabbix::database::mysql' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path2} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
end
- context 'when zabbix_type is server and zabbix version is 3.0' do
+
+ %w[3.0 3.2 3.4 4.0 4.2 4.4 5.0 5.2].each do |zabbix_version|
+ context "when zabbix_type is server and zabbix version is #{zabbix_version}" do
let :params do
{
database_name: 'zabbix-server',
@@ -75,7 +77,7 @@ describe 'zabbix::database::mysql' do
database_password: 'zabbix-server',
database_host: 'rspec.puppet.com',
zabbix_type: 'server',
- zabbix_version: '3.0'
+ zabbix_version: zabbix_version
}
end
@@ -84,9 +86,8 @@ describe 'zabbix::database::mysql' do
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path3} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < create.sql && 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') }
- end
- describe 'when zabbix_type is proxy and zabbix version is 3.0' do
+ describe "when zabbix_type is proxy and zabbix version is #{zabbix_version}" do
let :params do
{
database_name: 'zabbix-proxy',
@@ -94,7 +95,7 @@ describe 'zabbix::database::mysql' do
database_password: 'zabbix-proxy',
database_host: 'rspec.puppet.com',
zabbix_type: 'proxy',
- zabbix_version: '3.0'
+ zabbix_version: zabbix_version
}
end
@@ -102,40 +103,7 @@ describe 'zabbix::database::mysql' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path3} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
end
- context 'when zabbix_type is server and zabbix version is 3.2' do
- let :params do
- {
- database_name: 'zabbix-server',
- database_user: 'zabbix-server',
- database_password: 'zabbix-server',
- database_host: 'rspec.puppet.com',
- zabbix_type: 'server',
- zabbix_version: '3.2'
- }
end
-
- it { is_expected.to contain_class('zabbix::database::mysql') }
- it { is_expected.to compile.with_all_deps }
- it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path3} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < create.sql && 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') }
- end
-
- describe 'when zabbix_type is proxy and zabbix version is 3.2' do
- let :params do
- {
- database_name: 'zabbix-proxy',
- database_user: 'zabbix-proxy',
- database_password: 'zabbix-proxy',
- database_host: 'rspec.puppet.com',
- zabbix_type: 'proxy',
- zabbix_version: '3.2'
- }
- end
-
- it { is_expected.to contain_class('zabbix::database::mysql') }
- it { is_expected.to compile.with_all_deps }
- it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path3} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
end
end
end

MODIFY
spec/classes/database_postgresql_spec.rb
spec/classes/database_postgresql_spec.rb
@@ -17,8 +17,26 @@ describe 'zabbix::database::postgresql' do
end
case facts[:os]['name']
- when 'CentOS', 'RedHat'
- describe 'when zabbix_type is server' do
+ when 'CentOS', 'RedHat', 'OracleLinux', 'VirtuozzoLinux'
+ # Path for version 2.4 on RedHat
+ path_for2 = "/usr/share/doc/zabbix-*-pgsql-2.4*/create"
+ else
+ # Path for version 2.4 on Debian
+ path_for2 = "/usr/share/zabbix-*-pgsql"
+ end
+
+ %w[2.4 3.2 3.4 4.0 4.2 4.4 5.0 5.2].each do |zabbix_version|
+
+ case facts[:os]['name']
+ when 'CentOS', 'RedHat', 'OracleLinux', 'VirtuozzoLinux'
+ # Path for versions >= 3.x on RedHat
+ path_for3_and_up = "/usr/share/doc/zabbix-*-pgsql-#{zabbix_version}*/"
+ else
+ # Path for versions >= 3.x on Debian
+ path_for3_and_up = "/usr/share/doc/zabbix-*-pgsql"
+ end
+
+ describe "when zabbix_type is server and version is #{zabbix_version}" do
let :params do
{
database_name: 'zabbix-server',
@@ -26,20 +44,26 @@ describe 'zabbix::database::postgresql' do
database_password: 'zabbix-server',
database_host: 'node01.example.com',
zabbix_type: 'server',
- zabbix_version: '2.4'
+ 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 /usr/share/doc/zabbix-*-pgsql-2.4*/create && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -d 'zabbix-server' -f schema.sql && touch /etc/zabbix/.schema.done") }
- it { is_expected.to contain_exec('zabbix_server_images.sql').with_command("cd /usr/share/doc/zabbix-*-pgsql-2.4*/create && if [ -f images.sql.gz ]; then gunzip -f images.sql.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -d 'zabbix-server' -f images.sql && touch /etc/zabbix/.images.done") }
- it { is_expected.to contain_exec('zabbix_server_data.sql').with_command("cd /usr/share/doc/zabbix-*-pgsql-2.4*/create && if [ -f data.sql.gz ]; then gunzip -f data.sql.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -d 'zabbix-server' -f data.sql && touch /etc/zabbix/.data.done") }
+ if zabbix_version != '2.4'
+ it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path_for3_and_up} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -d 'zabbix-server' -f create.sql && 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") }
+ else
+ it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path_for2} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -d 'zabbix-server' -f schema.sql && touch /etc/zabbix/.schema.done") }
+ it { is_expected.to contain_exec('zabbix_server_images.sql').with_command("cd #{path_for2} && if [ -f images.sql.gz ]; then gunzip -f images.sql.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -d 'zabbix-server' -f images.sql && touch /etc/zabbix/.images.done") }
+ it { is_expected.to contain_exec('zabbix_server_data.sql').with_command("cd #{path_for2} && if [ -f data.sql.gz ]; then gunzip -f data.sql.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -d 'zabbix-server' -f data.sql && touch /etc/zabbix/.data.done") }
+ end
it { is_expected.to contain_file('/root/.pgpass') }
it { is_expected.to contain_class('zabbix::params') }
end
- describe 'when zabbix_type is proxy' do
+ describe "when zabbix_type is proxy and version is #{zabbix_version}" do
let :params do
{
database_name: 'zabbix-proxy',
@@ -47,13 +71,17 @@ describe 'zabbix::database::postgresql' do
database_password: 'zabbix-proxy',
database_host: 'node01.example.com',
zabbix_type: 'proxy',
- zabbix_version: '2.4'
+ 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') }
- it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd /usr/share/doc/zabbix-*-pgsql-2.4*/create && 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") }
+ if zabbix_version != '2.4'
+ it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path_for3_and_up} && 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_for2} && 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") }
+ end
it { is_expected.to contain_class('zabbix::params') }
end
end

spec: Add all versions of server/proxy for databases

Signed-off-by: Christos Papageorgiou <root.expert.xda@gmail.com>