Skip to content

Commit

Permalink
Enable usage of custom list of plugins when using static config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Nothen committed Nov 24, 2022
1 parent 17a0028 commit 71222de
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$admin_enable = $rabbitmq::admin_enable
$management_enable = $rabbitmq::management_enable
$use_config_file_for_plugins = $rabbitmq::use_config_file_for_plugins
$plugins = $rabbitmq::plugins
$cluster_node_type = $rabbitmq::cluster_node_type
$cluster_nodes = $rabbitmq::cluster_nodes
$config = $rabbitmq::config
Expand Down
11 changes: 11 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
# @param use_config_file_for_plugins
# If enabled the /etc/rabbitmq/enabled_plugins config file is created,
# replacing the use of the rabbitmqplugins provider to enable plugins.
# @param plugins
# Additional list of plugins to start, or to add to /etc/rabbitmq/enabled_plugins, if use_config_file_for_plugins is enabled.
# @param auth_backends
# An array specifying authorization/authentication backend to use. Single quotes should be placed around array entries,
# ex. `['{foo, baz}', 'baz']` Defaults to [rabbit_auth_backend_internal], and if using LDAP defaults to [rabbit_auth_backend_internal,
Expand Down Expand Up @@ -345,6 +347,7 @@
Boolean $admin_enable = true,
Boolean $management_enable = false,
Boolean $use_config_file_for_plugins = false,
Array $plugins = [],
Hash $cluster = $rabbitmq::cluster,
Enum['ram', 'disc'] $cluster_node_type = 'disc',
Array $cluster_nodes = [],
Expand Down Expand Up @@ -550,6 +553,14 @@
}
}
}
# Start anything else listed on the plugins array, if it was not started already by the other booleans
$plugins.each | $plugin | {
rabbitmq_plugin { $plugin:
ensure => present,
notify => Class['rabbitmq::service'],
provider => 'rabbitmqplugins',
}
}
}

if $admin_enable and $service_manage {
Expand Down
22 changes: 21 additions & 1 deletion spec/classes/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@
end

context 'use config file for plugins' do
describe 'config_plugins_file: true' do
describe 'config_plugins_file: true and default list of enabled plugins' do
let :params do
{ use_config_file_for_plugins: true }
end
Expand All @@ -700,6 +700,26 @@
end
end

describe 'config_plugins_file: true and custom list of enabled plugins' do
let :params do
{
use_config_file_for_plugins: true,
admin_enable: false,
plugins: %w[rabbitmq_stomp rabbitmq_shovel rabbitmq_prometheus]
}
end

it 'does not use rabbitmqplugin provider' do
is_expected.not_to contain_rabbitmq_plugin('rabbitmq_stomp')
is_expected.not_to contain_rabbitmq_plugin('rabbitmq_shovel')
is_expected.not_to contain_rabbitmq_plugin('rabbitmq_prometheus')
end

it 'configures enabled_plugins' do
is_expected.to contain_file('enabled_plugins').with_content(%r{\[rabbitmq_stomp,rabbitmq_shovel,rabbitmq_prometheus\]\.})
end
end

describe 'with all plugins enabled admin_enable: false, manamgent_enable: true' do
let :params do
{
Expand Down
4 changes: 2 additions & 2 deletions templates/enabled_plugins.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% This file managed by Puppet
% Template Path: <%= @module_name %>/templates/enabled_plugins
<%- @_plugins = [] -%>
<%- @_plugins = @plugins -%>
<%- if @admin_enable or @management_enable -%>
<%- @_plugins << 'rabbitmq_management' -%>
<%- end -%>
Expand All @@ -16,4 +16,4 @@
<%- @_plugins << 'rabbitmq_shovel_management' -%>
<%- end -%>
<%- end -%>
[<%= @_plugins.join(',')%>].
[<%= (@_plugins.uniq).join(',')%>].

0 comments on commit 71222de

Please sign in to comment.