Refactor api service management

Drop validation of service name which is not implemented for
the other daemons, to simplify handling of the provided service name.

This allows us to more easily offload the service name definition to
hiera data in the near future.

Change-Id: Ib41ff01471217e02941991a11c71a846750b24f7
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
Takashi Kajinami
2025-09-27 00:36:40 +09:00
parent aff2408709
commit 270011b948
2 changed files with 26 additions and 46 deletions

View File

@@ -80,7 +80,7 @@ class watcher::api (
$bind_host = $facts['os_service_default'],
$workers = $facts['os_workers'],
$enable_ssl_api = $facts['os_service_default'],
$service_name = $watcher::params::api_service_name,
String[1] $service_name = $watcher::params::api_service_name,
Boolean $create_db_schema = false,
Boolean $upgrade_db = false,
$auth_strategy = 'keystone',
@@ -107,37 +107,35 @@ class watcher::api (
}
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
case $service_name {
'httpd': {
Service <| title == 'httpd' |> { tag +> 'watcher-service' }
if $service_name == $watcher::params::api_service_name {
# NOTE(danpawlik) Watcher doesn't support db_sync command.
service { 'watcher-api':
ensure => $service_ensure,
name => $watcher::params::api_service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
tag => ['watcher-service'],
service { 'watcher-api':
ensure => 'stopped',
name => $watcher::params::api_service_name,
enable => false,
tag => ['watcher-service'],
}
# we need to make sure watcher-api/eventlet is stopped before trying to start apache
Service['watcher-api'] -> Service['httpd']
}
} elsif $service_name == 'httpd' {
Service <| title == 'httpd' |> { tag +> 'watcher-service' }
default: {
$service_ensure = $enabled ? {
true => 'running',
default => 'stopped',
}
service { 'watcher-api':
ensure => 'stopped',
name => $watcher::params::api_service_name,
enable => false,
tag => ['watcher-service'],
service { 'watcher-api':
ensure => $service_ensure,
name => $service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
tag => ['watcher-service'],
}
}
# we need to make sure watcher-api/eventlet is stopped before trying to start apache
Service['watcher-api'] -> Service[$service_name]
} else {
fail("Invalid service_name. Either watcher/openstack-watcher-api for running \
as a standalone service, or httpd for being run by a httpd server")
}
}

View File

@@ -94,24 +94,6 @@ describe 'watcher::api' do
)
end
end
context 'when service_name is not valid' do
before do
params.merge!({ :service_name => 'foobar' })
end
let :pre_condition do
"include apache
include watcher::db
class { 'watcher': }
class { 'watcher::keystone::authtoken':
password => 'a_big_secret',
}"
end
it_raises 'a Puppet::Error', /Invalid service_name/
end
end
on_supported_os({