Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to structured facts for os* and rabbitmq_version #579

Merged
merged 1 commit into from
Sep 2, 2017
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
10 changes: 5 additions & 5 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@
# Get ranch (socket acceptor pool) availability,
# Now that we have to rely on the fact, this may cause some chicken / egg
# or idempotency problems
if $::rabbitmq_version {
$ranch = versioncmp($::rabbitmq_version, '3.6') >= 0
if $facts['rabbitmq_version'] {
$ranch = versioncmp($facts['rabbitmq_version'], '3.6') >= 0
}

file { '/etc/rabbitmq':
Expand Down Expand Up @@ -192,9 +192,9 @@
}
}

case $::osfamily {
case $facts['os']['family'] {
'Debian': {
if versioncmp($::operatingsystemmajrelease, '16.04') >= 0 {
if versioncmp($facts['os']['release']['full'], '16.04') >= 0 {
file { '/etc/systemd/system/rabbitmq-server.service.d':
ensure => directory,
owner => '0',
Expand Down Expand Up @@ -225,7 +225,7 @@
}
}
'RedHat': {
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
if versioncmp($facts['os']['release']['major'], '7') >= 0 {
file { '/etc/systemd/system/rabbitmq-server.service.d':
ensure => directory,
owner => '0',
Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
}

if $repos_ensure {
case $::osfamily {
case $facts['os']['family'] {
'RedHat': {
class { '::rabbitmq::repo::rhel':
key_source => $package_gpg_key,
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
class rabbitmq::params {

case $::osfamily {
case $facts['os']['family'] {
'Archlinux': {
$package_ensure = 'installed'
$package_name = 'rabbitmq'
Expand Down Expand Up @@ -54,7 +54,7 @@
$rabbitmq_home = '/var/lib/rabbitmq'
}
default: {
fail("The ${module_name} module is not supported on an ${::osfamily} based system.")
fail("The ${module_name} module is not supported on an ${facts['os']['family']} based system.")
}
}

Expand Down
2 changes: 1 addition & 1 deletion manifests/repo/rhel.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Class: rabbitmq::repo::rhel
# Makes sure that the Packagecloud repo is installed
class rabbitmq::repo::rhel(
$location = "https://packagecloud.io/rabbitmq/rabbitmq-server/el/${::os[release][major]}/\$basearch",
$location = "https://packagecloud.io/rabbitmq/rabbitmq-server/el/${facts['os'][release][major]}/\$basearch",
$key_source = 'https://www.rabbitmq.com/rabbitmq-release-signing-key.asc',
) {

Expand Down
10 changes: 5 additions & 5 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper_acceptance'

describe 'rabbitmq class:' do
case fact('osfamily')
case fact('os.family')
when 'RedHat'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
Expand All @@ -20,7 +20,7 @@
it 'runs successfully' do
pp = <<-EOS
class { 'rabbitmq': }
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand All @@ -47,7 +47,7 @@ class { 'erlang': epel_enable => true}
class { 'rabbitmq':
service_ensure => 'stopped',
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand All @@ -66,7 +66,7 @@ class { 'erlang': epel_enable => true}
it 'runs successfully' do
pp_pre = <<-EOS
class { 'rabbitmq': }
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand All @@ -77,7 +77,7 @@ class { 'rabbitmq':
service_manage => false,
service_ensure => 'stopped',
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/clustering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class { 'rabbitmq':
erlang_cookie => 'TESTCOOKIE',
wipe_db_on_cookie_change => false,
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand All @@ -34,7 +34,7 @@ class { 'rabbitmq':
erlang_cookie => 'TESTCOOKIE',
wipe_db_on_cookie_change => true,
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/delete_guest_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class { 'rabbitmq':
port => 5672,
delete_guest_user => true,
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/parameter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
context 'create parameter resource' do
it 'runs successfully' do
pp = <<-EOS
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true }
Class['erlang'] -> Class['::rabbitmq']
}
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
context 'create policy resource' do
it 'runs successfully' do
pp = <<-EOS
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true }
Class['erlang'] -> Class['::rabbitmq']
}
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
context 'create binding and queue resources when using default management port' do
it 'runs successfully' do
pp = <<-EOS
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true }
Class['erlang'] -> Class['::rabbitmq']
}
Expand Down Expand Up @@ -78,7 +78,7 @@ class { '::rabbitmq':
context 'create multiple bindings when same source / destination / vhost but different routing keys' do
it 'runs successfully' do
pp = <<-EOS
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true }
Class['erlang'] -> Class['::rabbitmq']
}
Expand Down Expand Up @@ -160,7 +160,7 @@ class { '::rabbitmq':
context 'create binding and queue resources when using a non-default management port' do
it 'runs successfully' do
pp = <<-EOS
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true }
Class['erlang'] -> Class['::rabbitmq']
}
Expand Down
8 changes: 4 additions & 4 deletions spec/acceptance/rabbitmqadmin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class { 'rabbitmq':
admin_enable => true,
service_manage => true,
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand All @@ -29,7 +29,7 @@ class { 'rabbitmq':
admin_enable => true,
service_manage => false,
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand All @@ -53,7 +53,7 @@ class { 'rabbitmq':
default_user => 'foobar',
default_pass => 'bazblam',
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand All @@ -66,7 +66,7 @@ class { 'rabbitmq':
default_user => 'foobar',
default_pass => 'bazblam',
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
Expand Down
10 changes: 5 additions & 5 deletions spec/acceptance/server_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper_acceptance'

describe 'rabbitmq server:' do
case fact('osfamily')
case fact('os.family')
when 'RedHat'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
Expand All @@ -20,7 +20,7 @@
it 'runs successfully' do
pp = <<-EOS
class { 'rabbitmq::server': }
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq::server']
}
Expand All @@ -47,7 +47,7 @@ class { 'erlang': epel_enable => true}
class { 'rabbitmq::server':
service_ensure => 'stopped',
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq::server']
}
Expand All @@ -66,7 +66,7 @@ class { 'erlang': epel_enable => true}
it 'runs successfully' do
pp_pre = <<-EOS
class { 'rabbitmq::server': }
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq::server']
}
Expand All @@ -77,7 +77,7 @@ class { 'rabbitmq::server':
service_manage => false,
service_ensure => 'stopped',
}
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq::server']
}
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
context 'create user resource' do
it 'runs successfully' do
pp = <<-EOS
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true }
Class['erlang'] -> Class['::rabbitmq']
}
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
context 'create vhost resource' do
it 'runs successfully' do
pp = <<-EOS
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
class { 'erlang': epel_enable => true }
Class['erlang'] -> Class['::rabbitmq']
}
Expand Down
24 changes: 14 additions & 10 deletions spec/classes/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

describe 'rabbitmq' do
context 'on unsupported distributions' do
let(:facts) { { osfamily: 'Unsupported' } }
let(:facts) do
{
os: { family: 'Unsupported' }
}
end

it 'we fail' do
expect { catalogue }.to raise_error(Puppet::Error, %r{not supported on an Unsupported})
Expand All @@ -16,9 +20,9 @@
let(:facts) { facts }

has_systemd = (
(facts[:osfamily] == 'RedHat' && facts[:os]['release']['major'].to_i >= 7) ||
(facts[:osfamily] == 'Debian' && facts[:os]['release']['full'] == '16.04') ||
(facts[:osfamily] == 'Archlinux')
(facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i >= 7) ||
(facts[:os]['family'] == 'Debian' && facts[:os]['release']['full'] == '16.04') ||
(facts[:os]['family'] == 'Archlinux')
)

it { is_expected.to compile.with_all_deps }
Expand All @@ -38,7 +42,7 @@
context 'with repos_ensure => true' do
let(:params) { { repos_ensure: true } }

if facts[:osfamily] == 'Debian'
if facts[:os]['family'] == 'Debian'
it 'includes rabbitmq::repo::apt' do
is_expected.to contain_class('rabbitmq::repo::apt').
with_key_source('https://www.rabbitmq.com/rabbitmq-release-signing-key.asc').
Expand All @@ -57,7 +61,7 @@
it { is_expected.not_to contain_apt__souce('rabbitmq') }
end

if facts[:osfamily] == 'RedHat'
if 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 @@ -72,7 +76,7 @@
end
end

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

describe 'it sets up an apt::source' do
Expand All @@ -87,7 +91,7 @@
end
end

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

describe 'it sets up an apt::source and pin' do
Expand All @@ -114,7 +118,7 @@
context "with file_limit => '#{value}'" do
let(:params) { { file_limit: value } }

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

if facts[:osfamily] == 'Debian'
if 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') }
Expand Down
6 changes: 3 additions & 3 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
puppet_module_install(source: proj_root, module_name: 'rabbitmq')

hosts.each do |host|
if fact('osfamily') == 'RedHat' && fact('selinux') == 'true'
if fact('os.family') == 'RedHat' && fact('selinux') == 'true'
# Make sure selinux is disabled so the tests work.
on host, puppet('apply', '-e',
%("exec { 'setenforce 0': path => '/bin:/sbin:/usr/bin:/usr/sbin', onlyif => 'which setenforce && getenforce | grep Enforcing', }"))
Expand All @@ -24,11 +24,11 @@
on host, puppet('module', 'install', 'puppetlabs-stdlib'), acceptable_exit_codes: [0, 1]
on host, puppet('module', 'install', 'puppet-staging'), acceptable_exit_codes: [0, 1]

if fact('osfamily') == 'Debian'
if fact('os.family') == 'Debian'
on host, puppet('module', 'install', 'puppetlabs-apt'), acceptable_exit_codes: [0, 1]
end

if fact('osfamily') == 'RedHat'
if fact('os.family') == 'RedHat'
on host, puppet('module', 'install', 'garethr-erlang'), acceptable_exit_codes: [0, 1]
end
end
Expand Down