Skip to content

Commit 29042e9

Browse files
authored
Merge pull request #711 from ekohl/clean-zabbix-agent
Reduce configuration on agent service
2 parents 4dea0bc + 73e6da0 commit 29042e9

File tree

2 files changed

+28
-37
lines changed

2 files changed

+28
-37
lines changed

manifests/agent.pp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -432,24 +432,19 @@
432432
}
433433

434434
# Controlling the 'zabbix-agent' service
435-
if str2bool(getvar('::systemd')) {
436-
$service_provider = 'systemd'
437-
$service_path = undef
438-
} elsif $facts['os']['name'] == 'AIX' {
439-
$service_provider = 'init'
440-
$service_path = '/etc/rc.d/init.d'
441-
} else {
442-
$service_provider = undef
443-
$service_path = undef
444-
}
445435
service { $servicename:
446-
ensure => $service_ensure,
447-
enable => $service_enable,
448-
path => $service_path,
449-
provider => $service_provider,
450-
hasstatus => true,
451-
hasrestart => true,
452-
require => Package[$zabbix_package_agent],
436+
ensure => $service_ensure,
437+
enable => $service_enable,
438+
require => Package[$zabbix_package_agent],
439+
}
440+
441+
# Override the service provider on AIX
442+
# Doing it this way allows overriding it on other platforms
443+
if $facts['os']['name'] == 'AIX' {
444+
Service[$servicename] {
445+
service_provider => 'init',
446+
service_path => '/etc/rc.d/init.d',
447+
}
453448
}
454449

455450
# Configuring the zabbix-agent configuration file

spec/classes/agent_spec.rb

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,21 @@
6868
end
6969
else
7070
it do
71-
is_expected.to contain_package(package_name).with(
72-
ensure: 'present',
73-
require: 'Class[Zabbix::Repo]',
74-
tag: 'zabbix'
75-
)
71+
is_expected.to contain_package(package_name).
72+
with_ensure('present').
73+
with_tag('zabbix').
74+
that_requires('Class[zabbix::repo]')
7675
end
7776
it do
78-
is_expected.to contain_service(service_name).with(
79-
ensure: 'running',
80-
enable: true,
81-
hasstatus: true,
82-
hasrestart: true,
83-
require: "Package[#{package_name}]"
84-
)
77+
is_expected.to contain_service(service_name).
78+
with_ensure('running').
79+
with_enable(true).
80+
with_service_provider(facts[:osfamily] == 'AIX' ? 'init' : nil).
81+
that_requires("Package[#{package_name}]")
8582
end
8683

8784
it { is_expected.to contain_file(include_dir).with_ensure('directory') }
88-
it { is_expected.to contain_zabbix__startup(service_name).with(require: "Package[#{package_name}]") }
85+
it { is_expected.to contain_zabbix__startup(service_name).that_requires("Package[#{package_name}]") }
8986
it { is_expected.to compile.with_all_deps }
9087
it { is_expected.to contain_class('zabbix::params') }
9188
end
@@ -104,11 +101,11 @@
104101
when 'Debian'
105102
# rubocop:disable RSpec/RepeatedExample
106103
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version(zabbix_version) }
107-
it { is_expected.to contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') }
104+
it { is_expected.to contain_package('zabbix-agent').that_requires('Class[Zabbix::Repo]') }
108105
it { is_expected.to contain_apt__source('zabbix') }
109106
when 'RedHat'
110107
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version(zabbix_version) }
111-
it { is_expected.to contain_package('zabbix-agent').with_require('Class[Zabbix::Repo]') }
108+
it { is_expected.to contain_package('zabbix-agent').that_requires('Class[Zabbix::Repo]') }
112109
it { is_expected.to contain_yumrepo('zabbix-nonsupported') }
113110
it { is_expected.to contain_yumrepo('zabbix') }
114111
# rubocop:enable RSpec/RepeatedExample
@@ -347,11 +344,10 @@
347344
end
348345

349346
it do
350-
is_expected.to contain_service(service_name).with(
351-
ensure: 'stopped',
352-
enable: false,
353-
require: "Package[#{package_name}]"
354-
)
347+
is_expected.to contain_service(service_name).
348+
with_ensure('stopped').
349+
with_enable(false).
350+
that_requires("Package[#{package_name}]")
355351
end
356352
end
357353
end

0 commit comments

Comments
 (0)