Skip to content

Commit

Permalink
Merge pull request #434 from kajinamit/c9-conf-dir
Browse files Browse the repository at this point in the history
CentOS9/RHEL9: Migrate configuration files to /etc/redis
  • Loading branch information
ekohl committed Feb 7, 2022
2 parents f393150 + f1298f1 commit dee5d31
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 64 deletions.
41 changes: 25 additions & 16 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,31 @@
$sentinel_pid_file = "/var/opt/rh/${scl}/run/redis-sentinel.pid"
$sentinel_log_file = "/var/opt/rh/${scl}/log/redis/sentinel.log"
} else {
$config_dir = '/etc/redis'
$config_file = '/etc/redis.conf'
$config_file_orig = '/etc/redis.conf.puppet'
$log_dir = '/var/log/redis'
$package_name = 'redis'
$pid_file = '/var/run/redis_6379.pid'
$service_name = 'redis'
$workdir = '/var/lib/redis'
$bin_path = '/usr/bin'

$sentinel_config_file = '/etc/redis-sentinel.conf'
$sentinel_config_file_orig = '/etc/redis-sentinel.conf.puppet'
$sentinel_service_name = 'redis-sentinel'
$sentinel_package_name = 'redis'
$sentinel_pid_file = '/var/run/redis/redis-sentinel.pid'
$sentinel_log_file = '/var/log/redis/sentinel.log'
$config_dir = '/etc/redis'
if (versioncmp($facts['os']['release']['major'], '9') >= 0) {
$config_file = '/etc/redis/redis.conf'
$config_file_orig = '/etc/redis/redis.conf.puppet'
} else {
$config_file = '/etc/redis.conf'
$config_file_orig = '/etc/redis.conf.puppet'
}
$log_dir = '/var/log/redis'
$package_name = 'redis'
$pid_file = '/var/run/redis_6379.pid'
$service_name = 'redis'
$workdir = '/var/lib/redis'
$bin_path = '/usr/bin'
if (versioncmp($facts['os']['release']['major'], '9') >= 0) {
$sentinel_config_file = '/etc/redis/sentinel.conf'
$sentinel_config_file_orig = '/etc/redis/sentinel.conf.puppet'
} else {
$sentinel_config_file = '/etc/redis-sentinel.conf'
$sentinel_config_file_orig = '/etc/redis-sentinel.conf.puppet'
}
$sentinel_service_name = 'redis-sentinel'
$sentinel_package_name = 'redis'
$sentinel_pid_file = '/var/run/redis/redis-sentinel.pid'
$sentinel_log_file = '/var/log/redis/sentinel.log'
}
}

Expand Down
6 changes: 4 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"7",
"8"
"8",
"9"
]
},
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"7",
"8"
"8",
"9"
]
},
{
Expand Down
38 changes: 20 additions & 18 deletions spec/acceptance/redis_cli_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,33 @@
apply_manifest(pp, catch_changes: true)
end

describe 'ping' do
let(:params) { 'command="ping"' }
unless fact('os.family') == 'RedHat' && fact('os.release.major').to_i >= 9
describe 'ping' do
let(:params) { 'command="ping"' }

it 'execute ping' do
is_expected.to match(%r{{\s*"status":\s*"PONG"\s*}})
is_expected.to match(%r{Ran on 1 target in .+ sec})
it 'execute ping' do
is_expected.to match(%r{{\s*"status":\s*"PONG"\s*}})
is_expected.to match(%r{Ran on 1 target in .+ sec})
end
end
end

describe 'security' do
describe 'command with semi colon' do
let(:params) { 'command="ping; cat /etc/passwd"' }
describe 'security' do
describe 'command with semi colon' do
let(:params) { 'command="ping; cat /etc/passwd"' }

it 'stops script injections and escapes' do
is_expected.to match(%r!{\s*"status":\s*"ERR unknown command ('|`)ping; cat /etc/passwd('|`)!)
is_expected.to match(%r{Ran on 1 target in .+ sec})
it 'stops script injections and escapes' do
is_expected.to match(%r!{\s*"status":\s*"ERR unknown command ('|`)ping; cat /etc/passwd('|`)!)
is_expected.to match(%r{Ran on 1 target in .+ sec})
end
end
end

describe 'command with double ampersand' do
let(:params) { 'command="ping && cat /etc/passwd"' }
describe 'command with double ampersand' do
let(:params) { 'command="ping && cat /etc/passwd"' }

it 'stops script injections and escapes' do
is_expected.to match(%r!{\s*"status":\s*"ERR unknown command ('|`)ping && cat /etc/passwd('|`)!)
is_expected.to match(%r{Ran on 1 target in .+ sec})
it 'stops script injections and escapes' do
is_expected.to match(%r!{\s*"status":\s*"ERR unknown command ('|`)ping && cat /etc/passwd('|`)!)
is_expected.to match(%r{Ran on 1 target in .+ sec})
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@

describe 'redis::instance example' do
instances = [6379, 6380, 6381, 6382]
case fact('osfamily')
when 'Debian'
config_path = '/etc/redis'
redis_name = 'redis-server'
else
config_path = '/etc'
redis_name = 'redis'
end

config_path = case fact('os.family')
when 'Debian'
'/etc/redis'
when 'RedHat'
if fact('os.release.major').to_i >= 9
'/etc/redis'
else
'/etc'
end
else
'/etc'
end

redis_name = case fact('os.family')
when 'Debian'
'redis-server'
else
'redis'
end

it 'runs successfully' do
pp = <<-EOS
Expand Down
24 changes: 14 additions & 10 deletions spec/classes/redis_sentinel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
context "on #{os}" do
let(:facts) { facts }
let(:config_file_orig) do
case facts[:osfamily]
case facts[:os]['family']
when 'Archlinux'
'/etc/redis/redis-sentinel.conf.puppet'
when 'Debian'
Expand All @@ -15,15 +15,19 @@
when 'FreeBSD'
'/usr/local/etc/redis-sentinel.conf.puppet'
when 'RedHat'
'/etc/redis-sentinel.conf.puppet'
if facts[:os]['release']['major'].to_i > 8
'/etc/redis/sentinel.conf.puppet'
else
'/etc/redis-sentinel.conf.puppet'
end
end
end

let(:pidfile) do
if facts[:operatingsystem] == 'Ubuntu'
if facts[:os]['name'] == 'Ubuntu'
'/var/run/sentinel/redis-sentinel.pid'
elsif facts[:operatingsystem] == 'Debian'
facts[:operatingsystemmajrelease] == '9' ? '/var/run/redis/redis-sentinel.pid' : '/run/sentinel/redis-sentinel.pid'
elsif facts[:os]['name'] == 'Debian'
facts[:os]['release']['major'].to_i == 9 ? '/var/run/redis/redis-sentinel.pid' : '/run/sentinel/redis-sentinel.pid'
else
'/var/run/redis/redis-sentinel.pid'
end
Expand All @@ -45,8 +49,8 @@
let(:expected_content) do
<<CONFIG
port 26379
dir #{facts[:osfamily] == 'Debian' ? '/var/lib/redis' : '/tmp'}
daemonize #{facts[:osfamily] == 'RedHat' ? 'no' : 'yes'}
dir #{facts[:os]['family'] == 'Debian' ? '/var/lib/redis' : '/tmp'}
daemonize #{facts[:os]['family'] == 'RedHat' ? 'no' : 'yes'}
pidfile #{pidfile}
protected-mode yes
Expand All @@ -56,7 +60,7 @@
sentinel failover-timeout mymaster 180000
loglevel notice
logfile #{facts[:osfamily] == 'Debian' ? '/var/log/redis/redis-sentinel.log' : '/var/log/redis/sentinel.log'}
logfile #{facts[:os]['family'] == 'Debian' ? '/var/log/redis/redis-sentinel.log' : '/var/log/redis/sentinel.log'}
CONFIG
end

Expand Down Expand Up @@ -109,7 +113,7 @@ class { 'redis':
bind 192.0.2.10
port 26379
dir /tmp/redis
daemonize #{facts[:osfamily] == 'RedHat' ? 'no' : 'yes'}
daemonize #{facts[:os]['family'] == 'RedHat' ? 'no' : 'yes'}
pidfile #{pidfile}
protected-mode no
Expand Down Expand Up @@ -153,7 +157,7 @@ class { 'redis':
bind 192.0.2.10 192.168.1.1
port 26379
dir /tmp/redis
daemonize #{facts[:osfamily] == 'RedHat' ? 'no' : 'yes'}
daemonize #{facts[:os]['family'] == 'RedHat' ? 'no' : 'yes'}
pidfile #{pidfile}
protected-mode yes
Expand Down
16 changes: 10 additions & 6 deletions spec/classes/redis_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
require 'spec_helper'

describe 'redis' do
let(:package_name) { facts[:osfamily] == 'Debian' ? 'redis-server' : 'redis' }
let(:package_name) { facts[:os]['family'] == 'Debian' ? 'redis-server' : 'redis' }
let(:service_name) { package_name }
let(:config_file) do
case facts[:osfamily]
case facts[:os]['family']
when 'Archlinux', 'Debian'
'/etc/redis/redis.conf'
when 'FreeBSD'
'/usr/local/etc/redis.conf'
when 'RedHat'
'/etc/redis.conf'
if facts[:os]['release']['major'].to_i > 8
'/etc/redis/redis.conf'
else
'/etc/redis.conf'
end
end
end
let(:config_file_orig) { "#{config_file}.puppet" }
Expand All @@ -35,7 +39,7 @@
with_content(%r{logfile /var/log/redis/redis\.log}).
without_content(%r{undef})

if facts[:osfamily] == 'FreeBSD'
if facts[:os]['family'] == 'FreeBSD'
is_expected.to contain_file(config_file_orig).
with_content(%r{dir /var/db/redis}).
with_content(%r{pidfile /var/run/redis/redis\.pid})
Expand All @@ -44,7 +48,7 @@

it { is_expected.to contain_service(service_name).with_ensure('running').with_enable('true') }

context 'with SCL', if: facts[:osfamily] == 'RedHat' && facts[:operatingsystemmajrelease] < '8' do
context 'with SCL', if: facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i < 8 do
let(:pre_condition) do
<<-PUPPET
class { 'redis::globals':
Expand Down Expand Up @@ -470,7 +474,7 @@ class { 'redis::globals':
describe 'with parameter: manage_repo' do
let(:params) { { manage_repo: true } }

if facts[:osfamily] == 'RedHat' && facts[:operatingsystemmajrelease].to_i <= 7
if facts[:osfamily] == 'RedHat' && facts[:os]['release']['major'].to_i <= 7
it { is_expected.to contain_class('epel') }
else
it { is_expected.not_to contain_class('epel') }
Expand Down
8 changes: 6 additions & 2 deletions spec/defines/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ class { 'redis':
context 'with app2 title' do
let(:title) { 'app2' }
let(:config_file) do
case facts[:osfamily]
case facts[:os]['family']
when 'RedHat'
'/etc/redis-server-app2.conf'
if facts[:os]['release']['major'].to_i > 8
'/etc/redis/redis-server-app2.conf'
else
'/etc/redis-server-app2.conf'
end
when 'FreeBSD'
'/usr/local/etc/redis/redis-server-app2.conf'
when 'Debian'
Expand Down
8 changes: 6 additions & 2 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
require 'voxpupuli/acceptance/spec_helper_acceptance'

configure_beaker do |host|
if fact_on(host, 'osfamily') == 'RedHat' && fact_on(host, 'operatingsystemmajrelease') == '7'
if fact_on(host, 'osfamily') == 'RedHat' && fact_on(host, 'operatingsystemmajrelease').to_i == 7
install_module_from_forge_on(host, 'puppet/epel', '>= 3.0.0')
end
host.install_package('puppet-bolt')
unless fact_on(host, 'osfamily') == 'RedHat' && fact_on(host, 'operatingsystemmajrelease').to_i >= 9
# puppet-bolt rpm for CentOS 9 is not yet available
# https://tickets.puppetlabs.com/browse/MODULES-11275
host.install_package('puppet-bolt')
end
end

0 comments on commit dee5d31

Please sign in to comment.