From 368d53e24f43057fe7969da4911c26971b8c10d5 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Sat, 21 Nov 2015 20:33:54 -0500 Subject: [PATCH] Add mistral::executor class Adds a new class to manage the mistral-executor package/service. Change-Id: Ide01de8c761ccd099b7a8469bff34316ff5c04f2 --- manifests/executor.pp | 90 ++++++++++++++++++++++++ manifests/params.pp | 4 ++ spec/classes/mistral_executor_spec.rb | 98 +++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 manifests/executor.pp create mode 100644 spec/classes/mistral_executor_spec.rb diff --git a/manifests/executor.pp b/manifests/executor.pp new file mode 100644 index 0000000..5cca93d --- /dev/null +++ b/manifests/executor.pp @@ -0,0 +1,90 @@ +# == Class: mistral::executor +# +# Installs & configure the Mistral Engine service +# +# === Parameters +# [*package_ensure*] +# (Optional) Ensure state for package. +# Defaults to present +# +# [*enabled*] +# (optional) Should the service be enabled. +# Defaults to 'true'. +# +# [*manage_service*] +# (optional) Whether the service should be managed by Puppet. +# Defaults to 'true'. +# +# [*host*] +# (Optional) Name of the executor node. This can be an opaque identifier. +# It is not necessarily a hostname, FQDN, or IP address. (string value) +# Defaults to $::os_service_default. +# +# [*topic*] +# (Optional) The message topic that the executor listens on. (string value) +# Defaults to $::os_service_default. +# +# [*version*] +# (Optional) The version of the executor. (string value) +# Defaults to $::os_service_default. +# +# [*evaluation_interval*] +# (Optional) How often will the executions be evaluated +# (in minutes). For example for value 120 the interval +# will be 2 hours (every 2 hours). +# Defaults to $::os_service_default. +# +# [*older_than*] +# (Optional) Evaluate from which time remove executions in minutes. +# For example when older_than = 60, remove all executions +# that finished a 60 minutes ago or more. +# Minimum value is 1. +# Note that only final state execution will remove (SUCCESS/ERROR). +# Defaults to $::os_service_default. +# +class mistral::executor ( + $package_ensure = present, + $manage_service = true, + $enabled = true, + $host = $::os_service_default, + $topic = $::os_service_default, + $version = $::os_service_default, + $evaluation_interval = $::os_service_default, + $older_than = $::os_service_default, +) { + + include ::mistral + include ::mistral::params + + package { 'mistral-executor': + ensure => $package_ensure, + name => $::mistral::params::executor_package_name, + tag => ['openstack', 'mistral-package'], + } + + if $manage_service { + if $enabled { + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } + } + + service { 'mistral-executor': + ensure => $service_ensure, + name => $::mistral::params::executor_service_name, + enable => $enabled, + hasstatus => true, + hasrestart => true, + tag => 'mistral-service', + } + + mistral_config { + 'executor/host' : value => $host; + 'executor/topic' : value => $topic; + 'executor/version' : value => $version; + 'execution_expiration_policy/evaluation_interval' : value => $evaluation_interval; + 'execution_expiration_policy/older_than' : value => $older_than; + } + +} diff --git a/manifests/params.pp b/manifests/params.pp index 47bb297..68ba211 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -17,6 +17,8 @@ class mistral::params { $api_service_name = 'openstack-mistral-api' $engine_package_name = 'openstack-mistral-engine' $engine_service_name = 'openstack-mistral-engine' + $executor_package_name = 'openstack-mistral-executor' + $executor_service_name = 'openstack-mistral-executor' } 'Debian': { $common_package_name = 'mistral' @@ -24,6 +26,8 @@ class mistral::params { $api_service_name = 'mistral-api' $engine_package_name = 'mistral-engine' $engine_service_name = 'mistral-engine' + $executor_package_name = 'mistral-executor' + $executor_service_name = 'mistral-executor' } default: { fail("Unsupported osfamily: ${::osfamily} operatingsystem: \ diff --git a/spec/classes/mistral_executor_spec.rb b/spec/classes/mistral_executor_spec.rb new file mode 100644 index 0000000..c785ef2 --- /dev/null +++ b/spec/classes/mistral_executor_spec.rb @@ -0,0 +1,98 @@ +require 'spec_helper' + +describe 'mistral::executor' do + + let :params do + { :enabled => true, + :manage_service => true, + :host => true, + :topic => true, + :version => true, + :evaluation_interval => 1234, + :older_than => 60} + end + + shared_examples_for 'mistral-executor' do + + context 'config params' do + + it { is_expected.to contain_class('mistral') } + it { is_expected.to contain_class('mistral::params') } + + it { is_expected.to contain_mistral_config('executor/host').with_value( params[:host] ) } + 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] ) } + it { is_expected.to contain_mistral_config('execution_expiration_policy/evaluation_interval').with_value( params[:evaluation_interval] ) } + it { is_expected.to contain_mistral_config('execution_expiration_policy/older_than').with_value( params[:older_than] ) } + + 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 mistral-executor service' do + + is_expected.to contain_service('mistral-executor').with( + :ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped', + :name => platform_params[:executor_service_name], + :enable => params[:enabled], + :hasstatus => true, + :hasrestart => true, + :tag => 'mistral-service', + ) + is_expected.to contain_service('mistral-executor').that_subscribes_to(nil) + end + end + end + + context 'with disabled service managing' do + before do + params.merge!({ + :manage_service => false, + :enabled => false }) + end + + it 'configures mistral-executor service' do + + is_expected.to contain_service('mistral-executor').with( + :ensure => nil, + :name => platform_params[:executor_service_name], + :enable => false, + :hasstatus => true, + :hasrestart => true, + :tag => 'mistral-service', + ) + is_expected.to contain_service('mistral-executor').that_subscribes_to(nil) + end + end + + end + + context 'on Debian platforms' do + let :facts do + { :osfamily => 'Debian' } + end + + let :platform_params do + { :executor_service_name => 'mistral-executor' } + end + + it_configures 'mistral-executor' + end + + context 'on RedHat platforms' do + let :facts do + { :osfamily => 'RedHat' } + end + + let :platform_params do + { :executor_service_name => 'openstack-mistral-executor' } + end + + it_configures 'mistral-executor' + end + +end