Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
]
},
{
"operatingsystem": "FreeBSD"
"operatingsystem": "FreeBSD",
"operatingsystemrelease": [
"12",
"13"
]
},
{
"operatingsystem": "OpenBSD"
Expand Down
80 changes: 46 additions & 34 deletions spec/classes/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,34 @@
require 'spec_helper'

describe 'rabbitmq' do
on_supported_os.each do |os, facts|
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let :facts do
facts
os_facts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bastelfreak this (and associated changes) is what you had in mind, right?

end

name = case facts[:osfamily]
name = case os_facts[:osfamily]
when 'Archlinux', 'OpenBSD', 'FreeBSD'
'rabbitmq'
else
'rabbitmq-server'
end

rabbitmq_home = case os_facts[:osfamily]
when 'FreeBSD'
'/var/db/rabbitmq'
else
'/var/lib/rabbitmq'
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('rabbitmq::install') }
it { is_expected.to contain_class('rabbitmq::config').that_notifies('Class[rabbitmq::service]') }
it { is_expected.to contain_class('rabbitmq::service') }

it { is_expected.to contain_package(name).with_ensure('installed').with_name(name) }

it { is_expected.to contain_package('rabbitmq-server-plugins') } if facts[:os]['family'] == 'Suse'
it { is_expected.to contain_package('rabbitmq-server-plugins') } if os_facts[:os]['family'] == 'Suse'

context 'with default params' do
it { is_expected.not_to contain_class('rabbitmq::repo::apt') }
Expand All @@ -44,7 +51,7 @@
context 'with repos_ensure => true' do
let(:params) { { repos_ensure: true } }

if facts[:os]['family'] == 'Debian'
if os_facts[:os]['family'] == 'Debian'
it 'includes rabbitmq::repo::apt' do
is_expected.to contain_class('rabbitmq::repo::apt').
with_key_source('https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey').
Expand All @@ -54,7 +61,7 @@
it 'adds a repo with default values' do
is_expected.to contain_apt__source('rabbitmq').
with_ensure('present').
with_location("https://packagecloud.io/rabbitmq/rabbitmq-server/#{facts[:os]['name'].downcase}").
with_location("https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts[:os]['name'].downcase}").
with_release(nil).
with_repos('main')
end
Expand All @@ -63,7 +70,7 @@
it { is_expected.not_to contain_apt__souce('rabbitmq') }
end

if facts[:os]['family'] == 'RedHat'
if os_facts[:os]['family'] == 'RedHat'
it { is_expected.to contain_class('rabbitmq::repo::rhel') }

it 'the repo should be present, and contain the expected values' do
Expand All @@ -78,27 +85,27 @@
end
end

context 'with no pin', if: facts[:os]['family'] == 'Debian' do
context 'with no pin', if: os_facts[:os]['family'] == 'Debian' do
let(:params) { { repos_ensure: true, package_apt_pin: '' } }

describe 'it sets up an apt::source' do
it {
is_expected.to contain_apt__source('rabbitmq').with(
'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{facts[:os]['name'].downcase}",
'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts[:os]['name'].downcase}",
'repos' => 'main',
'key' => '{"id"=>"8C695B0219AFDEB04A058ED8F4E789204D206F89", "source"=>"https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey", "content"=>nil}'
)
}
end
end

context 'with pin', if: facts[:os]['family'] == 'Debian' do
context 'with pin', if: os_facts[:os]['family'] == 'Debian' do
let(:params) { { repos_ensure: true, package_apt_pin: '700' } }

describe 'it sets up an apt::source and pin' do
it {
is_expected.to contain_apt__source('rabbitmq').with(
'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{facts[:os]['name'].downcase}",
'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts[:os]['name'].downcase}",
'repos' => 'main',
'key' => '{"id"=>"8C695B0219AFDEB04A058ED8F4E789204D206F89", "source"=>"https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey", "content"=>nil}'
)
Expand All @@ -118,7 +125,7 @@
context "with file_limit => '#{value}'" do
let(:params) { { file_limit: value } }

if facts[:os]['family'] == 'RedHat'
if os_facts[:os]['family'] == 'RedHat'
it do
is_expected.to contain_file('/etc/security/limits.d/rabbitmq-server.conf').
with_owner('0').
Expand All @@ -131,14 +138,14 @@
it { is_expected.not_to contain_file('/etc/security/limits.d/rabbitmq-server.conf') }
end

if facts[:os]['family'] == 'Debian'
if os_facts[:os]['family'] == 'Debian'
it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(%r{ulimit -n #{value}}) }
else
it { is_expected.not_to contain_file('/etc/default/rabbitmq-server') }
end

if facts[:systemd]
selinux_ignore_defaults = facts[:os]['family'] == 'RedHat'
if os_facts[:systemd]
selinux_ignore_defaults = os_facts[:os]['family'] == 'RedHat'

it do
is_expected.to contain_systemd__service_limits("#{name}.service").
Expand Down Expand Up @@ -166,13 +173,13 @@
context "with oom_score_adj => '#{value}'" do
let(:params) { { oom_score_adj: value } }

if facts[:os]['family'] == 'Debian'
if os_facts[:os]['family'] == 'Debian'
it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(%r{^echo #{value} > /proc/\$\$/oom_score_adj$}) }
else
it { is_expected.not_to contain_file('/etc/default/rabbitmq-server') }
end

if facts[:systemd]
if os_facts[:systemd]
it do
is_expected.to contain_systemd__service_limits("#{name}.service").
with_limits('OOMScoreAdjust' => value).
Expand All @@ -194,14 +201,14 @@
end
end

context 'on systems with systemd', if: facts[:systemd] do
context 'on systems with systemd', if: os_facts[:systemd] do
it do
is_expected.to contain_systemd__service_limits("#{name}.service").
with_restart_service(false)
end
end

context 'on systems without systemd', unless: facts[:systemd] do
context 'on systems without systemd', unless: os_facts[:systemd] do
it { is_expected.not_to contain_systemd__service_limits("#{name}.service") }
end

Expand All @@ -227,8 +234,8 @@
is_expected.to contain_archive('rabbitmqadmin').with_source('http://1.1.1.1:15672/cli/rabbitmqadmin')
end

it { is_expected.to contain_package('python') } if %w[RedHat Debian SUSE Archlinux].include?(facts[:os]['family'])
it { is_expected.to contain_package('python2') } if %w[FreeBSD OpenBSD].include?(facts[:os]['family'])
it { is_expected.to contain_package('python') } if %w[RedHat Debian SUSE Archlinux].include?(os_facts[:os]['family'])
it { is_expected.to contain_package('python38') } if %w[FreeBSD].include?(os_facts[:os]['family'])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this may have changed by now - not sure. but at least it matches the current stuff in data, and can be adjusted in tests later if needed

end

context 'with manage_python false' do
Expand All @@ -241,7 +248,7 @@
end
end

context 'with $management_ip_address undef and service_manage set to true', unless: facts[:osfamily] == 'Archlinux' do
context 'with $management_ip_address undef and service_manage set to true', unless: os_facts[:osfamily] == 'Archlinux' do
let(:params) { { admin_enable: true, management_ip_address: :undef } }

it 'we enable the admin interface by default' do
Expand All @@ -253,7 +260,7 @@
end
end

context 'with service_manage set to true, node_ip_address = undef, and default user/pass specified', unless: facts[:osfamily] == 'Archlinux' do
context 'with service_manage set to true, node_ip_address = undef, and default user/pass specified', unless: os_facts[:osfamily] == 'Archlinux' do
let(:params) { { admin_enable: true, default_user: 'foobar', default_pass: 'hunter2', node_ip_address: :undef } }

it 'we use the correct URL to rabbitmqadmin' do
Expand All @@ -265,7 +272,7 @@
end
end

context 'with service_manage set to true and default user/pass specified', unless: facts[:osfamily] == 'Archlinux' do
context 'with service_manage set to true and default user/pass specified', unless: os_facts[:osfamily] == 'Archlinux' do
let(:params) { { admin_enable: true, default_user: 'foobar', default_pass: 'hunter2', management_ip_address: '1.1.1.1' } }

it 'we use the correct URL to rabbitmqadmin' do
Expand All @@ -277,7 +284,7 @@
end
end

context 'with service_manage set to true and archive_options set', unless: facts[:osfamily] == 'Archlinux' do
context 'with service_manage set to true and archive_options set', unless: os_facts[:osfamily] == 'Archlinux' do
let(:params) do
{
admin_enable: true,
Expand All @@ -294,7 +301,7 @@
end
end

context 'with service_manage set to true and management port specified', unless: facts[:osfamily] == 'Archlinux' do
context 'with service_manage set to true and management port specified', unless: os_facts[:osfamily] == 'Archlinux' do
# NOTE: that the 2.x management port is 55672 not 15672
let(:params) { { admin_enable: true, management_port: 55_672, management_ip_address: '1.1.1.1' } }

Expand All @@ -307,7 +314,7 @@
end
end

context 'with ipv6, service_manage set to true and management port specified', unless: facts[:osfamily] == 'Archlinux' do
context 'with ipv6, service_manage set to true and management port specified', unless: os_facts[:osfamily] == 'Archlinux' do
# NOTE: that the 2.x management port is 55672 not 15672
let(:params) { { admin_enable: true, management_port: 55_672, management_ip_address: '::1' } }

Expand Down Expand Up @@ -404,7 +411,7 @@
end

it 'contains the rabbitmq_erlang_cookie' do
is_expected.to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie')
is_expected.to contain_rabbitmq_erlang_cookie("#{rabbitmq_home}/.erlang.cookie")
end
end

Expand All @@ -417,7 +424,7 @@
end

it 'contains the rabbitmq_erlang_cookie' do
is_expected.to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie')
is_expected.to contain_rabbitmq_erlang_cookie("#{rabbitmq_home}/.erlang.cookie")
end
end

Expand All @@ -428,8 +435,8 @@
}
end

it 'contains the rabbitmq_erlang_cookie' do
is_expected.not_to contain_rabbitmq_erlang_cookie('/var/lib/rabbitmq/.erlang.cookie')
it 'does not contains the rabbitmq_erlang_cookie' do
is_expected.not_to contain_rabbitmq_erlang_cookie("#{rabbitmq_home}/.erlang.cookie")
end
end

Expand All @@ -453,8 +460,13 @@
describe 'rabbitmq-env configuration' do
context 'with default params' do
it 'sets environment variables' do
is_expected.to contain_file('rabbitmq-env.config'). \
with_content(%r{ERL_INETRC=/etc/rabbitmq/inetrc})
if %w[FreeBSD OpenBSD].include?(os_facts[:os]['family'])
is_expected.to contain_file('rabbitmq-env.config'). \
with_content(%r{ERL_INETRC=/usr/local/etc/rabbitmq/inetrc})
else
is_expected.to contain_file('rabbitmq-env.config'). \
with_content(%r{ERL_INETRC=/etc/rabbitmq/inetrc})
end
end
end

Expand Down Expand Up @@ -1764,7 +1776,7 @@
}
end

context 'on systems with systemd', if: facts[:systemd] do
context 'on systems with systemd', if: os_facts[:systemd] do
it do
is_expected.to contain_service('rabbitmq-server').
that_requires('Class[systemd::systemctl::daemon_reload]')
Expand Down