Do not define service resource when service management is disabled

Change-Id: I30d752928e2f76efbb711cff21a85e64f09f1215
This commit is contained in:
Takashi Kajinami 2022-02-10 16:43:05 +09:00
parent 9f113400cc
commit 536c44f8cf
6 changed files with 88 additions and 71 deletions

View File

@ -191,14 +191,6 @@ class watcher::api (
tag => ['openstack', 'watcher-package'],
}
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
}
if $create_db_schema {
include watcher::db::create_schema
}
@ -207,6 +199,13 @@ class watcher::api (
include watcher::db::upgrade
}
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
if $service_name == $::watcher::params::api_service_name {
# NOTE(danpawlik) Watcher doesn't support db_sync command.
service { 'watcher-api':
@ -235,6 +234,7 @@ class watcher::api (
fail("Invalid service_name. Either watcher/openstack-watcher-api for running \
as a standalone service, or httpd for being run by a httpd server")
}
}
if $enabled {
watcher_config {

View File

@ -62,7 +62,6 @@ class watcher::applier (
} else {
$service_ensure = 'stopped'
}
}
service { 'watcher-applier':
ensure => $service_ensure,
@ -72,6 +71,7 @@ class watcher::applier (
hasrestart => true,
tag => ['watcher-service'],
}
}
watcher_config {
'watcher_applier/workers': value => $applier_workers;

View File

@ -94,7 +94,6 @@ class watcher::decision_engine (
} else {
$service_ensure = 'stopped'
}
}
service { 'watcher-decision-engine':
ensure => $service_ensure,
@ -104,6 +103,7 @@ class watcher::decision_engine (
hasrestart => true,
tag => ['watcher-service'],
}
}
watcher_config {
'watcher_decision_engine/conductor_topic': value => $decision_engine_conductor_topic;

View File

@ -4,7 +4,6 @@ describe 'watcher::api' do
let :params do
{ :watcher_client_password => 'password',
:manage_service => true,
:enabled => true,
:package_ensure => 'latest',
}
@ -36,7 +35,7 @@ describe 'watcher::api' do
it 'configures watcher-api service' do
is_expected.to contain_service('watcher-api').with(
:ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped',
:ensure => params[:enabled] ? 'running' : 'stopped',
:name => platform_params[:api_service_name],
:enable => params[:enabled],
:hasstatus => true,
@ -63,20 +62,19 @@ describe 'watcher::api' do
before do
params.merge!({
:manage_service => false,
:enabled => false })
})
end
it 'configures watcher-api service' do
is_expected.to contain_service('watcher-api').with(
:ensure => nil,
:name => platform_params[:api_service_name],
:enable => false,
:hasstatus => true,
:hasrestart => true,
:tag => ['watcher-service',
'watcher-db-manage-create_schema',
'watcher-db-manage-upgrade'],
)
it 'should not configure watcher-api service' do
is_expected.to_not contain_service('watcher-api')
end
end
context 'with service disabled' do
before do
params.merge!({
:enabled => false
})
end
it 'should not configure the api configurations section when disabled' do
@ -86,7 +84,6 @@ describe 'watcher::api' do
is_expected.to_not contain_watcher_config('api/workers')
is_expected.to_not contain_watcher_config('api/enable_ssl_api')
end
end
context 'watcher clients auth section with default parameters' do

View File

@ -26,9 +26,7 @@ describe 'watcher::applier' do
[{:enabled => true}, {:enabled => false}].each do |param_hash|
context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do
let :params do
{ :enabled => true,
:manage_service => true,
}
{ :enabled => true, }
end
before do
params.merge!(param_hash)
@ -36,7 +34,7 @@ describe 'watcher::applier' do
it 'configures watcher applier service' do
is_expected.to contain_service('watcher-applier').with(
:ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped',
:ensure => params[:enabled] ? 'running' : 'stopped',
:name => platform_params[:applier_service_name],
:enable => params[:enabled],
:hasstatus => true,
@ -47,6 +45,18 @@ describe 'watcher::applier' do
end
end
context 'with disabled service managing' do
let :params do
{
:manage_service => false,
}
end
it 'should not configure watcher-applier service' do
is_expected.to_not contain_service('watcher-applier')
end
end
context 'with overridden parameters' do
let :params do
{

View File

@ -28,9 +28,7 @@ describe 'watcher::decision_engine' do
[{:enabled => true}, {:enabled => false}].each do |param_hash|
context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do
let :params do
{ :enabled => true,
:manage_service => true,
}
{ :enabled => true }
end
before do
params.merge!(param_hash)
@ -38,7 +36,7 @@ describe 'watcher::decision_engine' do
it 'configures watcher decision engine service' do
is_expected.to contain_service('watcher-decision-engine').with(
:ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped',
:ensure => params[:enabled] ? 'running' : 'stopped',
:name => platform_params[:decision_engine_service_name],
:enable => params[:enabled],
:hasstatus => true,
@ -49,6 +47,18 @@ describe 'watcher::decision_engine' do
end
end
context 'with disabled service managing' do
let :params do
{
:manage_service => false
}
end
it 'should not configure watcher-decision-engine service' do
is_expected.to_not contain_service('watcher-decision-engine')
end
end
context 'with overridden parameters' do
let :params do
{