From a54de2bb6fbeec4748ab9692fdedc12ffccf83b5 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Fri, 26 Sep 2025 23:09:19 +0900 Subject: [PATCH] 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: Icb6c0c8db190c383fd55e32dd7c71d1f7c7c46a7 Signed-off-by: Takashi Kajinami --- manifests/api.pp | 64 ++++++++++++++++----------------- spec/classes/cinder_api_spec.rb | 16 --------- 2 files changed, 32 insertions(+), 48 deletions(-) diff --git a/manifests/api.pp b/manifests/api.pp index df41a663..0e0338b4 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -155,42 +155,42 @@ class cinder::api ( } if $manage_service { - if $enabled { - $ensure = 'running' - } else { - $ensure = 'stopped' - } + case $service_name { + 'httpd': { + Service <| title == 'httpd' |> { tag +> 'cinder-service' } - if $service_name == $cinder::params::api_service { - service { 'cinder-api': - ensure => $ensure, - name => $cinder::params::api_service, - enable => $enabled, - hasstatus => true, - tag => 'cinder-service', + service { 'cinder-api': + ensure => 'stopped', + name => $cinder::params::api_service, + enable => false, + tag => ['cinder-service'], + } + + # we need to make sure cinder-api/eventlet is stopped before trying to start apache + Service['cinder-api'] -> Service['httpd'] + + # On any api-paste.ini config change, we must restart Cinder API. + Cinder_api_paste_ini<||> ~> Service['httpd'] } + default: { + $service_ensure = $enabled ? { + true => 'running', + default => 'stopped', + } - # On any api-paste.ini config change, we must restart Cinder API. - Cinder_api_paste_ini<||> ~> Service['cinder-api'] - # On any uwsgi config change, we must restart Cinder API. - Cinder_api_uwsgi_config<||> ~> Service['cinder-api'] - } elsif $service_name == 'httpd' { - service { 'cinder-api': - ensure => 'stopped', - name => $cinder::params::api_service, - enable => false, - tag => ['cinder-service'], + service { 'cinder-api': + ensure => $service_ensure, + name => $service_name, + enable => $enabled, + hasstatus => true, + tag => 'cinder-service', + } + + # On any api-paste.ini config change, we must restart Cinder API. + Cinder_api_paste_ini<||> ~> Service['cinder-api'] + # On any uwsgi config change, we must restart Cinder API. + Cinder_api_uwsgi_config<||> ~> Service['cinder-api'] } - Service <| title == 'httpd' |> { tag +> 'cinder-service' } - - # we need to make sure cinder-api/eventlet is stopped before trying to start apache - Service['cinder-api'] -> Service[$service_name] - - # On any api-paste.ini config change, we must restart Cinder API. - Cinder_api_paste_ini<||> ~> Service[$service_name] - } else { - fail("Invalid service_name. Either cinder-api/openstack-cinder-api for \ -running as a standalone service, or httpd for being run by a httpd server") } } diff --git a/spec/classes/cinder_api_spec.rb b/spec/classes/cinder_api_spec.rb index f95b61a8..a17b8df6 100644 --- a/spec/classes/cinder_api_spec.rb +++ b/spec/classes/cinder_api_spec.rb @@ -174,22 +174,6 @@ describe 'cinder::api' do end end - context 'when service_name is not valid' do - let :params do - req_params.merge!({ :service_name => 'foobar' }) - end - - let :pre_condition do - "include apache - class { 'cinder': } - class { 'cinder::keystone::authtoken': - password => 'foo', - }" - end - - it_raises 'a Puppet::Error', /Invalid service_name/ - end - context 'with SSL socket options set' do let :params do req_params.merge!({