Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide acceptance tests for zabbix server #392

Merged
merged 6 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions files/zabbix-server.te
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module zabbix-server 1.0;

require {
type zabbix_t;
class process setrlimit;
}

#============= zabbix_t ==============
allow zabbix_t self:process setrlimit;
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
$loadmodule = $zabbix::params::server_loadmodule,
Boolean $manage_selinux = $zabbix::params::manage_selinux,
String $additional_service_params = $zabbix::params::additional_service_params,
Optional[String[1]] $zabbix_user = $zabbix::params::server_zabbix_user,
) inherits zabbix::params {

class { '::zabbix::web':
Expand Down
4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
$agent_zabbix_user = 'zabbix'
$agent_config_group = 'zabbix'
$agent_pidfile = '/var/run/zabbix/zabbix_agentd.pid'
$server_zabbix_user = 'zabbix'
}
'Archlinux': {
$server_fpinglocation = '/usr/bin/fping'
Expand All @@ -38,6 +39,7 @@
$agent_zabbix_user = 'zabbix-agent'
$agent_config_group = 'zabbix-agent'
$agent_pidfile = undef
$server_zabbix_user = 'zabbix-server'
}
'Fedora': {
$server_fpinglocation = '/usr/sbin/fping'
Expand All @@ -51,6 +53,7 @@
$agent_zabbix_user = 'zabbix'
$agent_config_group = 'zabbix'
$agent_pidfile = '/var/run/zabbix/zabbix_agentd.pid'
$server_zabbix_user = 'zabbix'
}
default : {
$server_fpinglocation = '/usr/sbin/fping'
Expand All @@ -64,6 +67,7 @@
$agent_zabbix_user = 'zabbix'
$agent_config_group = 'zabbix'
$agent_pidfile = '/var/run/zabbix/zabbix_agentd.pid'
$server_zabbix_user = 'zabbix'
}
}

Expand Down
17 changes: 10 additions & 7 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@
$sslkeylocation_dir = $zabbix::params::server_sslkeylocation,
Boolean $manage_selinux = $zabbix::params::manage_selinux,
String $additional_service_params = $zabbix::params::additional_service_params,
Optional[String[1]] $zabbix_user = $zabbix::params::server_zabbix_user,
) inherits zabbix::params {

# the following codeblock is a bit blargh. The correct default value for
Expand Down Expand Up @@ -457,7 +458,9 @@
pidfile => $pidfile,
database_type => $database_type,
server_configfile_path => $server_configfile_path,
zabbix_user => $zabbix_user,
additional_service_params => $real_additional_service_params,
manage_database => $manage_database,
require => Package["zabbix-server-${db}"],
}

Expand All @@ -468,13 +471,6 @@
}
}

# Workaround for: The redhat provider can not handle attribute enable
# This is only happening when using an redhat family version 5.x.
if $::osfamily == 'redhat' and $::operatingsystemrelease !~ /^5.*/ and $manage_service {
Service[$server_service_name] {
enable => true }
}

# Controlling the 'zabbix-server' service
if $pacemaker {
exec { 'prevent zabbix boot-start':
Expand Down Expand Up @@ -509,6 +505,7 @@
if $manage_service {
service { $server_service_name:
ensure => running,
enable => true,
hasstatus => true,
hasrestart => true,
require => [
Expand Down Expand Up @@ -558,6 +555,12 @@
selboolean{'zabbix_can_network':
persistent => true,
value => 'on',
notify => Service[$server_service_name],
}
-> selinux::module{'zabbix-server':
ensure => 'present',
source_te => 'puppet:///modules/zabbix/zabbix-server.te',
before => Service[$server_service_name],
}
}
}
4 changes: 4 additions & 0 deletions manifests/startup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Optional[String] $zabbix_user = undef,
String $additional_service_params = '',
String $service_type = 'simple',
Optional[Boolean] $manage_database = undef,
) {

case $title {
Expand All @@ -34,6 +35,9 @@
unless $database_type {
fail('you have to provide a database_type param')
}
unless $manage_database {
fail('you have to provide a manage_database param')
}
}
default: {
fail('we currently only spport a title that contains agent or server')
Expand Down
38 changes: 38 additions & 0 deletions spec/acceptance/server_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper_acceptance'

describe 'zabbix::server class' do
context 'default parameters' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
# this is a minimal working example if you've a postgres server
# running on another node. multinode testing with beaker is pain,
# so we will deploy multiple services into one box
# pp = <<-EOS
# class { 'zabbix::server':
# manage_database => false,
# }
# EOS

# this will actually deploy apache + postgres + zabbix-server + zabbix-web
pp = <<-EOS
class { 'postgresql::server': } ->
class { 'zabbix::database': } ->
class { 'zabbix::server': }
EOS

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

# do some basic checks
describe package('zabbix-server-pgsql') do
it { is_expected.to be_installed }
end

describe service('zabbix-server') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end
end
end
21 changes: 9 additions & 12 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
end

on_supported_os.each do |os, facts|
next if facts[:osfamily] == 'Archlinux' # zabbix server is currently not supported on archlinux
context "on #{os} " do
systemd_fact = case facts[:osfamily]
when 'Archlinux'
{ systemd: true }
else
{ systemd: false }
end
let :facts do
facts.merge(systemd_fact)
facts
end

describe 'with default settings' do
Expand All @@ -23,12 +18,14 @@
it { is_expected.to contain_zabbix__startup('zabbix-server') }
end

describe 'with enabled selinux' do
let :facts do
super().merge(selinux: true)
end
if facts[:osfamily] == 'RedHat'
describe 'with enabled selinux' do
let :facts do
super().merge(selinux: true)
end

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

describe 'with disabled selinux' do
Expand Down
13 changes: 8 additions & 5 deletions spec/defines/startup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
let :params do
{
server_configfile_path: '/something',
database_type: 'mysql'
database_type: 'mysql',
manage_database: true
}
end

Expand Down Expand Up @@ -159,7 +160,8 @@
server_configfile_path: '/something',
pidfile: '/somethingelse',
database_type: 'mysql',
additional_service_params: '--foreground'
additional_service_params: '--foreground',
manage_database: true
}
end

Expand All @@ -173,18 +175,19 @@
end
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{ExecStart=/usr/sbin/zabbix_server --foreground -c /something}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{PIDFile=/somethingelse}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=syslog.target network.target mysqld.service}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=mysqld.service}) }

context 'and works on postgres' do
let :params do
{
server_configfile_path: '/something',
pidfile: '/somethingelse',
database_type: 'postgres'
database_type: 'postgresql',
manage_database: true
}
end

it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=syslog.target network.target postgresql.service}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=postgresql.service}) }
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
RSpec.configure do |c|
# Readable test descriptions
c.formatter = :documentation
hosts.each do |host|
if host[:platform] =~ %r{el-7-x86_64} && host[:hypervisor] =~ %r{docker}
on(host, "sed -i '/nodocs/d' /etc/yum.conf")
end
end
end
9 changes: 5 additions & 4 deletions templates/zabbix-server-systemd.init.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[Unit]
Description=Zabbix Server
Documentation=man:zabbix_server
<% if @database_type == "mysql" %>
After=syslog.target network.target mysqld.service
<% else %>
After=syslog.target network.target postgresql.service
<% if @database_type == "mysql" and @manage_database %>
After=mysqld.service
<% elsif @database_type == "postgresql" and @manage_database %>
After=postgresql.service
<% end -%>

[Service]
Expand All @@ -16,6 +16,7 @@ PrivateDevices=yes
PrivateTmp=yes
ProtectSystem=full
ProtectHome=yes
<% if @zabbix_user %>User=<%= @zabbix_user %><% end %>

[Install]
WantedBy=multi-user.target