Skip to content

Commit

Permalink
Fix manage_service_file variable
Browse files Browse the repository at this point in the history
Fixes #308
Fixes #310

The manage_service_file is configured incorrectly and doesn't
allow for overriding the value with hieradata.  Updaing the init.pp
class params allows the file to be passed in.

The filename for the systemd default service was incorrectly set
as the variable is undefined.
  • Loading branch information
CallumBanbery committed May 9, 2019
1 parent 16a52af commit 5858ca1
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
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' {
$redis_server_name = $::redis::service_name
$redis_file_name_orig = $config_file_orig
$redis_file_name = $config_file
} else {
Expand Down
1 change: 1 addition & 0 deletions spec/acceptance/nodesets/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bundler: failed to load command: beaker-hostgenerator (/home/callum/otb/malkovich/modules/redis/.vendor/ruby/2.3.0/bin/beaker-hostgenerator)
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
27 changes: 26 additions & 1 deletion spec/defines/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
let :title do
'app2'
end
let(:service_file) { redis_service_file(service_name: title, service_provider: facts[:service_provider]) }

describe 'os-dependent items' do
context 'on Ubuntu systems' do
Expand All @@ -26,6 +27,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 +47,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 +70,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 @@ -70,7 +89,13 @@
it { is_expected.to contain_file('/var/lib/redis/redis-server-app2') }
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}) }
it { is_expected.to contain_file(service_file).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
23 changes: 17 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def manifest_vars
when 'RedHat'
vars[:package_name] = 'redis'
vars[:service_name] = 'redis'
vars[:config_file] = '/etc/redis.conf'
vars[:config_file_orig] = '/etc/redis.conf.puppet'
vars[:ppa_repo] = nil
when 'FreeBSD',
Expand All @@ -76,12 +77,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

0 comments on commit 5858ca1

Please sign in to comment.