Skip to content

Commit

Permalink
Run acceptance tests for all supported versions
Browse files Browse the repository at this point in the history
Signed-off-by: Christos Papageorgiou <[email protected]>
  • Loading branch information
root-expert committed Mar 6, 2021
1 parent 79d6d6d commit bdb2c26
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 315 deletions.
8 changes: 8 additions & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,14 @@
Boolean $manage_startup_script = $zabbix::params::manage_startup_script,
Optional[Stdlib::Absolutepath] $socketdir = $zabbix::params::server_socketdir,
) inherits zabbix::params {
# zabbix server 5.2 is not supported on RHEL 7.
# https://www.zabbix.com/documentation/current/manual/installation/install_from_packages/rhel_centos
if $facts['os']['family'] == 'RedHat' and versioncmp($zabbix_version, '5.2') == 0 {
if versioncmp($facts['os']['release']['major'], '7') == 0 {
fail("${facts['os']['family']} ${$facts['os']['release']['major']} is not supported for zabbix::server (yet)")
}
}

# the following codeblock is a bit blargh. The correct default value for
# $real_additional_service_params changes based on the value of $zabbix_version
# We handle this in the params.pp, but that doesn't work if somebody provides a specific
Expand Down
8 changes: 4 additions & 4 deletions manifests/web.pp
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@
'2.4': {
$zabbixapi_version = '2.4.4'
}
'3.2' : {
'3.2': {
$zabbixapi_version = '3.2.1'
}
'3.4' : {
'3.4': {
$zabbixapi_version = '4.0.0'
}
/^4\.[02]$/: {
$zabbixapi_version = '4.1.2'
'4.0': {
$zabbixapi_version = '4.2.0'
}
'4.4': {
$zabbixapi_version = '4.2.0'
Expand Down
120 changes: 66 additions & 54 deletions spec/acceptance/zabbix_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,81 @@

# rubocop:disable RSpec/LetBeforeExamples
describe 'zabbix_application type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9|debian-10)-amd64} do
context 'create zabbix_application resources' do
# This will deploy a running Zabbix setup (server, web, db) which we can
# use for custom type tests
pp1 = <<-EOS
$compile_packages = $facts['os']['family'] ? {
'RedHat' => [ 'make', 'gcc-c++', ],
'Debian' => [ 'make', 'g++', ],
default => [],
}
ensure_packages($compile_packages, { before => Package['zabbixapi'], })
class { 'apache':
mpm_module => 'prefork',
}
include apache::mod::php
include postgresql::server
%w[4.0 5.0 5.2].each do |zabbix_version|
# 5.2 server packages are not available for RHEL 7
next if zabbix_version == '5.2' and default[:platform] == 'el-7-x86_64'

class { 'zabbix':
zabbix_version => '5.0',
zabbix_url => 'localhost',
zabbix_api_user => 'Admin',
zabbix_api_pass => 'zabbix',
apache_use_ssl => false,
manage_resources => true,
require => [ Class['postgresql::server'], Class['apache'], ],
}
template = case zabbix_version
when '4.0'
'Template OS Linux'
else
'Template OS Linux by Zabbix agent'
end

EOS
context "create zabbix_application 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
pp1 = <<-EOS
$compile_packages = $facts['os']['family'] ? {
'RedHat' => [ 'make', 'gcc-c++', ],
'Debian' => [ 'make', 'g++', ],
default => [],
}
ensure_packages($compile_packages, { before => Package['zabbixapi'], })
class { 'apache':
mpm_module => 'prefork',
}
include apache::mod::php
include postgresql::server
pp2 = <<-EOS
zabbix_application { 'TestApplication1':
template => 'Template OS Linux by Zabbix agent',
}
EOS
# setup zabbix. Apache module isn't idempotent and requires a second run
it 'works with no error on the first apply' do
# Cleanup old database
prepare_host
class { 'zabbix':
zabbix_version => "#{zabbix_version}",
zabbix_url => 'localhost',
zabbix_api_user => 'Admin',
zabbix_api_pass => 'zabbix',
apache_use_ssl => false,
manage_resources => true,
require => [ Class['postgresql::server'], Class['apache'], ],
}
apply_manifest(pp1, catch_failures: true)
end
it 'works with no error on the second apply' do
apply_manifest(pp1, catch_failures: true)
end
EOS

# configure the applications within zabbix
it 'works with no error on the third apply' do
apply_manifest(pp2, catch_failures: true)
end
it 'works without changes on the fourth apply' do
apply_manifest(pp2, catch_changes: true)
pp2 = <<-EOS
zabbix_application { 'TestApplication1':
template => "#{template}",
}
EOS
# setup zabbix. Apache module isn't idempotent and requires a second run
it 'works with no error on the first apply' do
# Cleanup old database
prepare_host

apply_manifest(pp1, catch_failures: true)
end
it 'works with no error on the second apply' do
apply_manifest(pp1, catch_failures: true)
end

# configure the applications within zabbix
it 'works with no error on the third apply' do
apply_manifest(pp2, catch_failures: true)
end
it 'works without changes on the fourth apply' do
apply_manifest(pp2, catch_changes: true)
end
end
end

let(:result_templates) do
zabbixapi('localhost', 'Admin', 'zabbix', 'template.get', selectApplications: ['name'],
output: ['host']).result
end
let(:result_templates) do
zabbixapi('localhost', 'Admin', 'zabbix', 'template.get', selectApplications: ['name'],
output: ['host']).result
end

context 'TestApplication1' do
let(:template1) { result_templates.select { |t| t['host'] == 'Template OS Linux by Zabbix agent' }.first }
context 'TestApplication1' do
let(:template1) { result_templates.select { |t| t['host'] == template }.first }

it 'is attached to Template OS Linux by Zabbix agent' do
expect(template1['applications'].map { |a| a['name'] }).to include('TestApplication1')
it "is attached to #{template}" do
expect(template1['applications'].map { |a| a['name'] }).to include('TestApplication1')
end
end
end
end
Loading

0 comments on commit bdb2c26

Please sign in to comment.