Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Added manage_service option #27

Merged
merged 1 commit into from
Feb 8, 2017
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
14 changes: 8 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class puppetserver(
$version = 'present',
$enable = true,
$start = true,
$package = 'puppetserver',
$config = {},
class puppetserver (
$version = 'present',
$enable = true,
$start = true,
$package = 'puppetserver',
$service = 'puppetserver',
$manage_service = true,
$config = {},
) {
anchor { 'puppetserver::begin': } ->
class { '::puppetserver::install': } ->
Expand Down
17 changes: 10 additions & 7 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
class puppetserver::service {
$ensure = $::puppetserver::start ? {
true => running,
default => stopped,
}
service { 'puppetserver':
ensure => $ensure,
enable => $::puppetserver::enable,
if $::puppetserver::manage_service {
$ensure = $::puppetserver::start ? {
true => running,
default => stopped,
}

service { $::puppetserver::service:
ensure => $ensure,
enable => $::puppetserver::enable,
}
}
}
3 changes: 3 additions & 0 deletions spec/classes/puppetserver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
context 'with defaults for all parameters' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppetserver') }
it { is_expected.to contain_class('puppetserver::install') }
it { is_expected.to contain_class('puppetserver::config') }
it { is_expected.to contain_class('puppetserver::service') }
end
end
end
Expand Down
73 changes: 73 additions & 0 deletions spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require 'spec_helper'

describe 'puppetserver::service' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

context 'with defaults for all parameters' do
let(:pre_condition) do
"class { 'puppetserver': }"
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppetserver::service') }
it { is_expected.to contain_service('puppetserver').with('ensure' => 'running') }
it { is_expected.to contain_service('puppetserver').with('enable' => true) }
end

context 'with custom service name' do
let(:pre_condition) do
"class { 'puppetserver':
service => 'foo',
}"
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppetserver::service') }
it { is_expected.to contain_service('foo').with('ensure' => 'running') }
it { is_expected.to contain_service('foo').with('enable' => true) }
end

context 'with service disabled' do
let(:pre_condition) do
"class { 'puppetserver':
enable => false,
}"
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppetserver::service') }
it { is_expected.to contain_service('puppetserver').with('ensure' => 'running') }
it { is_expected.to contain_service('puppetserver').with('enable' => false) }
end

context 'with service stopped' do
let(:pre_condition) do
"class { 'puppetserver':
start => false,
}"
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppetserver::service') }
it { is_expected.to contain_service('puppetserver').with('ensure' => 'stopped') }
it { is_expected.to contain_service('puppetserver').with('enable' => true) }
end

context 'with service not managed' do
let(:pre_condition) do
"class { 'puppetserver':
manage_service => false,
}"
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppetserver::service') }
it { is_expected.not_to contain_service('puppetserver') }
end
end
end
end