Skip to content

Commit 4ca8e9c

Browse files
committed
Centralize the logic which server/agent versions are supported
Rather than duplicating the logic in every file, this introduces helpers.
1 parent 934afa2 commit 4ca8e9c

File tree

9 files changed

+28
-76
lines changed

9 files changed

+28
-76
lines changed

spec/acceptance/agent_spec.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
require 'spec_helper_acceptance'
44

5-
supported_versions.each do |version|
6-
# < 6.0 agent packages are not available for Debian 12
7-
next if version < '6.0' && default[:platform] =~ %r{debian-12}
8-
5+
supported_agent_versions(default[:platform]).each do |version|
96
describe "zabbix::agent class with zabbix_version #{version}" do
107
context 'With minimal parameter' do
118
it 'works idempotently with no errors' do

spec/acceptance/server_spec.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,7 @@ class { 'zabbix::database': }
3838
end
3939
end
4040

41-
supported_versions.each do |zabbix_version|
42-
# >= 5.2 server packages are not available for RHEL 7
43-
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
44-
# < 6.0 server packages are not available for RHEL 9
45-
next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64'
46-
# <6.0 server packages are not available for ubuntu 22.04
47-
next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22}
48-
# < 6.0 server packages are not available for Debian 12
49-
next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12}
50-
41+
supported_server_versions(default[:platform]).each do |zabbix_version|
5142
context "deploys a zabbix #{zabbix_version} server" do
5243
# Using puppet_apply as a helper
5344
it 'works idempotently with no errors' do

spec/acceptance/zabbix_application_spec.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
require 'spec_helper_acceptance'
44
require 'serverspec_type_zabbixapi'
55

6-
describe 'zabbix_application type', unless: default[:platform] =~ %r{archlinux} do
7-
supported_versions.each do |zabbix_version|
6+
describe 'zabbix_application type' do
7+
supported_server_versions(default[:platform]).each do |zabbix_version|
88
# Application API was removed in Zabbix 5.4
99
next if zabbix_version >= '5.4'
10-
# < 6.0 server packages are not available for RHEL 9
11-
next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64'
12-
# <6.0 server packages are not available for ubuntu 22.04
13-
next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22}
14-
# < 6.0 server packages are not available for Debian 12
15-
next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12}
1610

1711
template = case zabbix_version
1812
when '5.0'

spec/acceptance/zabbix_host_spec.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,8 @@
44
require 'serverspec_type_zabbixapi'
55

66
# rubocop:disable RSpec/LetBeforeExamples
7-
describe 'zabbix_host type', unless: default[:platform] =~ %r{archlinux} do
8-
supported_versions.each do |zabbix_version|
9-
# >= 5.2 server packages are not available for RHEL 7
10-
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
11-
# < 6.0 server packages are not available for RHEL 9
12-
next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64'
13-
# <6.0 server packages are not available for ubuntu 22.04
14-
next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22}
15-
# < 6.0 server packages are not available for Debian 12
16-
next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12}
17-
7+
describe 'zabbix_host type' do
8+
supported_server_versions(default[:platform]).each do |zabbix_version|
189
context "create zabbix_host resources with zabbix version #{zabbix_version}" do
1910
# This will deploy a running Zabbix setup (server, web, db) which we can
2011
# use for custom type tests

spec/acceptance/zabbix_hostgroup_spec.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@
33
require 'spec_helper_acceptance'
44
require 'serverspec_type_zabbixapi'
55

6-
describe 'zabbix_hostgroup type', unless: default[:platform] =~ %r{archlinux} do
7-
supported_versions.each do |zabbix_version|
8-
# >= 5.2 server packages are not available for RHEL 7
9-
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
10-
# < 6.0 server packages are not available for RHEL 9
11-
next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64'
12-
# <6.0 server packages are not available for ubuntu 22.04
13-
next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22}
14-
# < 6.0 server packages are not available for Debian 12
15-
next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12}
16-
6+
describe 'zabbix_hostgroup type' do
7+
supported_server_versions(default[:platform]).each do |zabbix_version|
178
context "create zabbix_hostgroup resources with zabbix version #{zabbix_version}" do
189
# This will deploy a running Zabbix setup (server, web, db) which we can
1910
# use for custom type tests

spec/acceptance/zabbix_proxy_spec.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,8 @@
44
require 'serverspec_type_zabbixapi'
55

66
# rubocop:disable RSpec/LetBeforeExamples
7-
describe 'zabbix_proxy type', unless: default[:platform] =~ %r{archlinux} do
8-
supported_versions.each do |zabbix_version|
9-
# >= 5.2 server packages are not available for RHEL 7
10-
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
11-
# < 6.0 server packages are not available for RHEL 9
12-
next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64'
13-
# <6.0 server packages are not available for ubuntu 22.04
14-
next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22}
15-
# < 6.0 server packages are not available for Debian 12
16-
next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12}
17-
7+
describe 'zabbix_proxy type' do
8+
supported_server_versions(default[:platform]).each do |zabbix_version|
189
context "create zabbix_proxy resources with zabbix version #{zabbix_version}" do
1910
# This will deploy a running Zabbix setup (server, web, db) which we can
2011
# use for custom type tests

spec/acceptance/zabbix_template_host_spec.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@
33
require 'spec_helper_acceptance'
44
require 'serverspec_type_zabbixapi'
55

6-
describe 'zabbix_template_host type', unless: default[:platform] =~ %r{archlinux} do
7-
supported_versions.each do |zabbix_version|
6+
describe 'zabbix_template_host type' do
7+
supported_server_versions(default[:platform]).each do |zabbix_version|
88
# Zabbix 6.0 removed the ability to attach templates directly to hosts.
99
next if zabbix_version == '6.0'
10-
# >= 5.2 server packages are not available for RHEL 7
11-
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
12-
# < 6.0 server packages are not available for RHEL 9
13-
next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64'
14-
# <6.0 server packages are not available for ubuntu 22.04
15-
next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22}
16-
# < 6.0 server packages are not available for Debian 12
17-
next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12}
1810

1911
context "create zabbix_template_host resources with zabbix version #{zabbix_version}" do
2012
template = case zabbix_version

spec/acceptance/zabbix_template_spec.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@
33
require 'spec_helper_acceptance'
44
require 'serverspec_type_zabbixapi'
55

6-
describe 'zabbix_template type', unless: default[:platform] =~ %r{archlinux} do
7-
supported_versions.each do |zabbix_version|
8-
# >= 5.2 server packages are not available for RHEL 7
9-
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
10-
# < 6.0 server packages are not available for RHEL 9
11-
next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64'
12-
# <6.0 server packages are not available for ubuntu 22.04
13-
next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22}
14-
# < 6.0 server packages are not available for Debian 12
15-
next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12}
16-
6+
describe 'zabbix_template type' do
7+
supported_server_versions(default[:platform]).each do |zabbix_version|
178
context "create zabbix_template resources with zabbix version #{zabbix_version}" do
189
# This will deploy a running Zabbix setup (server, web, db) which we can
1910
# use for custom type tests

spec/support/acceptance/supported_versions.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,17 @@ def supported_versions
99
end
1010
supported_versions
1111
end
12+
13+
def supported_agent_versions(platform)
14+
supported_versions.reject do |version|
15+
version < '6.0' && platform.start_with?('debian-12')
16+
end
17+
end
18+
19+
def supported_server_versions(platform)
20+
supported_versions.reject do |version|
21+
platform.start_with?('archlinux') ||
22+
(version >= '5.2' && platform.start_with?('el-7')) ||
23+
(version < '6.0' && platform.start_with?('el-9', 'ubuntu-22', 'debian-12'))
24+
end
25+
end

0 commit comments

Comments
 (0)