Skip to content

Commit

Permalink
Merge pull request #576 from syseleven/fix/gentoo_rspec_tests
Browse files Browse the repository at this point in the history
Fix rspec tests for Gentoo
  • Loading branch information
alexjfisher authored Dec 21, 2018
2 parents 1a8808e + 99033d3 commit 9bf8f09
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 33 deletions.
4 changes: 2 additions & 2 deletions manifests/web.pp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@
) inherits zabbix::params {

# check osfamily, Arch is currently not supported for web
if $facts['os']['family'] == 'Archlinux' {
fail('Archlinux is currently not supported for zabbix::web ')
if $facts['os']['family'] in [ 'Archlinux', 'Gentoo', ] {
fail("${facts['os']['family']} is currently not supported for zabbix::web")
}

# Only include the repo class if it has not yet been included
Expand Down
39 changes: 23 additions & 16 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
on_supported_os.each do |os, facts|
context "on #{os} " do
systemd_fact = case facts[:osfamily]
when 'Archlinux', 'Fedora'
when 'Archlinux', 'Fedora', 'Gentoo'
{ systemd: true }
else
{ systemd: false }
Expand All @@ -30,29 +30,38 @@
facts.merge(systemd_fact)
end

if facts[:osfamily] == 'Gentoo'
package_name = 'zabbix'
service_name = 'zabbix-agentd'
else
package_name = 'zabbix-agent'
service_name = 'zabbix-agent'
end
# package = facts[:osfamily] == 'Gentoo' ? 'zabbix' : 'zabbix-agent'
# service = facts[:osfamily] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent'

context 'with all defaults' do
package = 'zabbix-agent'
# Make sure package will be installed, service running and ensure of directory.
it do
is_expected.to contain_package(package).with(
is_expected.to contain_package(package_name).with(
ensure: 'present',
require: 'Class[Zabbix::Repo]',
tag: 'zabbix'
)
end

it do
is_expected.to contain_service('zabbix-agent').with(
is_expected.to contain_service(service_name).with(
ensure: 'running',
enable: true,
hasstatus: true,
hasrestart: true,
require: "Package[#{package}]"
require: "Package[#{package_name}]"
)
end

it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') }
it { is_expected.to contain_zabbix__startup('zabbix-agent').that_requires("Package[#{package}]") }
it { is_expected.to contain_zabbix__startup(service_name).that_requires("Package[#{package_name}]") }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('zabbix::params') }
end
Expand Down Expand Up @@ -135,12 +144,12 @@

context 'it creates a startup script' do
case facts[:osfamily]
when 'Archlinux', 'Fedora'
it { is_expected.to contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-agent.service').with_ensure('file') }
when 'Archlinux', 'Fedora', 'Gentoo'
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') }
else
it { is_expected.to contain_file('/etc/init.d/zabbix-agent').with_ensure('file') }
it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-agent.service') }
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

Expand All @@ -151,7 +160,7 @@
}
end

it { is_expected.not_to contain_zabbix__startup('zabbix-agent') }
it { is_expected.not_to contain_zabbix__startup(service_name) }
end

context 'when declaring zabbix_alias' do
Expand Down Expand Up @@ -255,8 +264,6 @@
end

context 'when declaring service_ensure is stopped and service_enable false' do
package = 'zabbix-agent'

let :params do
{
service_ensure: 'stopped',
Expand All @@ -265,10 +272,10 @@
end

it do
is_expected.to contain_service('zabbix-agent').with(
is_expected.to contain_service(service_name).with(
ensure: 'stopped',
enable: false,
require: "Package[#{package}]"
require: "Package[#{package_name}]"
)
end
end
Expand Down
18 changes: 13 additions & 5 deletions spec/classes/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@
'rspec.puppet.com'
end

let :pre_condition do
"include 'postgresql::server'
include 'mysql::server'"
end

on_supported_os.each do |os, facts|
context "on #{os} " do
let :facts do
facts
end

let :pre_condition do
<<-EOS
include 'postgresql::server'
if $::osfamily == 'Gentoo' {
# We don't need the package to be installed as its the same for the server.
class { 'mysql::client':
package_manage => false,
}
}
include 'mysql::server'
EOS
end

describe 'database_type is postgresql, zabbix_type is server and is multiple host setup' do
let :params do
{
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
}
end

if facts[:osfamily] == 'Archlinux'
if %w[Archlinux Gentoo].include?(facts[:osfamily])
it 'fails' do
is_expected.to raise_error(Puppet::Error, %r{Managing a repo on Archlinux is currently not implemented})
is_expected.to raise_error(Puppet::Error, %r{Managing a repo on #{facts[:osfamily]} is currently not implemented})
end
else
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version('3.4') }
Expand Down
10 changes: 8 additions & 2 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
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', 'Fedora', 'Gentoo'
{ systemd: true }
else
{ systemd: false }
end
let :facts do
facts
facts.merge(systemd_fact)
end

describe 'with default settings' do
Expand Down Expand Up @@ -128,7 +134,7 @@

context 'it creates a startup script' do
case facts[:osfamily]
when 'Archlinux', 'Fedora'
when 'Archlinux', 'Fedora', 'Gentoo'
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') }
else
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/web_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
facts
end

if facts[:osfamily] == 'Archlinux'
if facts[:osfamily] == 'Archlinux' || facts[:osfamily] == 'Gentoo'
context 'with all defaults' do
it { is_expected.not_to compile }
end
Expand Down
13 changes: 8 additions & 5 deletions spec/defines/userparameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
context "on #{os} " do
let :facts do
systemd_fact = case facts[:os]['family']
when 'Archlinux', 'Fedora'
when 'Archlinux', 'Fedora', 'Gentoo'
{ systemd: true }
else
{ systemd: false }
Expand All @@ -15,6 +15,9 @@
let(:title) { 'mysqld' }
let(:pre_condition) { 'class { "zabbix::agent": include_dir => "/etc/zabbix/zabbix_agentd.d" }' }

package = facts[:osfamily] == 'Gentoo' ? 'zabbix' : 'zabbix-agent'
service = facts[:osfamily] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent'

context 'with an content' do
let(:params) { { content: 'UserParameter=mysql.ping,mysqladmin -uroot ping | grep -c alive' } }

Expand All @@ -23,12 +26,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/zabbix-agent') }
it { is_expected.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('zabbix-agent') }
it { is_expected.to contain_service('zabbix-agent') }
it { is_expected.to contain_zabbix__startup('zabbix-agent') }
it { is_expected.to contain_package(package) }
it { is_expected.to contain_service(service) }
it { is_expected.to contain_zabbix__startup(service) }
end
end
end
Expand Down

0 comments on commit 9bf8f09

Please sign in to comment.