From eb2c26940ad93615e924fd5ef4b242faa8083f00 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 27 Sep 2025 00:41:55 +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: Iaaff77cd9fef2bbd42b5b08eeb5561129d89fab5 Signed-off-by: Takashi Kajinami --- manifests/api.pp | 57 +++++++++++++++-------------- spec/classes/cloudkitty_api_spec.rb | 11 +----- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/manifests/api.pp b/manifests/api.pp index 8d64817..1b17d45 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -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') } } diff --git a/spec/classes/cloudkitty_api_spec.rb b/spec/classes/cloudkitty_api_spec.rb index 33b5c8f..7e4332e 100644 --- a/spec/classes/cloudkitty_api_spec.rb +++ b/spec/classes/cloudkitty_api_spec.rb @@ -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!({