From 8b071c26f69bb6421d71fc77f75389d91eb52020 Mon Sep 17 00:00:00 2001 From: Roberto Valentini Date: Thu, 27 Jun 2024 17:21:47 +0200 Subject: [PATCH 1/8] Change manage_startup_script default to false Set manage_startup_script to false on OS that provide correct systemd unit in package --- manifests/params.pp | 13 ++++---- spec/classes/agent_spec.rb | 51 ++++++++++++++++------------- spec/classes/server_spec.rb | 32 +++++++++--------- spec/defines/userparameters_spec.rb | 4 +-- 4 files changed, 54 insertions(+), 46 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 7b2c0c9b5..98ecd4162 100755 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -20,6 +20,7 @@ $server_zabbix_user = 'zabbix' $zabbix_package_provider = undef $agent_loadmodulepath = '/usr/lib/modules' + $manage_startup_script = false } 'AIX': { $manage_repo = false @@ -32,6 +33,7 @@ $agent_config_group = 'zabbix' $agent_pidfile = '/var/run/zabbix/zabbix_agentd.pid' $agent_servicename = 'zabbix-agent' + $manage_startup_script = true } 'Archlinux': { $server_fpinglocation = '/usr/bin/fping' @@ -51,6 +53,7 @@ $server_zabbix_user = 'zabbix-server' $zabbix_package_provider = undef $agent_loadmodulepath = '/usr/lib/modules' + $manage_startup_script = false } 'FreeBSD': { $manage_repo = false @@ -66,6 +69,7 @@ $server_zabbix_user = 'zabbix' $zabbix_package_provider = undef $agent_loadmodulepath = '/usr/local/lib/zabbix/modules' + $manage_startup_script = false } 'Gentoo': { $server_fpinglocation = '/usr/sbin/fping' @@ -85,6 +89,7 @@ $server_zabbix_user = 'zabbix' $zabbix_package_provider = undef $agent_loadmodulepath = '/usr/lib/modules' + $manage_startup_script = false } 'windows': { $manage_repo = false @@ -99,6 +104,7 @@ $agent_servicename = 'Zabbix Agent' $agent_include = 'C:/ProgramData/zabbix/zabbix_agentd.d' $agent_loadmodulepath = undef + $manage_startup_script = false } default : { $server_fpinglocation = '/usr/sbin/fping' @@ -118,6 +124,7 @@ $server_zabbix_user = 'zabbix' $zabbix_package_provider = undef $agent_loadmodulepath = '/usr/lib/modules' + $manage_startup_script = false } } @@ -129,12 +136,6 @@ $zabbix_version = '6.0' } - $manage_startup_script = downcase($facts['kernel']) ? { - 'windows' => false, - 'FreeBSD' => false, - default => true, - } - $zabbix_package_state = 'present' $zabbix_proxy = 'localhost' $zabbix_proxy_ip = '127.0.0.1' diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb index 856c3c954..edae4c834 100644 --- a/spec/classes/agent_spec.rb +++ b/spec/classes/agent_spec.rb @@ -86,11 +86,10 @@ is_expected.to contain_service(service_name). with_ensure('running'). with_enable(true). - with_service_provider(facts[:os]['family'] == 'AIX' ? 'init' : nil). - that_requires(["Package[#{package_name}]", "Zabbix::Startup[#{service_name}]"]) + with_service_provider(facts[:os]['family'] == 'AIX' ? 'init' : nil) end - it { is_expected.to contain_zabbix__startup(service_name).that_requires("Package[#{package_name}]") } + it { is_expected.not_to contain_zabbix__startup(service_name) } it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('zabbix::params') } end @@ -218,29 +217,37 @@ it { is_expected.not_to contain_firewall('150 zabbix-agent from 10.11.12.13') } end - context 'it creates a startup script' do - if facts[:kernel] == 'Linux' - case facts[:os]['family'] - when 'Archlinux', 'Debian', 'Gentoo', 'RedHat' - it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('absent') } - it { is_expected.to contain_file("/etc/systemd/system/#{service_name}.service").with_ensure('file') } - when 'windows' - it { is_expected.to contain_exec("install_agent_#{service_name}") } - else - it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('file') } - it { is_expected.not_to contain_file("/etc/systemd/system/#{service_name}.service") } - end - end - end - - context 'when declaring manage_startup_script is false' do + context 'when declaring manage_startup_script is true' do let :params do { - manage_startup_script: false + manage_startup_script: true } end - it { is_expected.not_to contain_zabbix__startup(service_name) } + context 'it creates a startup script' do + if facts[:kernel] == 'Linux' + case facts[:os]['family'] + when 'Archlinux', 'Debian', 'Gentoo', 'RedHat' + it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('absent') } + it { is_expected.to contain_file("/etc/systemd/system/#{service_name}.service").with_ensure('file') } + when 'windows' + it { is_expected.to contain_exec("install_agent_#{service_name}") } + else + it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('file') } + it { is_expected.not_to contain_file("/etc/systemd/system/#{service_name}.service") } + end + end + end + + it do + is_expected.to contain_service(service_name). + with_ensure('running'). + with_enable(true). + with_service_provider(facts[:os]['family'] == 'AIX' ? 'init' : nil). + that_requires(["Package[#{package_name}]", "Zabbix::Startup[#{service_name}]"]) + end + + it { is_expected.to contain_zabbix__startup(service_name).that_requires("Package[#{package_name}]") } end context 'when declaring zabbix_alias' do @@ -460,7 +467,7 @@ end end - describe 'with systemd active' do + describe 'with systemd active', skip: 'user package provided instead systemd::unit_file ' do if facts[:kernel] == 'Linux' let :facts do super().merge(systemd: true) diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 6de4ba196..0d343037a 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -25,7 +25,7 @@ it { is_expected.to contain_class('zabbix::repo') } it { is_expected.to contain_class('zabbix::params') } it { is_expected.to contain_service('zabbix-server').with_ensure('running') } - it { is_expected.to contain_zabbix__startup('zabbix-server') } + it { is_expected.not_to contain_zabbix__startup('zabbix-server') } it { is_expected.to contain_apt__source('zabbix') } if facts[:os]['family'] == 'Debian' it { is_expected.to contain_apt__key('zabbix-A1848F5') } if facts[:os]['family'] == 'Debian' @@ -159,26 +159,26 @@ it { is_expected.not_to contain_firewall('151 zabbix-server') } end - context 'it creates a startup script' do - case facts[:os]['family'] - when 'Archlinux', 'Debian', 'Gentoo', 'RedHat' - it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('absent') } - it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_ensure('file') } - it { is_expected.to contain_systemd__unit_file('zabbix-server.service') } - else - it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('file') } - it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-server.service') } - end - end - - context 'when declaring manage_startup_script is false' do + context 'when declaring manage_startup_script is true' do let :params do { - manage_startup_script: false + manage_startup_script: true } end - it { is_expected.not_to contain_zabbix__startup('zabbix-server') } + context 'it creates a startup script' do + case facts[:os]['family'] + when 'Archlinux', 'Debian', 'Gentoo', 'RedHat' + it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('absent') } + it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_ensure('file') } + it { is_expected.to contain_systemd__unit_file('zabbix-server.service') } + else + it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('file') } + it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-server.service') } + end + end + + it { is_expected.to contain_zabbix__startup('zabbix-server') } end # If manage_service is true (default), it should create a service diff --git a/spec/defines/userparameters_spec.rb b/spec/defines/userparameters_spec.rb index 8baef3f1c..a49949a4e 100644 --- a/spec/defines/userparameters_spec.rb +++ b/spec/defines/userparameters_spec.rb @@ -22,12 +22,12 @@ it { is_expected.to contain_class('zabbix::params') } it { is_expected.to contain_class('zabbix::repo') } it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file("/etc/init.d/#{service}") } + it { is_expected.not_to contain_file("/etc/init.d/#{service}") } it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf') } it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.d') } it { is_expected.to contain_package(package) } it { is_expected.to contain_service(service) } - it { is_expected.to contain_zabbix__startup(service) } + it { is_expected.not_to contain_zabbix__startup(service) } end context 'with ensure => absent' do From 7f1df97d70f45f3c6e508f6c084f06dbdad68acf Mon Sep 17 00:00:00 2001 From: Roberto Valentini Date: Thu, 27 Jun 2024 14:22:21 +0200 Subject: [PATCH 2/8] Remove VirtuozzoLinux from supported OS --- metadata.json | 6 ------ spec/classes/web_spec.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/metadata.json b/metadata.json index 38cd6ae87..90099b8e6 100644 --- a/metadata.json +++ b/metadata.json @@ -135,12 +135,6 @@ "12" ] }, - { - "operatingsystem": "VirtuozzoLinux", - "operatingsystemrelease": [ - "7" - ] - }, { "operatingsystem": "Archlinux" }, diff --git a/spec/classes/web_spec.rb b/spec/classes/web_spec.rb index 101b47bb3..645021c5c 100644 --- a/spec/classes/web_spec.rb +++ b/spec/classes/web_spec.rb @@ -91,7 +91,7 @@ class { 'apache': packages = if facts[:os]['family'] == 'RedHat' if facts[:os]['release']['major'].to_i == 7 && - !%w[VirtuozzoLinux OracleLinux Scientific].include?(facts[:os]['name']) + !%w[OracleLinux Scientific].include?(facts[:os]['name']) %w[zabbix-web-pgsql-scl zabbix-web] else %w[zabbix-web-pgsql zabbix-web] From f61c84bbc0da0ca96a7acd81ec976844b9cea4f2 Mon Sep 17 00:00:00 2001 From: Roberto Valentini Date: Thu, 27 Jun 2024 14:22:39 +0200 Subject: [PATCH 3/8] Remove XenServer from supported OS --- metadata.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/metadata.json b/metadata.json index 90099b8e6..973b52949 100644 --- a/metadata.json +++ b/metadata.json @@ -115,12 +115,6 @@ "8" ] }, - { - "operatingsystem": "XenServer", - "operatingsystemrelease": [ - "6" - ] - }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ From c011f23401e1b8e3648b616424b6bc047a1bd223 Mon Sep 17 00:00:00 2001 From: Roberto Valentini Date: Thu, 27 Jun 2024 14:22:45 +0200 Subject: [PATCH 4/8] Remove CloudLinux from supported OS --- metadata.json | 7 ------- 1 file changed, 7 deletions(-) diff --git a/metadata.json b/metadata.json index 973b52949..aeb485889 100644 --- a/metadata.json +++ b/metadata.json @@ -108,13 +108,6 @@ "9" ] }, - { - "operatingsystem": "CloudLinux", - "operatingsystemrelease": [ - "7", - "8" - ] - }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ From 1456de4a13fd3f8353b71eb92d5488529d71058c Mon Sep 17 00:00:00 2001 From: Roberto Valentini Date: Thu, 27 Jun 2024 14:22:49 +0200 Subject: [PATCH 5/8] Remove Scientific from supported OS --- metadata.json | 7 ------- spec/classes/web_spec.rb | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/metadata.json b/metadata.json index aeb485889..a68262671 100644 --- a/metadata.json +++ b/metadata.json @@ -79,13 +79,6 @@ "9" ] }, - { - "operatingsystem": "Scientific", - "operatingsystemrelease": [ - "7", - "8" - ] - }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ diff --git a/spec/classes/web_spec.rb b/spec/classes/web_spec.rb index 645021c5c..6fee84aff 100644 --- a/spec/classes/web_spec.rb +++ b/spec/classes/web_spec.rb @@ -91,7 +91,7 @@ class { 'apache': packages = if facts[:os]['family'] == 'RedHat' if facts[:os]['release']['major'].to_i == 7 && - !%w[OracleLinux Scientific].include?(facts[:os]['name']) + !%w[OracleLinux].include?(facts[:os]['name']) %w[zabbix-web-pgsql-scl zabbix-web] else %w[zabbix-web-pgsql zabbix-web] From f096892b5adfa4515150ad929d4ec175ce2987ba Mon Sep 17 00:00:00 2001 From: Roberto Valentini Date: Thu, 27 Jun 2024 14:22:58 +0200 Subject: [PATCH 6/8] Remove Amazon from supported OS --- manifests/repo.pp | 12 +----------- metadata.json | 7 ------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/manifests/repo.pp b/manifests/repo.pp index 4a7674566..41b88b015 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -18,19 +18,9 @@ String[1] $zabbix_version = $zabbix::params::zabbix_version, ) inherits zabbix::params { if $manage_repo { - case $facts['os']['name'] { - 'PSBM': { - $majorrelease = '6' - } - 'Amazon': { - $majorrelease = '6' - } - default: { - $majorrelease = $facts['os']['release']['major'] - } - } case $facts['os']['family'] { 'RedHat': { + $majorrelease = $facts['os']['release']['major'] if (versioncmp(fact('os.release.major'), '7') >= 0 and $zabbix_version == '7.0') { $gpgkey_zabbix = 'https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-B5333005' $gpgkey_nonsupported = 'https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-B5333005' diff --git a/metadata.json b/metadata.json index a68262671..dd7f39050 100644 --- a/metadata.json +++ b/metadata.json @@ -64,13 +64,6 @@ "9" ] }, - { - "operatingsystem": "Amazon", - "operatingsystemrelease": [ - "7", - "8" - ] - }, { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ From f00c8c9ad65554053111d342aaa6dc4519c8cd77 Mon Sep 17 00:00:00 2001 From: Roberto Valentini Date: Thu, 27 Jun 2024 14:23:03 +0200 Subject: [PATCH 7/8] Remove Centos 8 from supported OS --- metadata.json | 1 - spec/spec_helper_methods.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/metadata.json b/metadata.json index dd7f39050..315f8ac89 100644 --- a/metadata.json +++ b/metadata.json @@ -76,7 +76,6 @@ "operatingsystem": "CentOS", "operatingsystemrelease": [ "7", - "8", "9" ] }, diff --git a/spec/spec_helper_methods.rb b/spec/spec_helper_methods.rb index 5b3e02063..30ad7aaa8 100644 --- a/spec/spec_helper_methods.rb +++ b/spec/spec_helper_methods.rb @@ -5,7 +5,7 @@ def baseline_os_hash supported_os: [ { 'operatingsystem' => 'CentOS', - 'operatingsystemrelease' => %w[7 8] + 'operatingsystemrelease' => %w[7] }, { 'operatingsystem' => 'Debian', From 56c384a178c6c6bbd3fe0d9c0ec56e266e53c302 Mon Sep 17 00:00:00 2001 From: Roberto Valentini Date: Fri, 28 Jun 2024 13:29:34 +0200 Subject: [PATCH 8/8] Remove baseline_os filter Fix spec for supported OS in metadata.json --- .sync.yml | 1 - spec/classes/agent_spec.rb | 37 +- spec/classes/database_mysql_spec.rb | 2 +- spec/classes/database_postgresql_spec.rb | 2 +- spec/classes/database_spec.rb | 2 +- spec/classes/javagateway_spec.rb | 4 +- spec/classes/proxy_spec.rb | 698 +++++++++++------------ spec/classes/repo_spec.rb | 8 +- spec/classes/sender_spec.rb | 6 +- spec/classes/server_spec.rb | 6 +- spec/classes/userparameter_spec.rb | 2 +- spec/classes/web_spec.rb | 10 +- spec/defines/userparameters_spec.rb | 30 +- spec/spec_helper.rb | 1 - spec/spec_helper_methods.rb | 31 - 15 files changed, 416 insertions(+), 424 deletions(-) delete mode 100644 spec/spec_helper_methods.rb diff --git a/.sync.yml b/.sync.yml index 0eecc424f..75052a749 100644 --- a/.sync.yml +++ b/.sync.yml @@ -8,7 +8,6 @@ spec/spec_helper.rb: mock_with: ':mocha' spec_overrides: - "require 'support/acceptance/supported_versions'" - - "require 'spec_helper_methods'" .puppet-lint.rc: enabled_lint_checks: - parameter_documentation diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb index edae4c834..c52280fc0 100644 --- a/spec/classes/agent_spec.rb +++ b/spec/classes/agent_spec.rb @@ -14,11 +14,13 @@ } end - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| context "on #{os}" do config_path = case facts[:os]['name'] when 'windows' 'C:/ProgramData/zabbix/zabbix_agentd.conf' + when 'FreeBSD' + '/usr/local/etc/zabbix6/zabbix_agentd.conf' else '/etc/zabbix/zabbix_agentd.conf' end @@ -32,6 +34,8 @@ include_dir = case facts[:os]['name'] when 'windows' 'C:/ProgramData/zabbix/zabbix_agentd.d' + when 'FreeBSD' + '/usr/local/etc/zabbix6/zabbix_agentd.d' else '/etc/zabbix/zabbix_agentd.d' end @@ -50,6 +54,9 @@ when 'windows' package_name = 'zabbix-agent' service_name = 'Zabbix Agent' + when 'FreeBSD' + package_name = 'zabbix6-agent' + service_name = 'zabbix_agentd' else package_name = 'zabbix-agent' service_name = 'zabbix-agent' @@ -60,7 +67,7 @@ context 'with all defaults' do it { is_expected.to contain_selinux__module('zabbix-agent') } if facts[:os]['family'] == 'RedHat' it { is_expected.to contain_yumrepo('zabbix-frontend') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' - it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' + it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' && %w[OracleLinux CentOS].include?(facts[:os]['name']) it { is_expected.to contain_apt__key('zabbix-A1848F5') } if facts[:os]['family'] == 'Debian' it { is_expected.to contain_apt__key('zabbix-FBABD5F') } if facts[:os]['family'] == 'Debian' it { is_expected.to contain_file(include_dir).with_ensure('directory') } @@ -75,11 +82,20 @@ ) end else - it do - is_expected.to contain_package(package_name). - with_ensure('present'). - with_tag('zabbix'). - that_requires('Class[zabbix::repo]') + + if facts[:os]['family'] == 'Gentoo' + it do + is_expected.to contain_package(package_name). + with_ensure('present'). + with_tag('zabbix') + end + else + it do + is_expected.to contain_package(package_name). + with_ensure('present'). + with_tag('zabbix'). + that_requires('Class[zabbix::repo]') + end end it do @@ -103,7 +119,7 @@ end case facts[:os]['family'] - when 'Archlinux' + when %w[Archlinux Gentoo FreeBSD].include?(facts[:os]['family']) it { is_expected.not_to compile.with_all_deps } when 'Debian' # rubocop:disable RSpec/RepeatedExample @@ -218,6 +234,9 @@ end context 'when declaring manage_startup_script is true' do + next if facts[:os]['family'] == 'FreeBSD' + next if facts[:os]['family'] == 'Gentoo' + let :params do { manage_startup_script: true @@ -478,6 +497,8 @@ end context 'when zabbix_package_agent is zabbix-agent2' do + next if facts[:os]['family'] == 'Gentoo' + let :params do { zabbix_package_agent: 'zabbix-agent2', startagents: 1, diff --git a/spec/classes/database_mysql_spec.rb b/spec/classes/database_mysql_spec.rb index 2e59d7590..064e65627 100644 --- a/spec/classes/database_mysql_spec.rb +++ b/spec/classes/database_mysql_spec.rb @@ -7,7 +7,7 @@ 'rspec.puppet.com' end - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| next if facts[:os]['name'] == 'windows' context "on #{os}" do diff --git a/spec/classes/database_postgresql_spec.rb b/spec/classes/database_postgresql_spec.rb index 802550213..65c30300c 100644 --- a/spec/classes/database_postgresql_spec.rb +++ b/spec/classes/database_postgresql_spec.rb @@ -7,7 +7,7 @@ 'rspec.puppet.com' end - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| next if facts[:os]['name'] == 'windows' context "on #{os}" do diff --git a/spec/classes/database_spec.rb b/spec/classes/database_spec.rb index 809e6d852..8c84ee2b8 100644 --- a/spec/classes/database_spec.rb +++ b/spec/classes/database_spec.rb @@ -7,7 +7,7 @@ 'rspec.puppet.com' end - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| next if facts[:os]['name'] == 'windows' context "on #{os}" do diff --git a/spec/classes/javagateway_spec.rb b/spec/classes/javagateway_spec.rb index 11ba5d894..5350a82ca 100644 --- a/spec/classes/javagateway_spec.rb +++ b/spec/classes/javagateway_spec.rb @@ -7,7 +7,7 @@ 'rspec.puppet.com' end - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| next if facts[:os]['name'] == 'windows' context "on #{os}" do @@ -28,7 +28,7 @@ it { is_expected.to contain_service('zabbix-java-gateway').with_require(['Package[zabbix-java-gateway]', 'File[/etc/zabbix/zabbix_java_gateway.conf]']) } it { is_expected.to contain_yumrepo('zabbix-frontend') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' - it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' + it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' && %w[OracleLinux CentOS].include?(facts[:os]['name']) it { is_expected.to contain_apt__key('zabbix-A1848F5') } if facts[:os]['family'] == 'Debian' it { is_expected.to contain_apt__key('zabbix-FBABD5F') } if facts[:os]['family'] == 'Debian' end diff --git a/spec/classes/proxy_spec.rb b/spec/classes/proxy_spec.rb index 711d8e354..293baac09 100644 --- a/spec/classes/proxy_spec.rb +++ b/spec/classes/proxy_spec.rb @@ -7,13 +7,19 @@ 'rspec.puppet.com' end - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| + next if %w[Archlinux FreeBSD AIX Gentoo].include?(facts[:os]['family']) # zabbix proxy is currently not supported next if facts[:os]['name'] == 'windows' context "on #{os}" do let :facts do facts end + let :params do + { + zabbix_server_host: '192.168.1.1', + } + end zabbix_version = if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' '5.0' @@ -21,431 +27,417 @@ '6.0' end - case facts[:os]['family'] - when 'Archlinux' - context 'with all defaults' do - it { is_expected.not_to compile } - end - else + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf.d').with_ensure('directory') } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf.d').with_require('File[/etc/zabbix/zabbix_proxy.conf]') } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('zabbix::params') } + it { is_expected.to contain_exec('zabbix_create.sql') } + it { is_expected.to contain_postgresql__server__pg_hba_rule('Allow zabbix-proxy to access database') } + + describe 'when manage_repo is true and zabbix version is unset' do let :params do { - zabbix_server_host: '192.168.1.1', + manage_repo: true } end - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf.d').with_ensure('directory') } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf.d').with_require('File[/etc/zabbix/zabbix_proxy.conf]') } - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_class('zabbix::params') } - it { is_expected.to contain_exec('zabbix_create.sql') } - it { is_expected.to contain_postgresql__server__pg_hba_rule('Allow zabbix-proxy to access database') } + it { is_expected.to contain_class('zabbix::repo').with_zabbix_version(zabbix_version) } + it { is_expected.to contain_package('zabbix-proxy-pgsql').with_require('Class[Zabbix::Repo]') } - describe 'when manage_repo is true and zabbix version is unset' do - let :params do - { - manage_repo: true - } - end + case facts[:os]['family'] + when 'RedHat' + it { is_expected.to contain_yumrepo('zabbix-nonsupported') } + it { is_expected.to contain_yumrepo('zabbix') } + when 'Debian' + it { is_expected.to contain_apt__source('zabbix') } + end + end - it { is_expected.to contain_class('zabbix::repo').with_zabbix_version(zabbix_version) } - it { is_expected.to contain_package('zabbix-proxy-pgsql').with_require('Class[Zabbix::Repo]') } + describe 'with enabled selinux', if: facts[:os]['family'] == 'RedHat' do + let :facts do + super().merge(selinux: true) + end - case facts[:os]['family'] - when 'RedHat' - it { is_expected.to contain_yumrepo('zabbix-nonsupported') } - it { is_expected.to contain_yumrepo('zabbix') } - when 'Debian' - it { is_expected.to contain_apt__source('zabbix') } - end + it { is_expected.to contain_selboolean('zabbix_can_network').with('value' => 'on', 'persistent' => true) } + end + + describe 'when database_type is postgresql' do + let :params do + { + database_type: 'postgresql' + } end - describe 'with enabled selinux', if: facts[:os]['family'] == 'RedHat' do - let :facts do - super().merge(selinux: true) - end + it { is_expected.to contain_package('zabbix-proxy-pgsql').with_ensure('present') } + it { is_expected.to contain_package('zabbix-proxy-pgsql').with_name('zabbix-proxy-pgsql') } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_require('Package[zabbix-proxy-pgsql]') } + end - it { is_expected.to contain_selboolean('zabbix_can_network').with('value' => 'on', 'persistent' => true) } + describe 'when database_type is mysql' do + let :params do + { + database_type: 'mysql' + } end - describe 'when database_type is postgresql' do - let :params do - { - database_type: 'postgresql' - } - end + it { is_expected.to contain_package('zabbix-proxy-mysql').with_ensure('present') } + it { is_expected.to contain_package('zabbix-proxy-mysql').with_name('zabbix-proxy-mysql') } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_require('Package[zabbix-proxy-mysql]') } + end - it { is_expected.to contain_package('zabbix-proxy-pgsql').with_ensure('present') } - it { is_expected.to contain_package('zabbix-proxy-pgsql').with_name('zabbix-proxy-pgsql') } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_require('Package[zabbix-proxy-pgsql]') } + describe 'when manage_resources is true' do + let :params do + { + manage_resources: true, + listenip: '192.168.1.1' + } end - describe 'when database_type is mysql' do - let :params do - { - database_type: 'mysql' - } - end + it { is_expected.to contain_class('zabbix::resources::proxy') } + it { is_expected.to contain_zabbix__userparameters('Zabbix_Proxy') } + end - it { is_expected.to contain_package('zabbix-proxy-mysql').with_ensure('present') } - it { is_expected.to contain_package('zabbix-proxy-mysql').with_name('zabbix-proxy-mysql') } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_require('Package[zabbix-proxy-mysql]') } + context 'with zabbix::database::postgresql class' do + let :params do + { + database_type: 'postgresql', + manage_database: true + } end - describe 'when manage_resources is true' do - let :params do - { - manage_resources: true, - listenip: '192.168.1.1' - } - end + it { is_expected.to contain_class('zabbix::database::postgresql').with_zabbix_type('proxy') } + it { is_expected.to contain_class('zabbix::database::postgresql').with_zabbix_version(zabbix_version) } + it { is_expected.to contain_class('zabbix::database::postgresql').with_database_name('zabbix_proxy') } + it { is_expected.to contain_class('zabbix::database::postgresql').with_database_user('zabbix-proxy') } + it { is_expected.to contain_class('zabbix::database::postgresql').with_database_password('zabbix-proxy') } + it { is_expected.to contain_class('zabbix::database::postgresql').with_database_host('localhost') } + end - it { is_expected.to contain_class('zabbix::resources::proxy') } - it { is_expected.to contain_zabbix__userparameters('Zabbix_Proxy') } + context 'with zabbix::database::mysql class' do + let(:params) do + { + database_type: 'mysql', + manage_database: true + } end - context 'with zabbix::database::postgresql class' do - let :params do - { - database_type: 'postgresql', - manage_database: true - } - end + it { is_expected.to contain_class('zabbix::database::mysql').with_zabbix_type('proxy') } + it { is_expected.to contain_class('zabbix::database::mysql').with_zabbix_version(zabbix_version) } + it { is_expected.to contain_class('zabbix::database::mysql').with_database_name('zabbix_proxy') } + it { is_expected.to contain_class('zabbix::database::mysql').with_database_user('zabbix-proxy') } + it { is_expected.to contain_class('zabbix::database::mysql').with_database_password('zabbix-proxy') } + it { is_expected.to contain_class('zabbix::database::mysql').with_database_host('localhost') } + it { is_expected.to contain_mysql__db('zabbix_proxy') } + end - it { is_expected.to contain_class('zabbix::database::postgresql').with_zabbix_type('proxy') } - it { is_expected.to contain_class('zabbix::database::postgresql').with_zabbix_version(zabbix_version) } - it { is_expected.to contain_class('zabbix::database::postgresql').with_database_name('zabbix_proxy') } - it { is_expected.to contain_class('zabbix::database::postgresql').with_database_user('zabbix-proxy') } - it { is_expected.to contain_class('zabbix::database::postgresql').with_database_password('zabbix-proxy') } - it { is_expected.to contain_class('zabbix::database::postgresql').with_database_host('localhost') } + context 'when manage_database is true' do + let(:params) do + { + manage_database: true + } end - context 'with zabbix::database::mysql class' do - let(:params) do - { - database_type: 'mysql', - manage_database: true - } - end + it { is_expected.to contain_class('zabbix::database').with_zabbix_type('proxy') } + it { is_expected.to contain_class('zabbix::database').with_database_type('postgresql') } + it { is_expected.to contain_class('zabbix::database').with_database_name('zabbix_proxy') } + it { is_expected.to contain_class('zabbix::database').with_database_user('zabbix-proxy') } + it { is_expected.to contain_class('zabbix::database').with_database_password('zabbix-proxy') } + it { is_expected.to contain_class('zabbix::database').with_database_host('localhost') } + it { is_expected.to contain_class('zabbix::database').with_zabbix_proxy('localhost') } + it { is_expected.to contain_class('zabbix::database').with_zabbix_proxy_ip('127.0.0.1') } + end - it { is_expected.to contain_class('zabbix::database::mysql').with_zabbix_type('proxy') } - it { is_expected.to contain_class('zabbix::database::mysql').with_zabbix_version(zabbix_version) } - it { is_expected.to contain_class('zabbix::database::mysql').with_database_name('zabbix_proxy') } - it { is_expected.to contain_class('zabbix::database::mysql').with_database_user('zabbix-proxy') } - it { is_expected.to contain_class('zabbix::database::mysql').with_database_password('zabbix-proxy') } - it { is_expected.to contain_class('zabbix::database::mysql').with_database_host('localhost') } - it { is_expected.to contain_mysql__db('zabbix_proxy') } + context 'when declaring manage_firewall is true' do + let(:params) do + { + manage_firewall: true + } end - context 'when manage_database is true' do - let(:params) do - { - manage_database: true - } - end + it { is_expected.to contain_firewall('151 zabbix-proxy') } + end - it { is_expected.to contain_class('zabbix::database').with_zabbix_type('proxy') } - it { is_expected.to contain_class('zabbix::database').with_database_type('postgresql') } - it { is_expected.to contain_class('zabbix::database').with_database_name('zabbix_proxy') } - it { is_expected.to contain_class('zabbix::database').with_database_user('zabbix-proxy') } - it { is_expected.to contain_class('zabbix::database').with_database_password('zabbix-proxy') } - it { is_expected.to contain_class('zabbix::database').with_database_host('localhost') } - it { is_expected.to contain_class('zabbix::database').with_zabbix_proxy('localhost') } - it { is_expected.to contain_class('zabbix::database').with_zabbix_proxy_ip('127.0.0.1') } + context 'when declaring manage_firewall is false' do + let(:params) do + { + manage_firewall: false + } end - context 'when declaring manage_firewall is true' do - let(:params) do - { - manage_firewall: true - } - end + it { is_expected.not_to contain_firewall('151 zabbix-proxy') } + end - it { is_expected.to contain_firewall('151 zabbix-proxy') } + # If manage_service is true (default), it should create a service + # and ensure that it is running. + context 'when declaring manage_service is true' do + let :params do + { + manage_service: true + } end - context 'when declaring manage_firewall is false' do - let(:params) do - { - manage_firewall: false - } - end + it { is_expected.to contain_service('zabbix-proxy').with_ensure('running') } + it { is_expected.to contain_service('zabbix-proxy').with_enable('true') } + it { is_expected.to contain_service('zabbix-proxy').with_require(['Package[zabbix-proxy-pgsql]', 'File[/etc/zabbix/zabbix_proxy.conf.d]', 'File[/etc/zabbix/zabbix_proxy.conf]', 'Class[Zabbix::Database]']) } + end - it { is_expected.not_to contain_firewall('151 zabbix-proxy') } + # When the manage_service is false, it may not make the service. + context 'when declaring manage_service is false' do + let :params do + { + manage_service: false + } end - # If manage_service is true (default), it should create a service - # and ensure that it is running. - context 'when declaring manage_service is true' do - let :params do - { - manage_service: true - } - end + it { is_expected.not_to contain_service('zabbix-proxy') } + end - it { is_expected.to contain_service('zabbix-proxy').with_ensure('running') } - it { is_expected.to contain_service('zabbix-proxy').with_enable('true') } - it { is_expected.to contain_service('zabbix-proxy').with_require(['Package[zabbix-proxy-pgsql]', 'File[/etc/zabbix/zabbix_proxy.conf.d]', 'File[/etc/zabbix/zabbix_proxy.conf]', 'Class[Zabbix::Database]']) } + # Make sure we have set some vars in zabbix_proxy.conf file. This is configuration file is the same on all + # operating systems. So we aren't testing this for all opeating systems, just this one. + context 'with zabbix_proxy.conf settings' do + let(:params) do + { + allowroot: '0', + cachesize: '32M', + configfrequency: '3600', + database_host: 'localhost', + database_name: 'zabbix-proxy', + database_password: 'zabbix-proxy', + database_schema: 'zabbix-proxy', + database_user: 'zabbix-proxy', + database_tlsconnect: 'verify_ca', + database_tlscafile: '/etc/zabbix/ssl/ca.cert', + database_tlscertfile: '/etc/zabbix/ssl/cert.cert', + database_tlskeyfile: '/etc/zabbix/ssl/key.key', + database_tlscipher: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256', + database_tlscipher13: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256', + datasenderfrequency: '1', + debuglevel: '4', + externalscripts: '/usr/lib/zabbix/externalscripts', + fping6location: '/usr/sbin/fping6', + fpinglocation: '60', + heartbeatfrequency: '60', + historycachesize: '16M', + historytextcachesize: '8M', + hostname: 'rspec.puppet.com', + housekeepingfrequency: '1', + include_dir: '/etc/zabbix/zabbix_proxy.conf.d', + javagateway: '192.168.1.2', + javagatewayport: '10051', + startjavapollers: '5', + listenip: '192.168.1.1', + listenport: '10051', + loadmodulepath: '${libdir}/modules', + loadmodule: 'pizza', + localbuffer: '0', + logfilesize: '15', + logfile: '/var/log/zabbix/proxy_server.log', + logtype: 'file', + logslowqueries: '0', + mode: '0', + offlinebuffer: '1', + pidfile: '/var/run/zabbix/proxy_server.pid', + snmptrapper: '0', + snmptrapperfile: '/tmp/zabbix_traps.tmp', + sshkeylocation: '/home/zabbix/.ssh/', + sslcertlocation_dir: '/usr/lib/zabbix/ssl/certs', + sslkeylocation_dir: '/usr/lib/zabbix/ssl/keys', + sslcalocation_dir: '/usr/lib/zabbix/ssl/certs', + startdbsyncers: '4', + startdiscoverers: '15', + starthttppollers: '15', + startipmipollers: '15', + startpingers: '15', + startpollers: '15', + startpollersunreachable: '15', + startpreprocessors: 10, + starttrappers: '15', + startvmwarecollectors: '0', + timeout: '20', + tmpdir: '/tmp', + trappertimeout: '16', + unavaliabledelay: '60', + unreachabedelay: '15', + unreachableperiod: '45', + vmwarecachesize: '8M', + vmwarefrequency: '60', + zabbix_server_host: '192.168.1.1', + zabbix_server_port: '10051', + zabbix_version: '5.0', + tlsciphercert: 'EECDH+aRSA+AES128:RSA+aRSA+AES128', + tlsciphercert13: 'EECDH+aRSA+AES128:RSA+aRSA+AES128', + tlscipherpsk: 'kECDHEPSK+AES128:kPSK+AES128', + tlscipherpsk13: 'TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256', + tlscipherall: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256', + tlscipherall13: 'EECDH+aRSA+AES128:RSA+aRSA+AES128:kECDHEPSK+AES128:kPSK+AES128' + } end - # When the manage_service is false, it may not make the service. - context 'when declaring manage_service is false' do - let :params do - { - manage_service: false - } - end + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ProxyMode=0$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^Server=192.168.1.1$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ServerPort=10051$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^Hostname=rspec.puppet.com$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ListenPort=10051$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogFile=/var/log/zabbix/proxy_server.log$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogFileSize=15$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogType=file$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DebugLevel=4$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^PidFile=/var/run/zabbix/proxy_server.pid$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBHost=localhost$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBName=zabbix-proxy$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBSchema=zabbix-proxy$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBUser=zabbix-proxy$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBPassword=zabbix-proxy$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSConnect=verify_ca} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSCAFile=/etc/zabbix/ssl/ca.cert} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSCertFile=/etc/zabbix/ssl/cert.cert} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSKeyFile=/etc/zabbix/ssl/key.key} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSCipher=TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSCipher13=TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ProxyLocalBuffer=0$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ProxyOfflineBuffer=1$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^HeartbeatFrequency=60$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ConfigFrequency=3600$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DataSenderFrequency=1$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartPollers=15$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartIPMIPollers=15$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartPreprocessors=10$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartPollersUnreachable=15$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartTrappers=15$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartPingers=15$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartDiscoverers=15$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartHTTPPollers=15$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^JavaGateway=192.168.1.2$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^JavaGatewayPort=10051$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartJavaPollers=5$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartVMwareCollectors=0$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^VMwareFrequency=60$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^VMwareCacheSize=8M$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SNMPTrapperFile=/tmp/zabbix_traps.tmp$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartSNMPTrapper=0$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ListenIP=192.168.1.1$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^HousekeepingFrequency=1$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^CacheSize=32M$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartDBSyncers=4$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^HistoryCacheSize=16M$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^Timeout=20$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TrapperTimeout=16$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^UnreachablePeriod=45$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^UnavailableDelay=60$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^UnreachableDelay=15$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ExternalScripts=/usr/lib/zabbix/externalscripts$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^FpingLocation=60$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^Fping6Location=/usr/sbin/fping6$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SSHKeyLocation=/home/zabbix/.ssh/$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogSlowQueries=0$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TmpDir=/tmp$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^AllowRoot=0$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^Include=/etc/zabbix/zabbix_proxy.conf.d$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SSLCertLocation=/usr/lib/zabbix/ssl/certs} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SSLKeyLocation=/usr/lib/zabbix/ssl/keys} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SSLCALocation=/usr/lib/zabbix/ssl/certs} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LoadModule=pizza$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherCert=EECDH\+aRSA\+AES128:RSA\+aRSA\+AES128$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherCert13=EECDH\+aRSA\+AES128:RSA\+aRSA\+AES128$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherPSK=kECDHEPSK\+AES128:kPSK\+AES128$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherPSK13=TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherAll=TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherAll13=EECDH\+aRSA\+AES128:RSA\+aRSA\+AES128:kECDHEPSK\+AES128:kPSK\+AES128$} } + end - it { is_expected.not_to contain_service('zabbix-proxy') } + context 'with zabbix_proxy.conf and version 5.0' do + let :params do + { + socketdir: '/var/run/zabbix', + startodbcpollers: 1, + zabbix_version: '5.0' + } end - # Make sure we have set some vars in zabbix_proxy.conf file. This is configuration file is the same on all - # operating systems. So we aren't testing this for all opeating systems, just this one. - context 'with zabbix_proxy.conf settings' do - let(:params) do - { - allowroot: '0', - cachesize: '32M', - configfrequency: '3600', - database_host: 'localhost', - database_name: 'zabbix-proxy', - database_password: 'zabbix-proxy', - database_schema: 'zabbix-proxy', - database_user: 'zabbix-proxy', - database_tlsconnect: 'verify_ca', - database_tlscafile: '/etc/zabbix/ssl/ca.cert', - database_tlscertfile: '/etc/zabbix/ssl/cert.cert', - database_tlskeyfile: '/etc/zabbix/ssl/key.key', - database_tlscipher: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256', - database_tlscipher13: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256', - datasenderfrequency: '1', - debuglevel: '4', - externalscripts: '/usr/lib/zabbix/externalscripts', - fping6location: '/usr/sbin/fping6', - fpinglocation: '60', - heartbeatfrequency: '60', - historycachesize: '16M', - historytextcachesize: '8M', - hostname: 'rspec.puppet.com', - housekeepingfrequency: '1', - include_dir: '/etc/zabbix/zabbix_proxy.conf.d', - javagateway: '192.168.1.2', - javagatewayport: '10051', - startjavapollers: '5', - listenip: '192.168.1.1', - listenport: '10051', - loadmodulepath: '${libdir}/modules', - loadmodule: 'pizza', - localbuffer: '0', - logfilesize: '15', - logfile: '/var/log/zabbix/proxy_server.log', - logtype: 'file', - logslowqueries: '0', - mode: '0', - offlinebuffer: '1', - pidfile: '/var/run/zabbix/proxy_server.pid', - snmptrapper: '0', - snmptrapperfile: '/tmp/zabbix_traps.tmp', - sshkeylocation: '/home/zabbix/.ssh/', - sslcertlocation_dir: '/usr/lib/zabbix/ssl/certs', - sslkeylocation_dir: '/usr/lib/zabbix/ssl/keys', - sslcalocation_dir: '/usr/lib/zabbix/ssl/certs', - startdbsyncers: '4', - startdiscoverers: '15', - starthttppollers: '15', - startipmipollers: '15', - startpingers: '15', - startpollers: '15', - startpollersunreachable: '15', - startpreprocessors: 10, - starttrappers: '15', - startvmwarecollectors: '0', - timeout: '20', - tmpdir: '/tmp', - trappertimeout: '16', - unavaliabledelay: '60', - unreachabedelay: '15', - unreachableperiod: '45', - vmwarecachesize: '8M', - vmwarefrequency: '60', - zabbix_server_host: '192.168.1.1', - zabbix_server_port: '10051', - zabbix_version: '5.0', - tlsciphercert: 'EECDH+aRSA+AES128:RSA+aRSA+AES128', - tlsciphercert13: 'EECDH+aRSA+AES128:RSA+aRSA+AES128', - tlscipherpsk: 'kECDHEPSK+AES128:kPSK+AES128', - tlscipherpsk13: 'TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256', - tlscipherall: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256', - tlscipherall13: 'EECDH+aRSA+AES128:RSA+aRSA+AES128:kECDHEPSK+AES128:kPSK+AES128' - } - end + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SocketDir=/var/run/zabbix} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').without_content %r{^StartODBCPollers=1$} } + end - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ProxyMode=0$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^Server=192.168.1.1$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ServerPort=10051$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^Hostname=rspec.puppet.com$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ListenPort=10051$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogFile=/var/log/zabbix/proxy_server.log$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogFileSize=15$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogType=file$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DebugLevel=4$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^PidFile=/var/run/zabbix/proxy_server.pid$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBHost=localhost$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBName=zabbix-proxy$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBSchema=zabbix-proxy$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBUser=zabbix-proxy$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBPassword=zabbix-proxy$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSConnect=verify_ca} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSCAFile=/etc/zabbix/ssl/ca.cert} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSCertFile=/etc/zabbix/ssl/cert.cert} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSKeyFile=/etc/zabbix/ssl/key.key} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSCipher=TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DBTLSCipher13=TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ProxyLocalBuffer=0$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ProxyOfflineBuffer=1$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^HeartbeatFrequency=60$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ConfigFrequency=3600$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^DataSenderFrequency=1$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartPollers=15$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartIPMIPollers=15$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartPreprocessors=10$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartPollersUnreachable=15$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartTrappers=15$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartPingers=15$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartDiscoverers=15$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartHTTPPollers=15$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^JavaGateway=192.168.1.2$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^JavaGatewayPort=10051$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartJavaPollers=5$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartVMwareCollectors=0$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^VMwareFrequency=60$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^VMwareCacheSize=8M$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SNMPTrapperFile=/tmp/zabbix_traps.tmp$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartSNMPTrapper=0$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ListenIP=192.168.1.1$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^HousekeepingFrequency=1$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^CacheSize=32M$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartDBSyncers=4$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^HistoryCacheSize=16M$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^Timeout=20$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TrapperTimeout=16$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^UnreachablePeriod=45$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^UnavailableDelay=60$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^UnreachableDelay=15$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^ExternalScripts=/usr/lib/zabbix/externalscripts$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^FpingLocation=60$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^Fping6Location=/usr/sbin/fping6$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SSHKeyLocation=/home/zabbix/.ssh/$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogSlowQueries=0$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TmpDir=/tmp$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^AllowRoot=0$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^Include=/etc/zabbix/zabbix_proxy.conf.d$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SSLCertLocation=/usr/lib/zabbix/ssl/certs} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SSLKeyLocation=/usr/lib/zabbix/ssl/keys} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SSLCALocation=/usr/lib/zabbix/ssl/certs} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LoadModulePath=\$\{libdir\}/modules$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LoadModule=pizza$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherCert=EECDH\+aRSA\+AES128:RSA\+aRSA\+AES128$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherCert13=EECDH\+aRSA\+AES128:RSA\+aRSA\+AES128$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherPSK=kECDHEPSK\+AES128:kPSK\+AES128$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherPSK13=TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherAll=TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSCipherAll13=EECDH\+aRSA\+AES128:RSA\+aRSA\+AES128:kECDHEPSK\+AES128:kPSK\+AES128$} } + context 'with zabbix_proxy.conf and version 6.0' do + let :params do + { + socketdir: '/var/run/zabbix', + startodbcpollers: 1, + zabbix_version: '6.0' + } end - context 'with zabbix_proxy.conf and version 5.0' do + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SocketDir=/var/run/zabbix} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartODBCPollers=1$} } + end + + context 'with zabbix_proxy.conf and logtype declared' do + describe 'as system' do let :params do { - socketdir: '/var/run/zabbix', - startodbcpollers: 1, - zabbix_version: '5.0' + logtype: 'system' } end - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SocketDir=/var/run/zabbix} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').without_content %r{^StartODBCPollers=1$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogType=system$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').without_content %r{^LogFile=} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').without_content %r{^LogFileSize=} } end - context 'with zabbix_proxy.conf and version 6.0' do + describe 'as console' do let :params do { - socketdir: '/var/run/zabbix', - startodbcpollers: 1, - zabbix_version: '6.0' + logtype: 'console' } end - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^SocketDir=/var/run/zabbix} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^StartODBCPollers=1$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogType=console$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').without_content %r{^LogFile=} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').without_content %r{^LogFileSize=} } end - context 'with zabbix_proxy.conf and logtype declared' do - describe 'as system' do - let :params do - { - logtype: 'system' - } - end - - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogType=system$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').without_content %r{^LogFile=} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').without_content %r{^LogFileSize=} } - end - - describe 'as console' do - let :params do - { - logtype: 'console' - } - end - - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogType=console$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').without_content %r{^LogFile=} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').without_content %r{^LogFileSize=} } - end - - describe 'as file' do - let :params do - { - logtype: 'file' - } - end - - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogType=file$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_proxy.log$} } - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogFileSize=10$} } - end - end - - context 'tlsaccept with one string value' do + describe 'as file' do let :params do { - tlsaccept: 'cert' + logtype: 'file' } end - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSAccept=cert$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogType=file$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogFile=/var/log/zabbix/zabbix_proxy.log$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^LogFileSize=10$} } end + end - context 'tlsaccept with one value array' do - let :params do - { - tlsaccept: %w[cert] - } - end + context 'tlsaccept with one string value' do + let :params do + { + tlsaccept: 'cert' + } + end - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSAccept=cert$} } + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSAccept=cert$} } + end + + context 'tlsaccept with one value array' do + let :params do + { + tlsaccept: %w[cert] + } end - context 'tlsaccept with two value array' do - let :params do - { - tlsaccept: %w[unencrypted cert] - } - end + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSAccept=cert$} } + end - it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSAccept=unencrypted,cert$} } + context 'tlsaccept with two value array' do + let :params do + { + tlsaccept: %w[unencrypted cert] + } end + it { is_expected.to contain_file('/etc/zabbix/zabbix_proxy.conf').with_content %r{^TLSAccept=unencrypted,cert$} } end end end diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb index 8bbd91694..1ff31bf89 100644 --- a/spec/classes/repo_spec.rb +++ b/spec/classes/repo_spec.rb @@ -4,18 +4,18 @@ require 'spec_helper' describe 'zabbix::repo' do - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end case facts[:os]['family'] - when 'Archlinux' - next + when 'Archlinux', 'FreeBSD', 'Gentoo', 'AIX' + # rubocop:disable RSpec/RepeatedExample + it { is_expected.to compile.with_all_deps } when 'Debian' - # rubocop:disable RSpec/RepeatedExample it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('zabbix::params') } it { is_expected.to contain_class('zabbix::repo') } diff --git a/spec/classes/sender_spec.rb b/spec/classes/sender_spec.rb index b9917d98e..47f96393a 100644 --- a/spec/classes/sender_spec.rb +++ b/spec/classes/sender_spec.rb @@ -7,7 +7,7 @@ 'agent.example.com' end - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| next if facts[:os]['name'] == 'windows' context "on #{os}" do @@ -37,7 +37,7 @@ } end - if %w[Archlinux Gentoo].include?(facts[:os]['family']) + if %w[Archlinux Gentoo FreeBSD].include?(facts[:os]['family']) it { is_expected.not_to compile.with_all_deps } else it { is_expected.to contain_class('zabbix::repo').with_zabbix_version(zabbix_version) } @@ -50,7 +50,7 @@ it { is_expected.to contain_yumrepo('zabbix') } it { is_expected.to contain_yumrepo('zabbix-frontend') } if facts[:os]['release']['major'] == '7' - it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['release']['major'] == '7' + it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['release']['major'] == '7' && %w[OracleLinux CentOS].include?(facts[:os]['name']) when 'Debian' it { is_expected.to contain_apt__source('zabbix') } it { is_expected.to contain_apt__key('zabbix-A1848F5') } diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 0d343037a..910819ef6 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -8,8 +8,8 @@ 'rspec.puppet.com' end - on_supported_os(baseline_os_hash).each do |os, facts| - next if facts[:os]['family'] == 'Archlinux' # zabbix server is currently not supported on archlinux + on_supported_os.each do |os, facts| + next if %w[Archlinux FreeBSD AIX Gentoo].include?(facts[:os]['family']) # zabbix server is currently not supported next if facts[:os]['name'] == 'windows' context "on #{os}" do @@ -54,7 +54,7 @@ it { is_expected.to contain_yumrepo('zabbix') } it { is_expected.to contain_yumrepo('zabbix-frontend') } if facts[:os]['release']['major'] == '7' - it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['release']['major'] == '7' + it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['release']['major'] == '7' && %w[OracleLinux CentOS].include?(facts[:os]['name']) end end diff --git a/spec/classes/userparameter_spec.rb b/spec/classes/userparameter_spec.rb index 5d2ddb78e..4de5e5ddb 100644 --- a/spec/classes/userparameter_spec.rb +++ b/spec/classes/userparameter_spec.rb @@ -7,7 +7,7 @@ 'agent.example.com' end - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts diff --git a/spec/classes/web_spec.rb b/spec/classes/web_spec.rb index 6fee84aff..5864765ef 100644 --- a/spec/classes/web_spec.rb +++ b/spec/classes/web_spec.rb @@ -24,11 +24,10 @@ class { 'apache': PUPPET end - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| supported_versions.each do |zabbix_version| next if facts[:os]['name'] == 'windows' - next if facts[:os]['name'] == 'Archlinux' - next if facts[:os]['name'] == 'Gentoo' + next if %w[Archlinux Gentoo FreeBSD].include?(facts[:os]['family']) context "on #{os}" do let :facts do @@ -47,7 +46,7 @@ class { 'apache': it { is_expected.to contain_yumrepo('zabbix') } if facts[:os]['family'] == 'RedHat' it { is_expected.to contain_yumrepo('zabbix-nonsupported') } if facts[:os]['family'] == 'RedHat' it { is_expected.to contain_yumrepo('zabbix-frontend') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' - it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' + it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' && %w[OracleLinux CentOS].include?(facts[:os]['name']) it { is_expected.to contain_service('rh-php72-php-fpm') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' it { is_expected.to contain_file('/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' it { is_expected.to contain_file('/etc/zabbix/zabbix.conf.php') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' @@ -90,8 +89,7 @@ class { 'apache': pgsqlpackage = 'php-pgsql' packages = if facts[:os]['family'] == 'RedHat' - if facts[:os]['release']['major'].to_i == 7 && - !%w[OracleLinux].include?(facts[:os]['name']) + if facts[:os]['release']['major'].to_i == 7 %w[zabbix-web-pgsql-scl zabbix-web] else %w[zabbix-web-pgsql zabbix-web] diff --git a/spec/defines/userparameters_spec.rb b/spec/defines/userparameters_spec.rb index a49949a4e..c7583a65f 100644 --- a/spec/defines/userparameters_spec.rb +++ b/spec/defines/userparameters_spec.rb @@ -3,16 +3,30 @@ require 'spec_helper' describe 'zabbix::userparameters', type: :define do - on_supported_os(baseline_os_hash).each do |os, facts| + on_supported_os.each do |os, facts| next if facts[:os]['name'] == 'windows' context "on #{os}" do let(:facts) { facts } let(:title) { 'mysqld' } - let(:pre_condition) { 'class { "zabbix::agent": include_dir => "/etc/zabbix/zabbix_agentd.d" }' } + let(:pre_condition) do + 'class { "zabbix::agent": + include_dir => "/etc/zabbix/zabbix_agentd.d", + agent_configfile_path => "/etc/zabbix/zabbix_agentd.conf" + }' + end - package = facts[:os]['family'] == 'Gentoo' ? 'zabbix' : 'zabbix-agent' - service = facts[:os]['family'] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent' + case facts[:os]['family'] + when 'Gentoo' + package_name = 'zabbix' + service_name = 'zabbix-agentd' + when 'FreeBSD' + package_name = 'zabbix6-agent' + service_name = 'zabbix_agentd' + else + package_name = 'zabbix-agent' + service_name = 'zabbix-agent' + end context 'with an content' do let(:params) { { content: 'UserParameter=mysql.ping,mysqladmin -uroot ping | grep -c alive' } } @@ -22,12 +36,12 @@ it { is_expected.to contain_class('zabbix::params') } it { is_expected.to contain_class('zabbix::repo') } it { is_expected.to compile.with_all_deps } - it { is_expected.not_to contain_file("/etc/init.d/#{service}") } + it { is_expected.not_to contain_file("/etc/init.d/#{service_name}") } it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf') } it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.d') } - it { is_expected.to contain_package(package) } - it { is_expected.to contain_service(service) } - it { is_expected.not_to contain_zabbix__startup(service) } + it { is_expected.to contain_package(package_name) } + it { is_expected.to contain_service(service_name) } + it { is_expected.not_to contain_zabbix__startup(service_name) } end context 'with ensure => absent' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0aec83fe7..8361eb93b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,5 +24,4 @@ require 'support/acceptance/supported_versions' -require 'spec_helper_methods' Dir['./spec/support/spec/**/*.rb'].sort.each { |f| require f } diff --git a/spec/spec_helper_methods.rb b/spec/spec_helper_methods.rb deleted file mode 100644 index 30ad7aaa8..000000000 --- a/spec/spec_helper_methods.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -def baseline_os_hash - { - supported_os: [ - { - 'operatingsystem' => 'CentOS', - 'operatingsystemrelease' => %w[7] - }, - { - 'operatingsystem' => 'Debian', - 'operatingsystemrelease' => %w[11 12] - }, - { - 'operatingsystem' => 'Ubuntu', - 'operatingsystemrelease' => %w[20.04 22.04] - }, - { - 'operatingsystem' => 'Archlinux', - }, - # TODO: Support and tests for Gentoo need to be fixed - # { - # 'operatingsystem' => 'Gentoo', - # }, - { - 'operatingsystem' => 'windows', - 'operatingsystemrelease' => %w[2016 2019] - }, - ] - } -end