Skip to content

Commit

Permalink
Merge pull request #715 from bastelfreak/wip
Browse files Browse the repository at this point in the history
Rebase of #683 / mock systemd fact properly
  • Loading branch information
bastelfreak authored Sep 5, 2018
2 parents dc94535 + 509aef0 commit 5edf3f2
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 215 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ fixtures:
"apt": "git://github.com/puppetlabs/puppetlabs-apt.git"
"archive": "https://github.com/voxpupuli/puppet-archive.git"
"erlang": "git://github.com/garethr/garethr-erlang.git"
"systemd": "https://github.com/camptocamp/puppet-systemd.git"
symlinks:
"rabbitmq": "#{source_dir}"
1 change: 1 addition & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ appveyor.yml:
spec/spec_helper.rb:
allow_deprecations: true
spec_overrides: "require 'spec_helper_local'"
mock_with: ':rspec'
72 changes: 8 additions & 64 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,6 @@
case $facts['os']['family'] {
'Debian': {
if versioncmp($facts['os']['release']['full'], '16.04') >= 0 {
file { '/etc/systemd/system/rabbitmq-server.service.d':
ensure => directory,
owner => '0',
group => '0',
mode => '0755',
selinux_ignore_defaults => true,
}
-> file { '/etc/systemd/system/rabbitmq-server.service.d/limits.conf':
content => template('rabbitmq/rabbitmq-server.service.d/limits.conf'),
owner => '0',
group => '0',
mode => '0644',
notify => Exec['rabbitmq-systemd-reload'],
}
exec { 'rabbitmq-systemd-reload':
command => '/bin/systemctl daemon-reload',
notify => Class['Rabbitmq::Service'],
refreshonly => true,
}
}
file { '/etc/default/rabbitmq-server':
ensure => file,
content => template('rabbitmq/default.erb'),
Expand All @@ -226,27 +205,6 @@
}
}
'RedHat': {
if versioncmp($facts['os']['release']['major'], '7') >= 0 {
file { '/etc/systemd/system/rabbitmq-server.service.d':
ensure => directory,
owner => '0',
group => '0',
mode => '0755',
selinux_ignore_defaults => true,
}
-> file { '/etc/systemd/system/rabbitmq-server.service.d/limits.conf':
content => template('rabbitmq/rabbitmq-server.service.d/limits.conf'),
owner => '0',
group => '0',
mode => '0644',
notify => Exec['rabbitmq-systemd-reload'],
}
exec { 'rabbitmq-systemd-reload':
command => '/bin/systemctl daemon-reload',
notify => Class['Rabbitmq::Service'],
refreshonly => true,
}
}
file { '/etc/security/limits.d/rabbitmq-server.conf':
content => template('rabbitmq/limits.conf'),
owner => '0',
Expand All @@ -255,28 +213,14 @@
notify => Class['Rabbitmq::Service'],
}
}
'Archlinux': {
file { '/etc/systemd/system/rabbitmq.service.d':
ensure => directory,
owner => '0',
group => '0',
mode => '0755',
selinux_ignore_defaults => true,
}
-> file { '/etc/systemd/system/rabbitmq.service.d/limits.conf':
content => template('rabbitmq/rabbitmq-server.service.d/limits.conf'),
owner => '0',
group => '0',
mode => '0644',
notify => Exec['rabbitmq-systemd-reload'],
}
exec { 'rabbitmq-systemd-reload':
command => '/bin/systemctl daemon-reload',
notify => Class['Rabbitmq::Service'],
refreshonly => true,
}
}
default: {
default: { }
}
if $facts['systemd'] { # systemd fact provided by systemd module
systemd::service_limits { 'rabbitmq.service':
limits => {'LimitNOFILE' => $file_limit},
# The service will be notified when config changes
restart_service => false,
}
}
Expand Down
184 changes: 92 additions & 92 deletions manifests/init.pp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
hasrestart => true,
name => $service_name,
}

if $facts['systemd'] {
Class['systemd::systemctl::daemon_reload'] -> Service['rabbitmq-server']
}
}

}
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
{
"name": "puppet/archive",
"version_requirement": ">= 2.0.0 < 4.0.0"
},
{
"name": "camptocamp/systemd",
"version_requirement": ">= 2.1.0 < 3.0.0"
}
],
"tags": [
Expand Down
68 changes: 26 additions & 42 deletions spec/classes/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,20 @@
end
end

# TODO: get Archlinux & OpenBSD facts from facterdb

on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) { facts }
systemd_facts = os_specific_facts(facts)
facts = facts.merge(systemd_facts)
let :facts do
facts
end

packagename = case facts[:osfamily]
when 'Archlinux'
'rabbitmq'
else
'rabbitmq-server'
end
has_systemd = (
(facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i >= 7) ||
(facts[:os]['family'] == 'Debian' && facts[:os]['release']['major'].to_i >= 16) ||
(facts[:os]['family'] == 'Archlinux')
)

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('rabbitmq::install') }
Expand Down Expand Up @@ -121,7 +118,7 @@
end
end

['unlimited', 'infinity', -1, 1234].each do |value|
['infinity', -1, 1234].each do |value|
context "with file_limit => '#{value}'" do
let(:params) { { file_limit: value } }

Expand All @@ -144,22 +141,19 @@
it { is_expected.not_to contain_file('/etc/default/rabbitmq-server') }
end

if has_systemd
if facts[:systemd]
it do
is_expected.to contain_file("/etc/systemd/system/#{packagename}.service.d/limits.conf").
with_owner('0').
with_group('0').
with_mode('0644').
that_notifies('Exec[rabbitmq-systemd-reload]').
with_content("[Service]\nLimitNOFILE=#{value}\n")
is_expected.to contain_systemd__service_limits('rabbitmq.service').
with_limits('LimitNOFILE' => value).
with_restart_service(false)
end
else
it { is_expected.not_to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf') }
it { is_expected.not_to contain_systemd__service_limits('rabbitmq.service') }
end
end
end

[-42, '-42', 'foo', '42'].each do |value|
[-42, '-42', 'foo'].each do |value|
context "with file_limit => '#{value}'" do
let(:params) { { file_limit: value } }

Expand All @@ -169,32 +163,15 @@
end
end

context 'on systems with systemd', if: has_systemd do
it {
is_expected.to contain_file("/etc/systemd/system/#{packagename}.service.d").with(
'ensure' => 'directory',
'owner' => '0',
'group' => '0',
'mode' => '0755',
'selinux_ignore_defaults' => true
)
}

it { is_expected.to contain_file("/etc/systemd/system/#{packagename}.service.d/limits.conf") }

it {
is_expected.to contain_exec('rabbitmq-systemd-reload').with(
command: '/bin/systemctl daemon-reload',
notify: 'Class[Rabbitmq::Service]',
refreshonly: true
)
}
context 'on systems with systemd', if: facts[:systemd] do
it do
is_expected.to contain_systemd__service_limits('rabbitmq.service').
with_restart_service(false)
end
end

context 'on systems without systemd', unless: has_systemd do
it { is_expected.not_to contain_file('/etc/systemd/system/rabbitmq-server.service.d') }
it { is_expected.not_to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf') }
it { is_expected.not_to contain_exec('rabbitmq-systemd-reload') }
context 'on systems without systemd', unless: facts[:systemd] do
it { is_expected.not_to contain_systemd__service_limits('rabbitmq.service') }
end

context 'with admin_enable set to true' do
Expand Down Expand Up @@ -1450,6 +1427,13 @@
}
end

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

describe 'service with ensure stopped' do
let :params do
{ service_ensure: 'stopped' }
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__))
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
c.default_facts = default_facts
c.mock_with :rspec
end

require 'spec_helper_local'
Expand Down
29 changes: 25 additions & 4 deletions spec/spec_helper_local.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
require 'rspec-puppet-facts'
include RspecPuppetFacts
# # Original fact sources:
add_custom_fact :puppetversion, Puppet.version # Facter, but excluded from rspec-puppet-facts
add_custom_fact :rabbitmq_version, '3.6.1' # puppet-rabbitmq
add_custom_fact :erl_ssl_path, '/usr/lib64/erlang/lib/ssl-7.3.3.1/ebin' # puppet-rabbitmq

def os_specific_facts(facts)
case facts[:os]['family']
when 'Archlinux'
{ service_provider: 'systemd', systemd: true }
when 'Debian'
case facts[:os]['release']['major']
when '7'
{ service_provider: 'sysv', systemd: false }
when '14.04'
{ service_provider: 'upstart', systemd: false }
else
{ service_provider: 'systemd', systemd: true }
end
when 'RedHat'
case facts[:os]['release']['major']
when '6'
{ service_provider: 'sysv', systemd: false }
else
{ service_provider: 'systemd', systemd: true }
end
else
{ service_provider: 'systemd', systemd: true }
end
end
3 changes: 0 additions & 3 deletions spec/unit/facter/util/fact_erl_ssl_path_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
require 'spec_helper'
RSpec.configure do |config|
config.mock_with :rspec
end

describe Facter::Util::Fact do
before { Facter.clear }
Expand Down
4 changes: 0 additions & 4 deletions spec/unit/facter/util/fact_rabbitmq_nodename_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
require 'spec_helper'

RSpec.configure do |config|
config.mock_with :rspec
end

describe Facter::Util::Fact do
before { Facter.clear }

Expand Down
4 changes: 0 additions & 4 deletions spec/unit/facter/util/fact_rabbitmq_version_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
require 'spec_helper'

RSpec.configure do |config|
config.mock_with :rspec
end

describe Facter::Util::Fact do
before do
Facter.clear
Expand Down
2 changes: 0 additions & 2 deletions templates/rabbitmq-server.service.d/limits.conf

This file was deleted.

0 comments on commit 5edf3f2

Please sign in to comment.