Merge "Support [executor] type"

This commit is contained in:
Zuul
2025-08-04 15:50:24 +00:00
committed by Gerrit Code Review
3 changed files with 113 additions and 55 deletions

View File

@@ -9,11 +9,18 @@
# #
# [*enabled*] # [*enabled*]
# (optional) Should the service be enabled. # (optional) Should the service be enabled.
# Defaults to 'true'. # Defaults to true.
# #
# [*manage_service*] # [*manage_service*]
# (optional) Whether the service should be managed by Puppet. # (optional) Whether the service should be managed by Puppet.
# Defaults to 'true'. # Defaults to true.
#
# [*type*]
# (Optional) Type of executor. Use local to run the executor within
# the engine server. Use remote if the executor is launched as a separate
# server to process events.
# (string value)
# Defaults to 'remote'.
# #
# [*host*] # [*host*]
# (Optional) Name of the executor node. This can be an opaque identifier. # (Optional) Name of the executor node. This can be an opaque identifier.
@@ -32,6 +39,7 @@ class mistral::executor (
$package_ensure = present, $package_ensure = present,
Boolean $manage_service = true, Boolean $manage_service = true,
Boolean $enabled = true, Boolean $enabled = true,
Enum['local', 'remote'] $type = 'remote',
$host = $facts['os_service_default'], $host = $facts['os_service_default'],
$topic = $facts['os_service_default'], $topic = $facts['os_service_default'],
$version = $facts['os_service_default'], $version = $facts['os_service_default'],
@@ -47,7 +55,12 @@ class mistral::executor (
} }
if $manage_service { if $manage_service {
if $enabled { $enabled_real = $type ? {
'remote' => $enabled,
default => false,
}
if $enabled_real {
$service_ensure = 'running' $service_ensure = 'running'
} else { } else {
$service_ensure = 'stopped' $service_ensure = 'stopped'
@@ -56,7 +69,7 @@ class mistral::executor (
service { 'mistral-executor': service { 'mistral-executor':
ensure => $service_ensure, ensure => $service_ensure,
name => $::mistral::params::executor_service_name, name => $::mistral::params::executor_service_name,
enable => $enabled, enable => $enabled_real,
hasstatus => true, hasstatus => true,
hasrestart => true, hasrestart => true,
tag => 'mistral-service', tag => 'mistral-service',
@@ -64,6 +77,7 @@ class mistral::executor (
} }
mistral_config { mistral_config {
'executor/type': value => $type;
'executor/host': value => $host; 'executor/host': value => $host;
'executor/topic': value => $topic; 'executor/topic': value => $topic;
'executor/version': value => $version; 'executor/version': value => $version;

View File

@@ -0,0 +1,4 @@
---
features:
- |
The new ``mistral::executor::type`` parameter has been added.

View File

@@ -1,51 +1,84 @@
require 'spec_helper' require 'spec_helper'
describe 'mistral::executor' do describe 'mistral::executor' do
let :params do
{ shared_examples_for 'mistral::executor' do
:enabled => true, context 'with defaults' do
:manage_service => true, it 'configure executor default params' do
:host => true, is_expected.to contain_mistral_config('executor/type').with_value('remote')
:topic => true, is_expected.to contain_mistral_config('executor/host').with_value('<SERVICE DEFAULT>')
:version => true is_expected.to contain_mistral_config('executor/topic').with_value('<SERVICE DEFAULT>')
} is_expected.to contain_mistral_config('executor/version').with_value('<SERVICE DEFAULT>')
end end
shared_examples 'mistral::executor' do it 'installs mistral-executor package' do
context 'config params' do is_expected.to contain_package('mistral-executor').with(
it { is_expected.to contain_class('mistral::params') } :ensure => 'present',
:name => platform_params[:executor_package_name],
it { is_expected.to contain_mistral_config('executor/host').with_value( params[:host] ) } :tag => ['openstack', 'mistral-package']
it { is_expected.to contain_mistral_config('executor/topic').with_value( params[:topic] ) } )
it { is_expected.to contain_mistral_config('executor/version').with_value( params[:version] ) }
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 end
it 'configures mistral-executor service' do it 'configures mistral-executor service' do
is_expected.to contain_service('mistral-executor').with( is_expected.to contain_service('mistral-executor').with(
:ensure => params[:enabled] ? 'running' : 'stopped', :ensure => 'running',
:name => platform_params[:executor_service_name], :name => platform_params[:executor_service_name],
:enable => params[:enabled], :enable => true,
:hasstatus => true, :hasstatus => true,
:hasrestart => true, :hasrestart => true,
:tag => 'mistral-service', :tag => 'mistral-service',
) )
is_expected.to contain_service('mistral-executor').that_subscribes_to(nil)
end
end end
end end
context 'with disabled service managing' do context 'with specific parameters' do
before do let :params do
params.merge!({ { :type => 'local',
:manage_service => false :host => 'localhost',
}) :topic => 'mistral_executor',
:version => '1.0'
}
end
it 'configure executor params' do
is_expected.to contain_mistral_config('executor/type').with_value('local')
is_expected.to contain_mistral_config('executor/host').with_value('localhost')
is_expected.to contain_mistral_config('executor/topic').with_value('mistral_executor')
is_expected.to contain_mistral_config('executor/version').with_value('1.0')
end
it 'disables mistral-executor service' do
is_expected.to contain_service('mistral-executor').with(
:ensure => 'stopped',
:name => platform_params[:executor_service_name],
:enable => false,
:hasstatus => true,
:hasrestart => true,
:tag => 'mistral-service',
)
end
end
context 'with service disabled' do
let :params do
{ :enabled => false }
end
it 'configures mistral-executor service' do
is_expected.to contain_service('mistral-executor').with(
:ensure => 'stopped',
:name => platform_params[:executor_service_name],
:enable => false,
:hasstatus => true,
:hasrestart => true,
:tag => 'mistral-service',
)
end
end
context 'with service unmanaged' do
let :params do
{ :manage_service => false }
end end
it 'does not configure mistral-executor service' do it 'does not configure mistral-executor service' do
@@ -65,13 +98,20 @@ describe 'mistral::executor' do
let (:platform_params) do let (:platform_params) do
case facts[:os]['family'] case facts[:os]['family']
when 'Debian' when 'Debian'
{ :executor_service_name => 'mistral-executor' } {
:executor_package_name => 'mistral-executor',
:executor_service_name => 'mistral-executor'
}
when 'RedHat' when 'RedHat'
{ :executor_service_name => 'openstack-mistral-executor' } {
:executor_package_name => 'openstack-mistral-executor',
:executor_service_name => 'openstack-mistral-executor'
}
end end
end end
it_behaves_like 'mistral::executor' it_configures 'mistral::executor'
end end
end end
end end