Skip to content

Commit

Permalink
Use modern fact names
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Nov 28, 2019
1 parent 81bd278 commit 174f2b1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
8 changes: 4 additions & 4 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
contain redis::ulimit
}

$service_provider_lookup = pick(getvar('service_provider'), false)
$service_provider_lookup = fact('service_provider')

unless $facts['osfamily'] == 'Debian' or $service_provider_lookup == 'systemd' {
unless $facts['os']['family'] == 'Debian' or $service_provider_lookup == 'systemd' {
file { '/var/run/redis':
ensure => 'directory',
owner => $redis::config_owner,
Expand All @@ -53,10 +53,10 @@
}

# Adjust /etc/default/redis-server on Debian systems
case $::osfamily {
case $facts['os']['family'] {
'Debian': {
file { '/etc/default/redis-server':
ensure => present,
ensure => file,
group => $redis::config_group,
mode => $redis::config_file_mode,
owner => $redis::config_owner,
Expand Down
2 changes: 1 addition & 1 deletion manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
file { "/etc/init.d/${redis_server_name}":
ensure => file,
mode => '0755',
content => template("redis/service_templates/redis.${::osfamily}.erb"),
content => template("redis/service_templates/redis.${facts['os']['family']}.erb"),
}

if $title != 'default' {
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @summary This class provides a number of parameters.
# @api private
class redis::params {
case $::osfamily {
case $facts['os']['family'] {
'Debian': {
$config_dir = '/etc/redis'
$config_dir_mode = '0755'
Expand Down Expand Up @@ -137,7 +137,7 @@
$minimum_version = '3.2.4'
}
default: {
fail "Operating system ${::operatingsystem} is not supported yet."
fail "Operating system ${facts['os']['name']} is not supported yet."
}
}
}
2 changes: 1 addition & 1 deletion manifests/sentinel.pp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@

require 'redis'

if $facts['osfamily'] == 'Debian' {
if $facts['os']['family'] == 'Debian' {
package { $package_name:
ensure => $package_ensure,
before => File[$config_file_orig],
Expand Down
4 changes: 2 additions & 2 deletions manifests/ulimit.pp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
],
}
} else {
case $facts['osfamily'] {
case $facts['os']['family'] {
'Debian': {
augeas { 'redis ulimit':
context => '/files/etc/default/redis-server',
Expand All @@ -68,7 +68,7 @@
}
}
default: {
warning("Not sure how to set ULIMIT on non-systemd OSFamily ${facts['osfamily']}, PR's welcome")
warning("Not sure how to set ULIMIT on non-systemd OSFamily ${facts['os']['family']}, PR's welcome")
}
}
}
Expand Down
29 changes: 27 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
RSpec.configure do |c|
c.mock_with :mocha
end

require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts
Expand Down Expand Up @@ -53,6 +57,11 @@ def redis_service_file(service_name: redis_service_name, service_provider: nil)
end
end

if ENV['DEBUG']
Puppet::Util::Log.level = :debug
Puppet::Util::Log.newdestination(:console)
end

add_custom_fact :service_provider, (lambda do |_os, facts|
case facts[:osfamily].downcase
when 'archlinux'
Expand All @@ -78,5 +87,21 @@ def redis_service_file(service_name: redis_service_name, service_provider: nil)
end
end)

# Include code coverage report for all our specs
at_exit { RSpec::Puppet::Coverage.report! }
RSpec.configure do |c|
# getting the correct facter version is tricky. We use facterdb as a source to mock facts
# see https://github.com/camptocamp/facterdb
# people might provide a specific facter version. In that case we use it.
# Otherwise we need to match the correct facter version to the used puppet version.
# as of 2019-10-31, puppet 5 ships facter 3.11 and puppet 6 ships facter 3.14
# https://puppet.com/docs/puppet/5.5/about_agent.html
c.default_facter_version = if ENV['FACTERDB_FACTS_VERSION']
ENV['FACTERDB_FACTS_VERSION']
else
Gem::Dependency.new('', ENV['PUPPET_VERSION']).match?('', '5') ? '3.11.0' : '3.14.0'
end

# Coverage generation
c.after(:suite) do
RSpec::Puppet::Coverage.report!
end
end

0 comments on commit 174f2b1

Please sign in to comment.