Skip to content

Commit

Permalink
Merge pull request #965 from Valantin/fix/unitfile
Browse files Browse the repository at this point in the history
Change `manage_startup_script` default to false
  • Loading branch information
bastelfreak committed Jun 28, 2024
2 parents 55b827c + 8b071c2 commit 24dabc3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 46 deletions.
13 changes: 7 additions & 6 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -118,6 +124,7 @@
$server_zabbix_user = 'zabbix'
$zabbix_package_provider = undef
$agent_loadmodulepath = '/usr/lib/modules'
$manage_startup_script = false
}
}

Expand All @@ -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'
Expand Down
51 changes: 29 additions & 22 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 16 additions & 16 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/defines/userparameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 24dabc3

Please sign in to comment.