From 4ca8e9c452c2c71827c3debbe8c9f2ef330f653e Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 12 Mar 2024 13:01:02 +0100 Subject: [PATCH] Centralize the logic which server/agent versions are supported Rather than duplicating the logic in every file, this introduces helpers. --- spec/acceptance/agent_spec.rb | 5 +---- spec/acceptance/server_spec.rb | 11 +---------- spec/acceptance/zabbix_application_spec.rb | 10 ++-------- spec/acceptance/zabbix_host_spec.rb | 13 ++----------- spec/acceptance/zabbix_hostgroup_spec.rb | 13 ++----------- spec/acceptance/zabbix_proxy_spec.rb | 13 ++----------- spec/acceptance/zabbix_template_host_spec.rb | 12 ++---------- spec/acceptance/zabbix_template_spec.rb | 13 ++----------- spec/support/acceptance/supported_versions.rb | 14 ++++++++++++++ 9 files changed, 28 insertions(+), 76 deletions(-) diff --git a/spec/acceptance/agent_spec.rb b/spec/acceptance/agent_spec.rb index 15d5faf80..81950be09 100644 --- a/spec/acceptance/agent_spec.rb +++ b/spec/acceptance/agent_spec.rb @@ -2,10 +2,7 @@ require 'spec_helper_acceptance' -supported_versions.each do |version| - # < 6.0 agent packages are not available for Debian 12 - next if version < '6.0' && default[:platform] =~ %r{debian-12} - +supported_agent_versions(default[:platform]).each do |version| describe "zabbix::agent class with zabbix_version #{version}" do context 'With minimal parameter' do it 'works idempotently with no errors' do diff --git a/spec/acceptance/server_spec.rb b/spec/acceptance/server_spec.rb index 20f625b9d..60a0629ba 100644 --- a/spec/acceptance/server_spec.rb +++ b/spec/acceptance/server_spec.rb @@ -38,16 +38,7 @@ class { 'zabbix::database': } end end - supported_versions.each do |zabbix_version| - # >= 5.2 server packages are not available for RHEL 7 - next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64' - # < 6.0 server packages are not available for RHEL 9 - next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64' - # <6.0 server packages are not available for ubuntu 22.04 - next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22} - # < 6.0 server packages are not available for Debian 12 - next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12} - + supported_server_versions(default[:platform]).each do |zabbix_version| context "deploys a zabbix #{zabbix_version} server" do # Using puppet_apply as a helper it 'works idempotently with no errors' do diff --git a/spec/acceptance/zabbix_application_spec.rb b/spec/acceptance/zabbix_application_spec.rb index 6150ac751..b5f9cb2f1 100644 --- a/spec/acceptance/zabbix_application_spec.rb +++ b/spec/acceptance/zabbix_application_spec.rb @@ -3,16 +3,10 @@ require 'spec_helper_acceptance' require 'serverspec_type_zabbixapi' -describe 'zabbix_application type', unless: default[:platform] =~ %r{archlinux} do - supported_versions.each do |zabbix_version| +describe 'zabbix_application type' do + supported_server_versions(default[:platform]).each do |zabbix_version| # Application API was removed in Zabbix 5.4 next if zabbix_version >= '5.4' - # < 6.0 server packages are not available for RHEL 9 - next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64' - # <6.0 server packages are not available for ubuntu 22.04 - next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22} - # < 6.0 server packages are not available for Debian 12 - next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12} template = case zabbix_version when '5.0' diff --git a/spec/acceptance/zabbix_host_spec.rb b/spec/acceptance/zabbix_host_spec.rb index 79b195b99..5c46de337 100644 --- a/spec/acceptance/zabbix_host_spec.rb +++ b/spec/acceptance/zabbix_host_spec.rb @@ -4,17 +4,8 @@ require 'serverspec_type_zabbixapi' # rubocop:disable RSpec/LetBeforeExamples -describe 'zabbix_host type', unless: default[:platform] =~ %r{archlinux} do - supported_versions.each do |zabbix_version| - # >= 5.2 server packages are not available for RHEL 7 - next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64' - # < 6.0 server packages are not available for RHEL 9 - next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64' - # <6.0 server packages are not available for ubuntu 22.04 - next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22} - # < 6.0 server packages are not available for Debian 12 - next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12} - +describe 'zabbix_host type' do + supported_server_versions(default[:platform]).each do |zabbix_version| context "create zabbix_host resources with zabbix version #{zabbix_version}" do # This will deploy a running Zabbix setup (server, web, db) which we can # use for custom type tests diff --git a/spec/acceptance/zabbix_hostgroup_spec.rb b/spec/acceptance/zabbix_hostgroup_spec.rb index 22cf7ed81..260e4b1fd 100644 --- a/spec/acceptance/zabbix_hostgroup_spec.rb +++ b/spec/acceptance/zabbix_hostgroup_spec.rb @@ -3,17 +3,8 @@ require 'spec_helper_acceptance' require 'serverspec_type_zabbixapi' -describe 'zabbix_hostgroup type', unless: default[:platform] =~ %r{archlinux} do - supported_versions.each do |zabbix_version| - # >= 5.2 server packages are not available for RHEL 7 - next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64' - # < 6.0 server packages are not available for RHEL 9 - next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64' - # <6.0 server packages are not available for ubuntu 22.04 - next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22} - # < 6.0 server packages are not available for Debian 12 - next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12} - +describe 'zabbix_hostgroup type' do + supported_server_versions(default[:platform]).each do |zabbix_version| context "create zabbix_hostgroup resources with zabbix version #{zabbix_version}" do # This will deploy a running Zabbix setup (server, web, db) which we can # use for custom type tests diff --git a/spec/acceptance/zabbix_proxy_spec.rb b/spec/acceptance/zabbix_proxy_spec.rb index 401566c47..8003a5ae8 100644 --- a/spec/acceptance/zabbix_proxy_spec.rb +++ b/spec/acceptance/zabbix_proxy_spec.rb @@ -4,17 +4,8 @@ require 'serverspec_type_zabbixapi' # rubocop:disable RSpec/LetBeforeExamples -describe 'zabbix_proxy type', unless: default[:platform] =~ %r{archlinux} do - supported_versions.each do |zabbix_version| - # >= 5.2 server packages are not available for RHEL 7 - next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64' - # < 6.0 server packages are not available for RHEL 9 - next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64' - # <6.0 server packages are not available for ubuntu 22.04 - next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22} - # < 6.0 server packages are not available for Debian 12 - next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12} - +describe 'zabbix_proxy type' do + supported_server_versions(default[:platform]).each do |zabbix_version| context "create zabbix_proxy resources with zabbix version #{zabbix_version}" do # This will deploy a running Zabbix setup (server, web, db) which we can # use for custom type tests diff --git a/spec/acceptance/zabbix_template_host_spec.rb b/spec/acceptance/zabbix_template_host_spec.rb index 961e66eba..b455e3078 100644 --- a/spec/acceptance/zabbix_template_host_spec.rb +++ b/spec/acceptance/zabbix_template_host_spec.rb @@ -3,18 +3,10 @@ require 'spec_helper_acceptance' require 'serverspec_type_zabbixapi' -describe 'zabbix_template_host type', unless: default[:platform] =~ %r{archlinux} do - supported_versions.each do |zabbix_version| +describe 'zabbix_template_host type' do + supported_server_versions(default[:platform]).each do |zabbix_version| # Zabbix 6.0 removed the ability to attach templates directly to hosts. next if zabbix_version == '6.0' - # >= 5.2 server packages are not available for RHEL 7 - next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64' - # < 6.0 server packages are not available for RHEL 9 - next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64' - # <6.0 server packages are not available for ubuntu 22.04 - next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22} - # < 6.0 server packages are not available for Debian 12 - next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12} context "create zabbix_template_host resources with zabbix version #{zabbix_version}" do template = case zabbix_version diff --git a/spec/acceptance/zabbix_template_spec.rb b/spec/acceptance/zabbix_template_spec.rb index 1cbb87eac..ccbd66089 100644 --- a/spec/acceptance/zabbix_template_spec.rb +++ b/spec/acceptance/zabbix_template_spec.rb @@ -3,17 +3,8 @@ require 'spec_helper_acceptance' require 'serverspec_type_zabbixapi' -describe 'zabbix_template type', unless: default[:platform] =~ %r{archlinux} do - supported_versions.each do |zabbix_version| - # >= 5.2 server packages are not available for RHEL 7 - next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64' - # < 6.0 server packages are not available for RHEL 9 - next if zabbix_version < '6.0' && default[:platform] == 'el-9-x86_64' - # <6.0 server packages are not available for ubuntu 22.04 - next if zabbix_version < '6.0' && default[:platform] =~ %r{ubuntu-22} - # < 6.0 server packages are not available for Debian 12 - next if zabbix_version < '6.0' && default[:platform] =~ %r{debian-12} - +describe 'zabbix_template type' do + supported_server_versions(default[:platform]).each do |zabbix_version| context "create zabbix_template resources with zabbix version #{zabbix_version}" do # This will deploy a running Zabbix setup (server, web, db) which we can # use for custom type tests diff --git a/spec/support/acceptance/supported_versions.rb b/spec/support/acceptance/supported_versions.rb index 47017f7f8..e38eed6b7 100644 --- a/spec/support/acceptance/supported_versions.rb +++ b/spec/support/acceptance/supported_versions.rb @@ -9,3 +9,17 @@ def supported_versions end supported_versions end + +def supported_agent_versions(platform) + supported_versions.reject do |version| + version < '6.0' && platform.start_with?('debian-12') + end +end + +def supported_server_versions(platform) + supported_versions.reject do |version| + platform.start_with?('archlinux') || + (version >= '5.2' && platform.start_with?('el-7')) || + (version < '6.0' && platform.start_with?('el-9', 'ubuntu-22', 'debian-12')) + end +end