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

Fix manage_service_file variable #309

Merged
merged 2 commits into from
May 10, 2019
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
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
Stdlib::Filemode $log_dir_mode = $::redis::params::log_dir_mode,
Stdlib::Absolutepath $log_file = $::redis::params::log_file,
$log_level = $::redis::params::log_level,
Boolean $manage_service_file = $::redis::params::manage_service_file,
Boolean $manage_package = $::redis::params::manage_package,
Boolean $manage_repo = $::redis::params::manage_repo,
$masterauth = $::redis::params::masterauth,
Expand Down
1 change: 1 addition & 0 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
) {

if $title == 'default' {
CallumBanbery marked this conversation as resolved.
Show resolved Hide resolved
$redis_server_name = $::redis::service_name
$redis_file_name_orig = $config_file_orig
$redis_file_name = $config_file
} else {
Expand Down
34 changes: 33 additions & 1 deletion spec/classes/redis_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
require 'spec_helper'

describe 'redis', type: :class do
let(:service_file) { redis_service_file(service_provider: facts[:service_provider]) }

on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge(redis_server_version: '3.2.3')
merged_facts = facts.merge(redis_server_version: '3.2.3')

if facts[:operatingsystem].casecmp('archlinux') == 0
merged_facts = merged_facts.merge(service_provider: 'systemd')
end

merged_facts
end

let(:package_name) { manifest_vars[:package_name] }
Expand Down Expand Up @@ -1191,6 +1199,30 @@
)
}
end

describe 'with parameter manage_service_file' do
let(:params) do
{
manage_service_file: true
}
end

it {
is_expected.to contain_file(service_file)
}
end

describe 'with parameter manage_service_file' do
let(:params) do
{
manage_service_file: false
}
end

it {
is_expected.not_to contain_file(service_file)
}
end
end
end
end
26 changes: 26 additions & 0 deletions spec/defines/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
let :title do
'app2'
end
let(:service_name) { redis_service_name(service_name: title) }
let(:service_file) { redis_service_file(service_name: service_name, service_provider: facts[:service_provider]) }

describe 'os-dependent items' do
context 'on Ubuntu systems' do
Expand All @@ -26,6 +28,12 @@
it { is_expected.to contain_service('redis-server-app2').with_enable('true') }
it { is_expected.to contain_file('/etc/init.d/redis-server-app2').with_content(%r{DAEMON_ARGS=/etc/redis/redis-server-app2\.conf}) }
it { is_expected.to contain_file('/etc/init.d/redis-server-app2').with_content(%r{PIDFILE=/var/run/redis/redis-server-app2\.pid}) }

context 'with default title' do
let(:title) { 'default' }

it { is_expected.to contain_file(service_file).with_content(%r{DAEMON_ARGS=/etc/redis/redis.conf}) }
end
end
context '16.04' do
let(:facts) do
Expand All @@ -40,6 +48,12 @@
it { is_expected.to contain_service('redis-server-app2').with_ensure('running') }
it { is_expected.to contain_service('redis-server-app2').with_enable('true') }
it { is_expected.to contain_file('/etc/systemd/system/redis-server-app2.service').with_content(%r{ExecStart=/usr/bin/redis-server /etc/redis/redis-server-app2\.conf}) }

context 'with default title' do
let(:title) { 'default' }

it { is_expected.to contain_file(service_file).with_content(%r{ExecStart=/usr/bin/redis-server /etc/redis/redis.conf}) }
end
end
end
context 'on CentOS systems' do
Expand All @@ -57,6 +71,12 @@
it { is_expected.to contain_service('redis-server-app2').with_enable('true') }
it { is_expected.to contain_file('/etc/init.d/redis-server-app2').with_content(%r{REDIS_CONFIG="/etc/redis-server-app2\.conf"}) }
it { is_expected.to contain_file('/etc/init.d/redis-server-app2').with_content(%r{pidfile="/var/run/redis/redis-server-app2\.pid"}) }

context 'with default title' do
let(:title) { 'default' }

it { is_expected.to contain_file(service_file).with_content(%r{REDIS_CONFIG="/etc/redis.conf"}) }
end
end
context '7' do
let(:facts) do
Expand All @@ -71,6 +91,12 @@
it { is_expected.to contain_service('redis-server-app2').with_ensure('running') }
it { is_expected.to contain_service('redis-server-app2').with_enable('true') }
it { is_expected.to contain_file('/etc/systemd/system/redis-server-app2.service').with_content(%r{ExecStart=/usr/bin/redis-server /etc/redis-server-app2\.conf}) }

context 'with default title' do
let(:title) { 'default' }

it { is_expected.to contain_file(service_file).with_content(%r{ExecStart=/usr/bin/redis-server /etc/redis.conf}) }
end
end
end
end
Expand Down
22 changes: 16 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,22 @@ def manifest_vars
vars
end

def centos_facts
{
operatingsystem: 'CentOS',
osfamily: 'RedHat',
puppetversion: '4.5.2'
}
def redis_service_name(service_name: 'default')
case service_name.to_s
when 'default'
manifest_vars[:service_name]
else
"#{manifest_vars[:service_name]}-#{service_name}"
end
end

def redis_service_file(service_name: redis_service_name, service_provider: nil)
case service_provider.to_s
when 'systemd'
"/etc/systemd/system/#{service_name}.service"
else
"/etc/init.d/#{service_name}"
end
end

def debian_facts
Expand Down