Merge "Drop support for standalone api service in CentOS/Ubuntu"

This commit is contained in:
Zuul 2021-04-27 11:05:03 +00:00 committed by Gerrit Code Review
commit a6d537223b
4 changed files with 104 additions and 58 deletions

View File

@ -86,7 +86,8 @@ class aodh::api (
}
if $manage_service {
if $service_name == $::aodh::params::api_service_name {
$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 {
@ -95,7 +96,7 @@ class aodh::api (
service { 'aodh-api':
ensure => $service_ensure,
name => $::aodh::params::api_service_name,
name => $api_service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
@ -103,19 +104,20 @@ class aodh::api (
}
} elsif $service_name == 'httpd' {
include apache::params
service { 'aodh-api':
ensure => 'stopped',
name => $::aodh::params::api_service_name,
enable => false,
tag => 'aodh-service',
}
Service <| title == 'httpd' |> { tag +> 'aodh-service' }
# we need to make sure aodh-api/eventlet is stopped before trying to start apache
Service['aodh-api'] -> Service[$service_name]
if $api_service_name != 'httpd' {
service { 'aodh-api':
ensure => 'stopped',
name => $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[$service_name]
}
} else {
fail("Invalid service_name. Either aodh/openstack-aodh-api for running \
as a standalone service, or httpd for being run by a httpd server")
fail('Invalid service_name.')
}
}

View File

@ -12,7 +12,7 @@ class aodh::params {
'RedHat': {
$common_package_name = 'openstack-aodh-common'
$api_package_name = 'openstack-aodh-api'
$api_service_name = 'openstack-aodh-api'
$api_service_name = 'httpd'
$notifier_package_name = 'openstack-aodh-notifier'
$notifier_service_name = 'openstack-aodh-notifier'
$evaluator_package_name = 'openstack-aodh-evaluator'
@ -28,7 +28,14 @@ class aodh::params {
'Debian': {
$common_package_name = 'aodh-common'
$api_package_name = 'aodh-api'
$api_service_name = 'aodh-api'
case $::operatingsystem {
'Ubuntu': {
$api_service_name = 'httpd'
}
default: {
$api_service_name = 'aodh-api'
}
}
$notifier_package_name = 'aodh-notifier'
$notifier_service_name = 'aodh-notifier'
$evaluator_package_name = 'aodh-evaluator'

View File

@ -0,0 +1,6 @@
---
upgrade:
- |
The ``aodh::api`` class no longer supports standalone api service in
CentOS and Ubuntu, because these 2 distros don't provide standalone api
service and require that wsgi is used to run the api service.

View File

@ -3,7 +3,8 @@ require 'spec_helper'
describe 'aodh::api' do
let :pre_condition do
"class { 'aodh': }
"include apache
class { 'aodh': }
include aodh::db
class { 'aodh::keystone::authtoken':
password => 'a_big_secret',
@ -17,7 +18,7 @@ describe 'aodh::api' do
}
end
shared_examples 'aodh::api' do
shared_examples 'aodh-api' do
it { is_expected.to contain_class('aodh::deps') }
it { is_expected.to contain_class('aodh::params') }
@ -41,27 +42,6 @@ describe 'aodh::api' do
)
end
[{:enabled => true}, {:enabled => false}].each do |param_hash|
context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do
before do
params.merge!(param_hash)
end
it 'configures aodh-api service' do
is_expected.to contain_service('aodh-api').with(
:ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped',
:name => platform_params[:api_service_name],
:enable => params[:enabled],
:hasstatus => true,
:hasrestart => true,
: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 sync_db set to true' do
before do
params.merge!(
@ -111,6 +91,64 @@ 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
[{:enabled => true}, {:enabled => false}].each do |param_hash|
context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do
before do
params.merge!(param_hash)
end
it 'configures aodh-api service' do
is_expected.to contain_service('aodh-api').with(
:ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped',
:name => platform_params[:api_service_name],
:enable => params[:enabled],
:hasstatus => true,
:hasrestart => true,
: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
before do
params.merge!({
@ -146,23 +184,6 @@ describe 'aodh::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 aodh::db
class { 'aodh': }
class { 'aodh::keystone::authtoken':
password => 'a_big_secret',
}"
end
it_raises 'a Puppet::Error', /Invalid service_name/
end
end
on_supported_os({
@ -179,15 +200,25 @@ describe 'aodh::api' do
let(:platform_params) do
case facts[:osfamily]
when 'Debian'
{ :api_package_name => 'aodh-api',
:api_service_name => 'aodh-api' }
if facts[:operatingsystem] == 'Ubuntu'
{ :api_package_name => 'aodh-api',
:api_service_name => 'httpd' }
else
{ :api_package_name => 'aodh-api',
:api_service_name => 'aodh-api' }
end
when 'RedHat'
{ :api_package_name => 'openstack-aodh-api',
:api_service_name => 'openstack-aodh-api' }
:api_service_name => 'httpd' }
end
end
it_behaves_like 'aodh::api'
if facts[:osfamily] == 'Debian' and facts[:operatingsystem] != '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