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: I90a78929510ca3917d3ba32576fa123d512388b9
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
Takashi Kajinami
2025-09-27 00:07:42 +09:00
parent 5e7533b8c3
commit b9b2448b03
2 changed files with 34 additions and 52 deletions

View File

@@ -283,7 +283,7 @@ class glance::api (
$paste_deploy_config_file = $facts['os_service_default'],
Boolean $manage_service = true,
Boolean $enabled = true,
$service_name = $glance::params::api_service_name,
String[1] $service_name = $glance::params::api_service_name,
$show_image_direct_url = $facts['os_service_default'],
Boolean $purge_config = false,
$enforce_secure_rbac = $facts['os_service_default'],
@@ -568,43 +568,43 @@ enabled_backends instead.')
}
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
case $service_name {
'httpd': {
Service <| title == 'httpd' |> { tag +> 'glance-service' }
if $service_name == $glance::params::api_service_name {
service { 'glance-api':
ensure => $service_ensure,
name => $glance::params::api_service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
tag => 'glance-service',
service { 'glance-api':
ensure => 'stopped',
name => $glance::params::api_service_name,
enable => false,
tag => 'glance-service',
}
# we need to make sure glance-api/eventlet is stopped before trying to start apache
Service['glance-api'] -> Service['httpd']
# On any paste-api.ini config change, we must restart Glance API.
Glance_api_paste_ini<||> ~> Service['httpd']
}
default: {
$service_ensure = $enabled ? {
true => 'running',
default => 'stopped',
}
# On any paste-api.ini config change, we must restart Glance API.
Glance_api_paste_ini<||> ~> Service['glance-api']
# On any uwsgi config change, we must restart Glance API.
Glance_api_uwsgi_config<||> ~> Service['glance-api']
} elsif $service_name == 'httpd' {
service { 'glance-api':
ensure => 'stopped',
name => $glance::params::api_service_name,
enable => false,
tag => 'glance-service',
service { 'glance-api':
ensure => $service_ensure,
name => $service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
tag => 'glance-service',
}
# On any paste-api.ini config change, we must restart Glance API.
Glance_api_paste_ini<||> ~> Service['glance-api']
# On any uwsgi config change, we must restart Glance API.
Glance_api_uwsgi_config<||> ~> Service['glance-api']
}
Service <| title == 'httpd' |> { tag +> 'glance-service' }
# we need to make sure glance-api/eventlet is stopped before trying to start apache
Service['glance-api'] -> Service[$service_name]
# On any paste-api.ini config change, we must restart Glance API.
Glance_api_paste_ini<||> ~> Service[$service_name]
} else {
fail("Invalid service_name. ${glance::params::api_service_name} for \
running as a standalone service, or httpd for being run by a httpd server")
}
}
}

View File

@@ -272,24 +272,6 @@ describe 'glance::api' do
end
end
context 'when service_name is not valid' do
let :params do
{
:service_name => 'foobar'
}
end
let :pre_condition do
"include apache
class { 'glance': }
class { 'glance::api::authtoken':
password => 'foo',
}"
end
it_raises 'a Puppet::Error', /Invalid service_name/
end
describe 'with platform default oslo concurrency lock_path' do
it { is_expected.to contain_oslo__concurrency('glance_api_config').with(
:lock_path => platform_params[:lock_path]