Skip to content

Commit

Permalink
Merge 96905c5 into bd6c597
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Apr 21, 2020
2 parents bd6c597 + 96905c5 commit 0e948cb
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 60 deletions.
1 change: 1 addition & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- set: 'ubuntu1604-64{image=ubuntu:xenial-20191212}'
- set: 'centos7-64{image=centos:7.6.1810}'
- set: debian9-64
- set: debian10-64
secure: "ijm7hKPYWr1eg7151g5oK6MzZL4ojrgWjKlxgoBHXAdXdY88opMgvixfSJK5IMUbtanPfWRkqqABx+MYO78nfQBWDlghUzZ8sQXFeO2Ie0PgWl4nFV0kKWz+ejVaZC4dKSZlWha5pO1ek+sx7KnjIBZY82OXs/GXbjwhHx6d56YugXLuCyvfFxC7mXC9wF58bPwcYRCBSZt9CRl0OMBAFybxjdwsFMloRRhdz7f3hhlqF8Nrs1sxG1HhgiMcnrZqovNfb3Tw9K1RPYATazXxQrjcI7YHvJx0AvtHFUsn+/A0GtpKUuuPbaVdkYgE1Tye0AsAcey6RW4xhJywZglKrzDk7vfyUiU5CObeLh4/dhub3k111rDPL8v6v9t40fteduJoFLziHotQwdl37UALL7PwWZY5HuJvaBqHY2LsGs/ptGMB9ZCzxA85jfDw8lrZQ7P97SAoC34Ihs8D6vkKT9HUKHIXh19O5AAa70jReru0ej179IBjvs8m9nDwDNdY3sIsdhUU8WQ3BftDF6M8OzvgyLKDvjSs1Izag+Asl2Ze7RAQfQ2RvbfkDm9KEFnDQtXtzF4Cu1Ed6io2j1zI71JFQpIf6zb1qeNrhqulbJ15owGkQmHBgD8K+bDd1CCU4kA26axypV00XDsjfwdtFHgtUO3AlUVUim0QTMk9ATc="
Gemfile:
optional:
Expand Down
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ matrix:
bundler_args: --without development release
env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian9-64 BEAKER_HYPERVISOR=docker CHECK=beaker
services: docker
- rvm: 2.5.3
bundler_args: --without development release
env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=debian10-64 BEAKER_HYPERVISOR=docker CHECK=beaker
services: docker
- rvm: 2.5.3
bundler_args: --without development release
env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian10-64 BEAKER_HYPERVISOR=docker CHECK=beaker
services: docker
branches:
only:
- master
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ group :test do
gem 'fakefs', '0.13.3', :require => false if RUBY_VERSION < '2.3.0'
gem 'fakefs', :require => false if RUBY_VERSION >= '2.3.0'
gem 'zabbixapi', :require => false
gem 'rspec-puppet-facts', :require => false, :git => 'https://github.com/ekohl/rspec-puppet-facts', :ref => '7674437d8d48af3a910ac3858c9eb63853dc1821'
end

group :development do
Expand Down
10 changes: 6 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@
}
}

# Zabbix overall params. Is used by all components.
$zabbix_version = downcase($facts['kernel']) ? {
'windows' => '4.4.5',
default => '3.4',
if downcase($facts['kernel']) == 'windows' {
$zabbix_version = '4.4.5'
} elsif $facts['os']['name'] == 'Debian' and Integer($facts['os']['release']['major']) == 10 {
$zabbix_version = '4.0'
} else {
$zabbix_version = '3.4'
}

$manage_startup_script = downcase($facts['kernel']) ? {
Expand Down
3 changes: 2 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
{
"operatingsystem": "Debian",
"operatingsystemrelease": [
"9"
"9",
"10"
]
},
{
Expand Down
87 changes: 49 additions & 38 deletions spec/acceptance/agent_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require 'spec_helper_acceptance'

def agent_supported(version)
if default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64}
return version != '2.4'
end
return version != '2.4' if default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64}
return version >= '4.0' if default[:platform] =~ %r{debian-10-amd64}
true
end

Expand All @@ -14,7 +13,7 @@ def agent_supported(version)
class { 'zabbix::agent':
server => '192.168.20.11',
zabbix_package_state => 'latest',
zabbix_version => '#{version}'
zabbix_version => '#{version}',
}
EOS

Expand All @@ -36,42 +35,54 @@ class { 'zabbix::agent':
describe file('/etc/zabbix/zabbix_agentd.conf') do
its(:content) { is_expected.not_to match %r{ListenIP=} }
end
end
end

describe 'zabbix::agent class with zabbix_version 3.4' do
context 'With ListenIP set to an IP-Address' do
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'zabbix::agent':
server => '192.168.20.11',
zabbix_package_state => 'latest',
listenip => '127.0.0.1',
zabbix_version => '3.4'
}
EOS
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
describe file('/etc/zabbix/zabbix_agentd.conf') do
its(:content) { is_expected.to match %r{ListenIP=127.0.0.1} }
context 'With ListenIP set to an IP-Address' do
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'zabbix::agent':
server => '192.168.20.11',
zabbix_package_state => 'latest',
listenip => '127.0.0.1',
zabbix_version => '#{version}',
}
EOS
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
describe file('/etc/zabbix/zabbix_agentd.conf') do
its(:content) { is_expected.to match %r{ListenIP=127.0.0.1} }
end
end
end
context 'With ListenIP set to lo' do
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'zabbix::agent':
server => '192.168.20.11',
zabbix_package_state => 'latest',
listenip => 'lo',
zabbix_version => '3.4'
}
EOS
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
describe file('/etc/zabbix/zabbix_agentd.conf') do
its(:content) { is_expected.to match %r{ListenIP=127.0.0.1} }
context 'With ListenIP set to lo' do
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'zabbix::agent':
server => '192.168.20.11',
zabbix_package_state => 'latest',
listenip => 'lo',
zabbix_version => '#{version}',
}
EOS
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
context 'With ListenIP set to an IP-Address' do
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'zabbix::agent':
server => '192.168.20.11',
zabbix_package_state => 'latest',
listenip => '127.0.0.1',
zabbix_version => '#{version}',
}
EOS
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
describe file('/etc/zabbix/zabbix_agentd.conf') do
its(:content) { is_expected.to match %r{ListenIP=127.0.0.1} }
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/acceptance/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class { 'zabbix::database': } ->
class { 'zabbix::server': }
EOS

shell('yum clean metadata') if fact('os.family') == 'RedHat'
shell('rm -rf /etc/yum.repos.d/Zabbix*.repo; yum clean all') if fact('os.family') == 'RedHat'

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
Expand Down
4 changes: 3 additions & 1 deletion spec/acceptance/zabbix_application_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper_acceptance'
require 'serverspec_type_zabbixapi'

describe 'zabbix_application type' do
describe 'zabbix_application type', unless: default[:platform] =~ %r{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
Expand Down Expand Up @@ -37,6 +37,8 @@ class { 'zabbix':
EOS
# setup zabbix. Apache module isn't idempotent and requires a second run
it 'works with no error on the first apply' do
shell('yum clean all') if fact('os.family') == 'RedHat'

# Cleanup old database
cleanup_zabbix

Expand Down
4 changes: 3 additions & 1 deletion spec/acceptance/zabbix_host_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper_acceptance'
require 'serverspec_type_zabbixapi'

describe 'zabbix_host type' do
describe 'zabbix_host type', unless: default[:platform] =~ %r{debian-10-amd64} do
context 'create zabbix_host resources' do
# This will deploy a running Zabbix setup (server, web, db) which we can
# use for custom type tests
Expand Down Expand Up @@ -30,6 +30,8 @@ class { 'zabbix':
EOS
# setup zabbix. Apache module isn't idempotent and requires a second run
it 'works with no error on the first apply' do
shell('yum clean all') if fact('os.family') == 'RedHat'

# Cleanup old database
cleanup_zabbix

Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/zabbix_hostgroup_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper_acceptance'
require 'serverspec_type_zabbixapi'

describe 'zabbix_hostgroup type' do
describe 'zabbix_hostgroup type', unless: default[:platform] =~ %r{debian-10-amd64} do
context 'create zabbix_hostgroup resources' do
it 'runs successfully' do
# This will deploy a running Zabbix setup (server, web, db) which we can
Expand Down Expand Up @@ -33,7 +33,7 @@ class { 'zabbix':
}
EOS

shell('yum clean metadata') if fact('os.family') == 'RedHat'
shell('yum clean all') if fact('os.family') == 'RedHat'

# Cleanup old database
cleanup_zabbix
Expand Down
3 changes: 2 additions & 1 deletion spec/acceptance/zabbix_proxy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper_acceptance'
require 'serverspec_type_zabbixapi'

describe 'zabbix_proxy type' do
describe 'zabbix_proxy type', unless: default[:platform] =~ %r{debian-10-amd64} do
context 'create zabbix_proxy resources' do
# This will deploy a running Zabbix setup (server, web, db) which we can
# use for custom type tests
Expand Down Expand Up @@ -29,6 +29,7 @@ class { 'zabbix':
}
EOS

shell('yum clean all') if fact('os.family') == 'RedHat'
# Cleanup old database
cleanup_zabbix

Expand Down
6 changes: 4 additions & 2 deletions spec/acceptance/zabbix_template_host_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper_acceptance'
require 'serverspec_type_zabbixapi'

describe 'zabbix_template_host type' do
describe 'zabbix_template_host type', unless: default[:platform] =~ %r{debian-10-amd64} do
context 'create zabbix_template_host resources' do
it 'runs successfully' do
# This will deploy a running Zabbix setup (server, web, db) which we can
Expand Down Expand Up @@ -43,9 +43,11 @@ class { 'zabbix':
}
EOS

shell('yum clean metadata') if fact('os.family') == 'RedHat'
shell('yum clean all') if fact('os.family') == 'RedHat'
shell("echo '<?xml version=\"1.0\" encoding=\"UTF-8\"?><zabbix_export><version>3.0</version><date>2018-12-13T15:00:46Z</date><groups><group><name>Templates/Applications</name></group></groups><templates><template><template>TestTemplate1</template><name>TestTemplate1</name><description/><groups><group><name>Templates/Applications</name></group></groups><applications/><items/><discovery_rules/><macros/><templates/><screens/></template></templates></zabbix_export>' > /root/TestTemplate1.xml")

shell('yum clean all') if fact('os.family') == 'RedHat'

# Cleanup old database
cleanup_zabbix

Expand Down
6 changes: 4 additions & 2 deletions spec/acceptance/zabbix_template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper_acceptance'
require 'serverspec_type_zabbixapi'

describe 'zabbix_template type' do
describe 'zabbix_template type', unless: default[:platform] =~ %r{debian-10-amd64} do
context 'create zabbix_template resources' do
it 'runs successfully' do
# This will deploy a running Zabbix setup (server, web, db) which we can
Expand Down Expand Up @@ -29,9 +29,11 @@ class { 'zabbix':
}
EOS

shell('yum clean metadata') if fact('os.family') == 'RedHat'
shell('yum clean all') if fact('os.family') == 'RedHat'
shell("echo '<?xml version=\"1.0\" encoding=\"UTF-8\"?><zabbix_export><version>3.0</version><date>2018-12-13T15:00:46Z</date><groups><group><name>Templates/Applications</name></group></groups><templates><template><template>TestTemplate1</template><name>TestTemplate1</name><description/><groups><group><name>Templates/Applications</name></group></groups><applications/><items/><discovery_rules/><macros/><templates/><screens/></template></templates></zabbix_export>' > /root/TestTemplate1.xml")

shell('yum clean all') if fact('os.family') == 'RedHat'

# Cleanup old database
cleanup_zabbix

Expand Down
9 changes: 7 additions & 2 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
else
'/etc/zabbix/zabbix_agentd.d'
end
zabbix_version = if facts[:os]['name'] == 'Debian' && facts[:os]['release']['major'].to_i == 10
'4.0'
else
'3.4'
end
let :facts do
facts.merge(systemd_fact)
end
Expand Down Expand Up @@ -98,11 +103,11 @@
it { is_expected.not_to compile.with_all_deps }
when 'Debian'
# rubocop:disable RSpec/RepeatedExample
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version('3.4') }
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version(zabbix_version) }
it { is_expected.to contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') }
it { is_expected.to contain_apt__source('zabbix') }
when 'RedHat'
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version('3.4') }
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version(zabbix_version) }
it { is_expected.to contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') }
it { is_expected.to contain_yumrepo('zabbix-nonsupported') }
it { is_expected.to contain_yumrepo('zabbix') }
Expand Down
18 changes: 17 additions & 1 deletion spec/classes/sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

context 'with all defaults' do
it { is_expected.to contain_class('zabbix::sender') }
it { is_expected.to contain_class('zabbix::params') }
it { is_expected.to compile.with_all_deps }
# Make sure package will be installed, service running and ensure of directory.
it { is_expected.to contain_package('zabbix-sender').with_ensure('present') }
Expand All @@ -29,9 +30,24 @@
if %w[Archlinux Gentoo].include?(facts[:osfamily])
it { is_expected.not_to compile.with_all_deps }
else
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version('3.4') }
zabbix_version = if facts[:os]['name'] == 'Debian' && facts[:os]['release']['major'].to_i == 10
'4.0'
else
'3.4'
end
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version(zabbix_version) }
it { is_expected.to contain_package('zabbix-sender').with_require('Class[Zabbix::Repo]') }
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') }
it { is_expected.to contain_apt__key('zabbix-A1848F5') }
it { is_expected.to contain_apt__key('zabbix-FBABD5F') }
end
end
end
end
Expand Down
16 changes: 14 additions & 2 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@
facts.merge(systemd_fact)
end

zabbix_version = if facts[:os]['name'] == 'Debian' && facts[:os]['release']['major'].to_i == 10
'4.0'
else
'3.4'
end

describe 'with default settings' do
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') }
end
Expand All @@ -40,6 +47,11 @@

it { is_expected.to contain_selboolean('zabbix_can_network').with('value' => 'on', 'persistent' => true) }
end

describe 'with defaults' do
it { is_expected.to contain_yumrepo('zabbix-nonsupported') }
it { is_expected.to contain_yumrepo('zabbix') }
end
end

describe 'with disabled selinux' do
Expand Down Expand Up @@ -94,7 +106,7 @@
end

it { is_expected.to contain_class('zabbix::database::postgresql').with_zabbix_type('server') }
it { is_expected.to contain_class('zabbix::database::postgresql').with_zabbix_version('3.4') }
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-server') }
it { is_expected.to contain_class('zabbix::database::postgresql').with_database_user('zabbix-server') }
it { is_expected.to contain_class('zabbix::database::postgresql').with_database_password('zabbix-server') }
Expand All @@ -113,7 +125,7 @@
end

it { is_expected.to contain_class('zabbix::database::mysql').with_zabbix_type('server') }
it { is_expected.to contain_class('zabbix::database::mysql').with_zabbix_version('3.4') }
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-server') }
it { is_expected.to contain_class('zabbix::database::mysql').with_database_user('zabbix-server') }
it { is_expected.to contain_class('zabbix::database::mysql').with_database_password('zabbix-server') }
Expand Down

0 comments on commit 0e948cb

Please sign in to comment.