Skip to content

Commit dec8c50

Browse files
committed
Fix rspec tests for Gentoo
Due to the release of facterdb 0.6.0 we're now testing against Gentoo as well. This leads to a couple of errors which this commit fixes. Strict variable checking was disabled until puppetlabs/puppetlabs-mysql#1147 got merged.
1 parent 1a8808e commit dec8c50

File tree

8 files changed

+59
-34
lines changed

8 files changed

+59
-34
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ matrix:
1212
include:
1313
- rvm: 2.1.9
1414
bundler_args: --without system_tests development release
15-
env: PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=12
15+
env: STRICT_VARIABLES=no PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=12
1616
- rvm: 2.4.4
1717
bundler_args: --without system_tests development release
18-
env: PUPPET_VERSION="~> 5.0" CHECK=test
18+
env: STRICT_VARIABLES=no PUPPET_VERSION="~> 5.0" CHECK=test
1919
- rvm: 2.5.1
2020
bundler_args: --without system_tests development release
21-
env: PUPPET_VERSION="~> 6.0" CHECK=test_with_coveralls
21+
env: STRICT_VARIABLES=no PUPPET_VERSION="~> 6.0" CHECK=test_with_coveralls
2222
- rvm: 2.5.1
2323
bundler_args: --without system_tests development release
2424
env: PUPPET_VERSION="~> 6.0" CHECK=rubocop

manifests/web.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@
234234
) inherits zabbix::params {
235235

236236
# check osfamily, Arch is currently not supported for web
237-
if $facts['os']['family'] == 'Archlinux' {
238-
fail('Archlinux is currently not supported for zabbix::web ')
237+
if $facts['os']['family'] in [ 'Archlinux', 'Gentoo', ] {
238+
fail('Gentoo is currently not supported for zabbix::web ')
239239
}
240240

241241
# Only include the repo class if it has not yet been included

spec/classes/agent_spec.rb

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
on_supported_os.each do |os, facts|
1616
context "on #{os} " do
1717
systemd_fact = case facts[:osfamily]
18-
when 'Archlinux', 'Fedora'
18+
when 'Archlinux', 'Fedora', 'Gentoo'
1919
{ systemd: true }
2020
else
2121
{ systemd: false }
@@ -29,30 +29,38 @@
2929
let :facts do
3030
facts.merge(systemd_fact)
3131
end
32+
if facts[:osfamily] == 'Gentoo'
33+
package_name = 'zabbix'
34+
service_name = 'zabbix-agentd'
35+
else
36+
package_name = 'zabbix-agent'
37+
service_name = 'zabbix-agent'
38+
end
39+
#package = facts[:osfamily] == 'Gentoo' ? 'zabbix' : 'zabbix-agent'
40+
#service = facts[:osfamily] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent'
3241

3342
context 'with all defaults' do
34-
package = 'zabbix-agent'
3543
# Make sure package will be installed, service running and ensure of directory.
3644
it do
37-
is_expected.to contain_package(package).with(
45+
is_expected.to contain_package(package_name).with(
3846
ensure: 'present',
3947
require: 'Class[Zabbix::Repo]',
4048
tag: 'zabbix'
4149
)
4250
end
4351

4452
it do
45-
is_expected.to contain_service('zabbix-agent').with(
53+
is_expected.to contain_service(service_name).with(
4654
ensure: 'running',
4755
enable: true,
4856
hasstatus: true,
4957
hasrestart: true,
50-
require: "Package[#{package}]"
58+
require: "Package[#{package_name}]"
5159
)
5260
end
5361

5462
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') }
55-
it { is_expected.to contain_zabbix__startup('zabbix-agent').that_requires("Package[#{package}]") }
63+
it { is_expected.to contain_zabbix__startup(service_name).that_requires("Package[#{package_name}]") }
5664
it { is_expected.to compile.with_all_deps }
5765
it { is_expected.to contain_class('zabbix::params') }
5866
end
@@ -135,12 +143,12 @@
135143

136144
context 'it creates a startup script' do
137145
case facts[:osfamily]
138-
when 'Archlinux', 'Fedora'
139-
it { is_expected.to contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') }
140-
it { is_expected.to contain_file('/etc/systemd/system/zabbix-agent.service').with_ensure('file') }
146+
when 'Archlinux', 'Fedora', 'Gentoo'
147+
it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('absent') }
148+
it { is_expected.to contain_file("/etc/systemd/system/#{service_name}.service").with_ensure('file') }
141149
else
142-
it { is_expected.to contain_file('/etc/init.d/zabbix-agent').with_ensure('file') }
143-
it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-agent.service') }
150+
it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('file') }
151+
it { is_expected.not_to contain_file("/etc/systemd/system/#{service_name}.service") }
144152
end
145153
end
146154

@@ -151,7 +159,7 @@
151159
}
152160
end
153161

154-
it { is_expected.not_to contain_zabbix__startup('zabbix-agent') }
162+
it { is_expected.not_to contain_zabbix__startup(service_name) }
155163
end
156164

157165
context 'when declaring zabbix_alias' do
@@ -265,10 +273,10 @@
265273
end
266274

267275
it do
268-
is_expected.to contain_service('zabbix-agent').with(
276+
is_expected.to contain_service(service_name).with(
269277
ensure: 'stopped',
270278
enable: false,
271-
require: "Package[#{package}]"
279+
require: "Package[#{package_name}]"
272280
)
273281
end
274282
end

spec/classes/database_spec.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,26 @@
55
'rspec.puppet.com'
66
end
77

8-
let :pre_condition do
9-
"include 'postgresql::server'
10-
include 'mysql::server'"
11-
end
12-
138
on_supported_os.each do |os, facts|
149
context "on #{os} " do
1510
let :facts do
1611
facts
1712
end
1813

14+
let :pre_condition do
15+
<<-EOS
16+
include 'postgresql::server'
17+
if $::osfamily == 'Gentoo' {
18+
# We don't need the package to be installed as its the same for the server.
19+
class { 'mysql::client':
20+
package_manage => false,
21+
}
22+
}
23+
include 'mysql::server'
24+
EOS
25+
end
26+
27+
1928
describe 'database_type is postgresql, zabbix_type is server and is multiple host setup' do
2029
let :params do
2130
{

spec/classes/sender_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
}
2626
end
2727

28-
if facts[:osfamily] == 'Archlinux'
28+
if ['Archlinux', 'Gentoo'].include?(facts[:osfamily])
2929
it 'fails' do
30-
is_expected.to raise_error(Puppet::Error, %r{Managing a repo on Archlinux is currently not implemented})
30+
is_expected.to raise_error(Puppet::Error, %r{Managing a repo on #{facts[:osfamily]} is currently not implemented})
3131
end
3232
else
3333
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version('3.4') }

spec/classes/server_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
on_supported_os.each do |os, facts|
99
next if facts[:osfamily] == 'Archlinux' # zabbix server is currently not supported on archlinux
1010
context "on #{os} " do
11+
systemd_fact = case facts[:osfamily]
12+
when 'Archlinux', 'Fedora', 'Gentoo'
13+
{ systemd: true }
14+
else
15+
{ systemd: false }
16+
end
1117
let :facts do
12-
facts
18+
facts.merge(systemd_fact)
1319
end
1420

1521
describe 'with default settings' do
@@ -128,7 +134,7 @@
128134

129135
context 'it creates a startup script' do
130136
case facts[:osfamily]
131-
when 'Archlinux', 'Fedora'
137+
when 'Archlinux', 'Fedora', 'Gentoo'
132138
it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('absent') }
133139
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_ensure('file') }
134140
else

spec/classes/web_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
facts
1818
end
1919

20-
if facts[:osfamily] == 'Archlinux'
20+
if facts[:osfamily] == 'Archlinux' or facts[:osfamily] == 'Gentoo'
2121
context 'with all defaults' do
2222
it { is_expected.not_to compile }
2323
end

spec/defines/userparameters_spec.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
context "on #{os} " do
66
let :facts do
77
systemd_fact = case facts[:os]['family']
8-
when 'Archlinux', 'Fedora'
8+
when 'Archlinux', 'Fedora', 'Gentoo'
99
{ systemd: true }
1010
else
1111
{ systemd: false }
@@ -14,6 +14,8 @@
1414
end
1515
let(:title) { 'mysqld' }
1616
let(:pre_condition) { 'class { "zabbix::agent": include_dir => "/etc/zabbix/zabbix_agentd.d" }' }
17+
package = facts[:osfamily] == 'Gentoo' ? 'zabbix' : 'zabbix-agent'
18+
service = facts[:osfamily] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent'
1719

1820
context 'with an content' do
1921
let(:params) { { content: 'UserParameter=mysql.ping,mysqladmin -uroot ping | grep -c alive' } }
@@ -23,12 +25,12 @@
2325
it { is_expected.to contain_class('zabbix::params') }
2426
it { is_expected.to contain_class('zabbix::repo') }
2527
it { is_expected.to compile.with_all_deps }
26-
it { is_expected.to contain_file('/etc/init.d/zabbix-agent') }
28+
it { is_expected.to contain_file("/etc/init.d/#{service}") }
2729
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf') }
2830
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.d') }
29-
it { is_expected.to contain_package('zabbix-agent') }
30-
it { is_expected.to contain_service('zabbix-agent') }
31-
it { is_expected.to contain_zabbix__startup('zabbix-agent') }
31+
it { is_expected.to contain_package(package) }
32+
it { is_expected.to contain_service(service) }
33+
it { is_expected.to contain_zabbix__startup(service) }
3234
end
3335
end
3436
end

0 commit comments

Comments
 (0)