Skip to content

Commit 24dabc3

Browse files
authored
Merge pull request #965 from Valantin/fix/unitfile
Change `manage_startup_script` default to false
2 parents 55b827c + 8b071c2 commit 24dabc3

File tree

4 files changed

+54
-46
lines changed

4 files changed

+54
-46
lines changed

manifests/params.pp

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
$server_zabbix_user = 'zabbix'
2121
$zabbix_package_provider = undef
2222
$agent_loadmodulepath = '/usr/lib/modules'
23+
$manage_startup_script = false
2324
}
2425
'AIX': {
2526
$manage_repo = false
@@ -32,6 +33,7 @@
3233
$agent_config_group = 'zabbix'
3334
$agent_pidfile = '/var/run/zabbix/zabbix_agentd.pid'
3435
$agent_servicename = 'zabbix-agent'
36+
$manage_startup_script = true
3537
}
3638
'Archlinux': {
3739
$server_fpinglocation = '/usr/bin/fping'
@@ -51,6 +53,7 @@
5153
$server_zabbix_user = 'zabbix-server'
5254
$zabbix_package_provider = undef
5355
$agent_loadmodulepath = '/usr/lib/modules'
56+
$manage_startup_script = false
5457
}
5558
'FreeBSD': {
5659
$manage_repo = false
@@ -66,6 +69,7 @@
6669
$server_zabbix_user = 'zabbix'
6770
$zabbix_package_provider = undef
6871
$agent_loadmodulepath = '/usr/local/lib/zabbix/modules'
72+
$manage_startup_script = false
6973
}
7074
'Gentoo': {
7175
$server_fpinglocation = '/usr/sbin/fping'
@@ -85,6 +89,7 @@
8589
$server_zabbix_user = 'zabbix'
8690
$zabbix_package_provider = undef
8791
$agent_loadmodulepath = '/usr/lib/modules'
92+
$manage_startup_script = false
8893
}
8994
'windows': {
9095
$manage_repo = false
@@ -99,6 +104,7 @@
99104
$agent_servicename = 'Zabbix Agent'
100105
$agent_include = 'C:/ProgramData/zabbix/zabbix_agentd.d'
101106
$agent_loadmodulepath = undef
107+
$manage_startup_script = false
102108
}
103109
default : {
104110
$server_fpinglocation = '/usr/sbin/fping'
@@ -118,6 +124,7 @@
118124
$server_zabbix_user = 'zabbix'
119125
$zabbix_package_provider = undef
120126
$agent_loadmodulepath = '/usr/lib/modules'
127+
$manage_startup_script = false
121128
}
122129
}
123130

@@ -129,12 +136,6 @@
129136
$zabbix_version = '6.0'
130137
}
131138

132-
$manage_startup_script = downcase($facts['kernel']) ? {
133-
'windows' => false,
134-
'FreeBSD' => false,
135-
default => true,
136-
}
137-
138139
$zabbix_package_state = 'present'
139140
$zabbix_proxy = 'localhost'
140141
$zabbix_proxy_ip = '127.0.0.1'

spec/classes/agent_spec.rb

+29-22
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@
8686
is_expected.to contain_service(service_name).
8787
with_ensure('running').
8888
with_enable(true).
89-
with_service_provider(facts[:os]['family'] == 'AIX' ? 'init' : nil).
90-
that_requires(["Package[#{package_name}]", "Zabbix::Startup[#{service_name}]"])
89+
with_service_provider(facts[:os]['family'] == 'AIX' ? 'init' : nil)
9190
end
9291

93-
it { is_expected.to contain_zabbix__startup(service_name).that_requires("Package[#{package_name}]") }
92+
it { is_expected.not_to contain_zabbix__startup(service_name) }
9493
it { is_expected.to compile.with_all_deps }
9594
it { is_expected.to contain_class('zabbix::params') }
9695
end
@@ -218,29 +217,37 @@
218217
it { is_expected.not_to contain_firewall('150 zabbix-agent from 10.11.12.13') }
219218
end
220219

221-
context 'it creates a startup script' do
222-
if facts[:kernel] == 'Linux'
223-
case facts[:os]['family']
224-
when 'Archlinux', 'Debian', 'Gentoo', 'RedHat'
225-
it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('absent') }
226-
it { is_expected.to contain_file("/etc/systemd/system/#{service_name}.service").with_ensure('file') }
227-
when 'windows'
228-
it { is_expected.to contain_exec("install_agent_#{service_name}") }
229-
else
230-
it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('file') }
231-
it { is_expected.not_to contain_file("/etc/systemd/system/#{service_name}.service") }
232-
end
233-
end
234-
end
235-
236-
context 'when declaring manage_startup_script is false' do
220+
context 'when declaring manage_startup_script is true' do
237221
let :params do
238222
{
239-
manage_startup_script: false
223+
manage_startup_script: true
240224
}
241225
end
242226

243-
it { is_expected.not_to contain_zabbix__startup(service_name) }
227+
context 'it creates a startup script' do
228+
if facts[:kernel] == 'Linux'
229+
case facts[:os]['family']
230+
when 'Archlinux', 'Debian', 'Gentoo', 'RedHat'
231+
it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('absent') }
232+
it { is_expected.to contain_file("/etc/systemd/system/#{service_name}.service").with_ensure('file') }
233+
when 'windows'
234+
it { is_expected.to contain_exec("install_agent_#{service_name}") }
235+
else
236+
it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('file') }
237+
it { is_expected.not_to contain_file("/etc/systemd/system/#{service_name}.service") }
238+
end
239+
end
240+
end
241+
242+
it do
243+
is_expected.to contain_service(service_name).
244+
with_ensure('running').
245+
with_enable(true).
246+
with_service_provider(facts[:os]['family'] == 'AIX' ? 'init' : nil).
247+
that_requires(["Package[#{package_name}]", "Zabbix::Startup[#{service_name}]"])
248+
end
249+
250+
it { is_expected.to contain_zabbix__startup(service_name).that_requires("Package[#{package_name}]") }
244251
end
245252

246253
context 'when declaring zabbix_alias' do
@@ -460,7 +467,7 @@
460467
end
461468
end
462469

463-
describe 'with systemd active' do
470+
describe 'with systemd active', skip: 'user package provided instead systemd::unit_file ' do
464471
if facts[:kernel] == 'Linux'
465472
let :facts do
466473
super().merge(systemd: true)

spec/classes/server_spec.rb

+16-16
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
it { is_expected.to contain_class('zabbix::repo') }
2626
it { is_expected.to contain_class('zabbix::params') }
2727
it { is_expected.to contain_service('zabbix-server').with_ensure('running') }
28-
it { is_expected.to contain_zabbix__startup('zabbix-server') }
28+
it { is_expected.not_to contain_zabbix__startup('zabbix-server') }
2929

3030
it { is_expected.to contain_apt__source('zabbix') } if facts[:os]['family'] == 'Debian'
3131
it { is_expected.to contain_apt__key('zabbix-A1848F5') } if facts[:os]['family'] == 'Debian'
@@ -159,26 +159,26 @@
159159
it { is_expected.not_to contain_firewall('151 zabbix-server') }
160160
end
161161

162-
context 'it creates a startup script' do
163-
case facts[:os]['family']
164-
when 'Archlinux', 'Debian', 'Gentoo', 'RedHat'
165-
it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('absent') }
166-
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_ensure('file') }
167-
it { is_expected.to contain_systemd__unit_file('zabbix-server.service') }
168-
else
169-
it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('file') }
170-
it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-server.service') }
171-
end
172-
end
173-
174-
context 'when declaring manage_startup_script is false' do
162+
context 'when declaring manage_startup_script is true' do
175163
let :params do
176164
{
177-
manage_startup_script: false
165+
manage_startup_script: true
178166
}
179167
end
180168

181-
it { is_expected.not_to contain_zabbix__startup('zabbix-server') }
169+
context 'it creates a startup script' do
170+
case facts[:os]['family']
171+
when 'Archlinux', 'Debian', 'Gentoo', 'RedHat'
172+
it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('absent') }
173+
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_ensure('file') }
174+
it { is_expected.to contain_systemd__unit_file('zabbix-server.service') }
175+
else
176+
it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('file') }
177+
it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-server.service') }
178+
end
179+
end
180+
181+
it { is_expected.to contain_zabbix__startup('zabbix-server') }
182182
end
183183

184184
# If manage_service is true (default), it should create a service

spec/defines/userparameters_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
it { is_expected.to contain_class('zabbix::params') }
2323
it { is_expected.to contain_class('zabbix::repo') }
2424
it { is_expected.to compile.with_all_deps }
25-
it { is_expected.to contain_file("/etc/init.d/#{service}") }
25+
it { is_expected.not_to contain_file("/etc/init.d/#{service}") }
2626
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf') }
2727
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.d') }
2828
it { is_expected.to contain_package(package) }
2929
it { is_expected.to contain_service(service) }
30-
it { is_expected.to contain_zabbix__startup(service) }
30+
it { is_expected.not_to contain_zabbix__startup(service) }
3131
end
3232

3333
context 'with ensure => absent' do

0 commit comments

Comments
 (0)