Simplify the lma_collector::service class

The lma_collector::service class is a private class that doesn't need
configuration parameters.

Change-Id: Iae78f4a94f19858d045f1d6bc1ad4a1cf5bd912a
This commit is contained in:
Éric Lemoine 2016-01-22 13:23:03 +01:00
parent 9989f9c79d
commit 0c8c2df236
2 changed files with 34 additions and 38 deletions

View File

@ -23,44 +23,13 @@
# }
#
#
class lma_collector::service (
$service_name = $::lma_collector::params::service_name,
$service_enable = true,
$service_ensure = 'running',
$service_manage = true,
$provider = undef,
) {
# The base class must be included first because parameter defaults depend on it
if ! defined(Class['lma_collector::params']) {
fail('You must include the lma_collector::params class before using lma_collector::service')
class lma_collector::service {
include lma_collector::params
service { $lma_collector::params::service_name:
ensure => 'running',
enable => true,
}
validate_bool($service_enable)
validate_bool($service_manage)
case $service_ensure {
true, false, 'running', 'stopped': {
$_service_ensure = $service_ensure
}
default: {
$_service_ensure = undef
}
}
if $service_manage {
if $provider {
service { 'lma_collector':
ensure => $_service_ensure,
name => $service_name,
enable => $service_enable,
provider => $provider,
}
} else {
service { 'lma_collector':
ensure => $_service_ensure,
name => $service_name,
enable => $service_enable,
}
}
}
}

View File

@ -0,0 +1,27 @@
# Copyright 2016 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
require 'spec_helper'
describe 'lma_collector::service' do
let(:facts) do
{:kernel => 'Linux', :operatingsystem => 'Ubuntu',
:osfamily => 'Debian'}
end
describe 'default params' do
it { is_expected.to contain_service('lma_collector') \
.with({'ensure' => 'running', 'enable' => true}) }
end
end