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: I179246eabd540e7c905d67eb3f99840809c99e4e
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
Takashi Kajinami
2025-08-21 14:12:14 +09:00
parent 07ff154c4d
commit c8b7299299
3 changed files with 59 additions and 107 deletions

View File

@@ -84,44 +84,43 @@ class aodh::api (
}
if $manage_service {
$api_service_name = $aodh::params::api_service_name
if $api_service_name != 'httpd' and $service_name == $api_service_name {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
case $service_name {
'httpd': {
Service <| title == 'httpd' |> { tag +> 'aodh-service' }
service { 'aodh-api':
ensure => $service_ensure,
name => $api_service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
tag => 'aodh-service',
}
# On any paste-api.ini config change, we must restart Aodh API.
Aodh_api_paste_ini<||> ~> Service['aodh-api']
# On any uwsgi config change, we must restart Aodh API.
Aodh_api_uwsgi_config<||> ~> Service['aodh-api']
} elsif $service_name == 'httpd' {
Service <| title == 'httpd' |> { tag +> 'aodh-service' }
if $api_service_name != 'httpd' {
service { 'aodh-api':
ensure => 'stopped',
name => $api_service_name,
enable => false,
tag => 'aodh-service',
if $aodh::params::api_service_name {
service { 'aodh-api':
ensure => 'stopped',
name => $aodh::params::api_service_name,
enable => false,
tag => 'aodh-service',
}
# we need to make sure aodh-api/eventlet is stopped before trying to start apache
Service['aodh-api'] -> Service['httpd']
}
# we need to make sure aodh-api/eventlet is stopped before trying to start apache
Service['aodh-api'] -> Service[$service_name]
}
# On any paste-api.ini config change, we must restart Aodh API.
Aodh_api_paste_ini<||> ~> Service[$service_name]
} else {
fail('Invalid service_name.')
# On any paste-api.ini config change, we must restart Aodh API.
Aodh_api_paste_ini<||> ~> Service['httpd']
}
default: {
$service_ensure = $enabled ? {
true => 'running',
default => 'stopped',
}
service { 'aodh-api':
ensure => $service_ensure,
name => $service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
tag => 'aodh-service',
}
# On any paste-api.ini config change, we must restart Aodh API.
Aodh_api_paste_ini<||> ~> Service['aodh-api']
# On any uwsgi config change, we must restart Aodh API.
Aodh_api_uwsgi_config<||> ~> Service['aodh-api']
}
}
}

View File

@@ -14,7 +14,7 @@ class aodh::params {
'RedHat': {
$common_package_name = 'openstack-aodh-common'
$api_package_name = 'openstack-aodh-api'
$api_service_name = 'httpd'
$api_service_name = undef
$notifier_package_name = 'openstack-aodh-notifier'
$notifier_service_name = 'openstack-aodh-notifier'
$evaluator_package_name = 'openstack-aodh-evaluator'
@@ -31,7 +31,7 @@ class aodh::params {
$api_package_name = 'aodh-api'
case $facts['os']['name'] {
'Ubuntu': {
$api_service_name = 'httpd'
$api_service_name = undef
}
default: {
$api_service_name = 'aodh-api'

View File

@@ -3,22 +3,21 @@ require 'spec_helper'
describe 'aodh::api' do
let :pre_condition do
"include apache
class { 'aodh': }
include aodh::db
class { 'aodh::keystone::authtoken':
password => 'a_big_secret',
}"
end
let :params do
{ :enabled => true,
:manage_service => true,
:package_ensure => 'latest',
<<-EOS
include apache
class { 'aodh': }
class { 'aodh::keystone::authtoken':
password => 'a_big_secret',
}
EOS
end
shared_examples 'aodh-api' do
let :params do
{
:service_name => 'httpd'
}
end
it { is_expected.to contain_class('aodh::deps') }
it { is_expected.to contain_class('aodh::params') }
@@ -26,7 +25,7 @@ describe 'aodh::api' do
it 'installs aodh-api package' do
is_expected.to contain_package('aodh-api').with(
:ensure => 'latest',
:ensure => 'present',
:name => platform_params[:api_package_name],
:tag => ['openstack', 'aodh-package'],
)
@@ -91,42 +90,12 @@ describe 'aodh::api' do
is_expected.to contain_aodh_config('api/gnocchi_external_domain_name').with_value('MyDomain')
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 aodh::db
class { 'aodh': }
class { 'aodh::keystone::authtoken':
password => 'a_big_secret',
}"
end
it_raises 'a Puppet::Error', /Invalid service_name/
end
end
shared_examples_for 'aodh-api without standalone service' do
let :pre_condition do
"include apache
include aodh::db
class { 'aodh': }
class {'aodh::keystone::authtoken':
password => 'password',
}"
end
it { is_expected.to_not contain_service('aodh-api') }
end
shared_examples 'aodh-api with standalone service' do
let :params do
{}
end
[{:enabled => true}, {:enabled => false}].each do |param_hash|
context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do
@@ -136,7 +105,7 @@ describe 'aodh::api' do
it 'configures aodh-api service' do
is_expected.to contain_service('aodh-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,
@@ -144,12 +113,10 @@ describe 'aodh::api' do
:tag => 'aodh-service',
)
end
it { is_expected.to contain_service('aodh-api').that_subscribes_to('Anchor[aodh::service::begin]')}
it { is_expected.to contain_service('aodh-api').that_notifies('Anchor[aodh::service::end]')}
end
end
context 'with disabled service managing' do
context 'with disabled service management' do
before do
params.merge!({
:manage_service => false,
@@ -166,21 +133,12 @@ describe 'aodh::api' do
params.merge!({ :service_name => 'httpd' })
end
let :pre_condition do
"include apache
include aodh::db
class { 'aodh': }
class { 'aodh::keystone::authtoken':
password => 'a_big_secret',
}"
end
it 'configures aodh-api service with Apache' do
is_expected.to contain_service('aodh-api').with(
:ensure => 'stopped',
:name => platform_params[:api_service_name],
:enable => false,
:tag => 'aodh-service',
:ensure => 'stopped',
:name => platform_params[:api_service_name],
:enable => false,
:tag => 'aodh-service',
)
end
end
@@ -198,25 +156,20 @@ describe 'aodh::api' do
case facts[:os]['family']
when 'Debian'
if facts[:os]['name'] == 'Ubuntu'
{ :api_package_name => 'aodh-api',
:api_service_name => 'httpd' }
{ :api_package_name => 'aodh-api' }
else
{ :api_package_name => 'aodh-api',
:api_service_name => 'aodh-api' }
end
when 'RedHat'
{ :api_package_name => 'openstack-aodh-api',
:api_service_name => 'httpd' }
{ :api_package_name => 'openstack-aodh-api' }
end
end
if facts[:os]['family'] == 'Debian' and facts[:os]['name'] != 'Ubuntu'
it_behaves_like 'aodh-api with standalone service'
else
it_behaves_like 'aodh-api without standalone service'
end
it_behaves_like 'aodh-api'
end
end
end