From 8f5421a182cbaab633c370a30c2ddf74e3da97c4 Mon Sep 17 00:00:00 2001 From: William Yardley Date: Thu, 11 May 2023 09:59:38 -0700 Subject: [PATCH] Support FreeBSD 12 and 13 Update tests and metadata to support FreeBSD 12 and 13 This also helps us unit test the (otherwise untested) conditionals related to systems without systemd We may still need to tweak the current python package name, but this is a start Per @bastelfreak's suggestion, use os_facts to avoid confusion with :facts Signed-off-by: William Yardley --- metadata.json | 6 ++- spec/classes/rabbitmq_spec.rb | 80 ++++++++++++++++++++--------------- 2 files changed, 51 insertions(+), 35 deletions(-) diff --git a/metadata.json b/metadata.json index ee16264ef..aa09ef08a 100644 --- a/metadata.json +++ b/metadata.json @@ -39,7 +39,11 @@ ] }, { - "operatingsystem": "FreeBSD" + "operatingsystem": "FreeBSD", + "operatingsystemrelease": [ + "12", + "13" + ] }, { "operatingsystem": "OpenBSD" diff --git a/spec/classes/rabbitmq_spec.rb b/spec/classes/rabbitmq_spec.rb index 0645661c5..7eb5c8bbe 100644 --- a/spec/classes/rabbitmq_spec.rb +++ b/spec/classes/rabbitmq_spec.rb @@ -6,19 +6,26 @@ 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 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]') } @@ -26,7 +33,7 @@ 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') } @@ -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'). @@ -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 @@ -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 @@ -78,13 +85,13 @@ 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}' ) @@ -92,13 +99,13 @@ 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}' ) @@ -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'). @@ -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"). @@ -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). @@ -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 @@ -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']) end context 'with manage_python false' do @@ -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 @@ -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 @@ -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 @@ -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, @@ -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' } } @@ -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' } } @@ -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 @@ -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 @@ -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 @@ -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 @@ -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]')