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: Iaaff77cd9fef2bbd42b5b08eeb5561129d89fab5
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
Takashi Kajinami
2025-09-27 00:41:55 +09:00
parent 705eb94c0b
commit eb2c26940a
2 changed files with 31 additions and 37 deletions

View File

@@ -57,7 +57,7 @@ class cloudkitty::api (
$port = $facts['os_service_default'],
$pecan_debug = $facts['os_service_default'],
Boolean $sync_db = true,
$service_name = 'httpd',
String[1] $service_name = 'httpd',
$enable_proxy_headers_parsing = $facts['os_service_default'],
$max_request_body_size = $facts['os_service_default'],
) {
@@ -77,37 +77,38 @@ class cloudkitty::api (
}
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
case $service_name {
'httpd': {
Service <| title == 'httpd' |> { tag +> 'cloudkitty-service' }
if $service_name == $cloudkitty::params::api_service_name {
service { 'cloudkitty-api':
enable => $enabled,
name => 'cloudkitty-api',
hasstatus => true,
hasrestart => true,
tag => 'cloudkitty-service',
service { 'cloudkitty-api':
ensure => 'stopped',
name => $cloudkitty::params::api_service_name,
enable => false,
tag => 'cloudkitty-service',
}
# we need to make sure cloudkitty-api/eventlet is stopped before trying to start apache
Service['cloudkitty-api'] -> Service['httpd']
Cloudkitty_api_paste_ini<||> ~> Service['httpd']
}
default: {
$service_ensure = $enabled ? {
true => 'running',
default => 'stopped',
}
Cloudkitty_api_paste_ini<||> ~> Service['cloudkitty-api']
} elsif $service_name == 'httpd' {
service { 'cloudkitty-api':
ensure => 'stopped',
name => $cloudkitty::params::api_service_name,
enable => false,
tag => 'cloudkitty-service',
service { 'cloudkitty-api':
ensure => $service_ensure,
name => $service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
tag => 'cloudkitty-service',
}
Cloudkitty_api_paste_ini<||> ~> Service['cloudkitty-api']
}
Service <| title == 'httpd' |> { tag +> 'cloudkitty-service' }
# we need to make sure cloudkitty-api/eventlet is stopped before trying to start apache
Service['cloudkitty-api'] -> Service[$service_name]
Cloudkitty_api_paste_ini<||> ~> Service[$service_name]
} else {
fail('Invalid service_name. Only httpd for being run by a httpd server')
}
}

View File

@@ -67,8 +67,9 @@ describe 'cloudkitty::api' do
it 'configures cloudkitty-api service as standalone' do
is_expected.to contain_service('cloudkitty-api').with(
:enable => true,
:ensure => 'running',
:name => platform_params[:api_service_name],
:enable => true,
:hasstatus => true,
:hasrestart => true,
:tag => 'cloudkitty-service',
@@ -76,14 +77,6 @@ describe 'cloudkitty::api' do
end
end
context 'when service_name is not valid' do
before do
params.merge!({ :service_name => 'foobar' })
end
it_raises 'a Puppet::Error', /Invalid service_name/
end
context 'with $sync_db set to false in ::cloudkitty' do
before do
params.merge!({