From b7bc135bc0271dbc31e699b4f4742fdcc9bd089d Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 27 Sep 2025 14:54:01 +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: I14417328d26b48eb4484d1a1b368f6417fb8211a Signed-off-by: Takashi Kajinami --- manifests/api.pp | 60 ++++++++++++++++----------------- spec/classes/ironic_api_spec.rb | 15 --------- 2 files changed, 30 insertions(+), 45 deletions(-) diff --git a/manifests/api.pp b/manifests/api.pp index 59ff37c1..4c9179e5 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -77,7 +77,7 @@ class ironic::api ( Stdlib::Ensure::Package $package_ensure = 'present', Boolean $manage_service = true, Boolean $enabled = true, - $service_name = $ironic::params::api_service, + String[1] $service_name = $ironic::params::api_service, $host_ip = $facts['os_service_default'], $port = $facts['os_service_default'], $max_limit = $facts['os_service_default'], @@ -108,37 +108,37 @@ class ironic::api ( } if $manage_service { - if $enabled { - $ensure = 'running' - } else { - $ensure = 'stopped' - } + case $service_name { + 'httpd': { + Service <| title == 'httpd' |> { tag +> 'ironic-service' } - if $service_name == $ironic::params::api_service { - service { 'ironic-api': - ensure => $ensure, - name => $ironic::params::api_service, - enable => $enabled, - hasstatus => true, - hasrestart => true, - tag => 'ironic-service', - } - Keystone_endpoint<||> -> Service['ironic-api'] - Ironic_api_uwsgi_config<||> ~> Service['ironic-api'] - } elsif $service_name == 'httpd' { - service { 'ironic-api': - ensure => 'stopped', - name => $ironic::params::api_service, - enable => false, - tag => 'ironic-service', - } - Service <| title == 'httpd' |> { tag +> 'ironic-service' } + service { 'ironic-api': + ensure => 'stopped', + name => $ironic::params::api_service, + enable => false, + tag => 'ironic-service', + } - # we need to make sure ironic-api/eventlet is stopped before trying to start apache - Service['ironic-api'] -> Service[$service_name] - } else { - fail("Invalid service_name. Either ironic-api/openstack-ironic-api for running as a \ -standalone service, or httpd for being run by a httpd server") + # we need to make sure ironic-api/eventlet is stopped before trying to start apache + Service['ironic-api'] -> Service['httpd'] + } + default: { + $service_ensure = $enabled ? { + true => 'running', + default => 'stopped', + } + + service { 'ironic-api': + ensure => $service_ensure, + name => $service_name, + enable => $enabled, + hasstatus => true, + hasrestart => true, + tag => 'ironic-service', + } + Keystone_endpoint<||> -> Service['ironic-api'] + Ironic_api_uwsgi_config<||> ~> Service['ironic-api'] + } } } diff --git a/spec/classes/ironic_api_spec.rb b/spec/classes/ironic_api_spec.rb index c520fa33..7ed6c278 100644 --- a/spec/classes/ironic_api_spec.rb +++ b/spec/classes/ironic_api_spec.rb @@ -132,21 +132,6 @@ describe 'ironic::api' do ) end end - - context 'when service_name is not valid' do - before do - params.merge!({ :service_name => 'foobar' }) - end - - let :pre_condition do - "class { 'ironic::api::authtoken': - password => 'password', - } - include apache" - end - - it_raises 'a Puppet::Error', /Invalid service_name/ - end end on_supported_os({