2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
inherit_from: .rubocop_todo.yml

# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v13.5.0](https://github.com/voxpupuli/puppet-rabbitmq/tree/v13.5.0) (2024-05-23)

[Full Changelog](https://github.com/voxpupuli/puppet-rabbitmq/compare/v13.4.0...v13.5.0)

**Implemented enhancements:**

- Add require\_epel parameter, defaulting to `true` [\#997](https://github.com/voxpupuli/puppet-rabbitmq/pull/997) ([wyardley](https://github.com/wyardley))
- Add support for policy definition consumer-timeout [\#991](https://github.com/voxpupuli/puppet-rabbitmq/pull/991) ([wyardley](https://github.com/wyardley))

**Fixed bugs:**

- Handle rabbitmq.config when cluster\_nodes is empty [\#993](https://github.com/voxpupuli/puppet-rabbitmq/pull/993) ([nosrio](https://github.com/nosrio))

**Closed issues:**

- Does not find rabbitmqadmin under ubuntu [\#812](https://github.com/voxpupuli/puppet-rabbitmq/issues/812)

**Merged pull requests:**

- Add unit test to handle bug solved on PR \#993 [\#994](https://github.com/voxpupuli/puppet-rabbitmq/pull/994) ([nosrio](https://github.com/nosrio))
- Use stdlib::ensure\_packages [\#990](https://github.com/voxpupuli/puppet-rabbitmq/pull/990) ([wyardley](https://github.com/wyardley))

## [v13.4.0](https://github.com/voxpupuli/puppet-rabbitmq/tree/v13.4.0) (2024-05-19)

[Full Changelog](https://github.com/voxpupuli/puppet-rabbitmq/compare/v13.3.0...v13.4.0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ These are now documented via [Puppet Strings](https://github.com/puppetlabs/pupp

You can view example usage in [REFERENCE](REFERENCE.md).

**[puppet/epel](https://forge.puppet.com/modules/puppet/epel) is a soft dependency. The module requires it if you're on CentOS 7**
**[puppet/epel](https://forge.puppet.com/modules/puppet/epel) is a soft dependency. If you're on CentOS 7 and don't want to require it, set `$require_epel` to `false`**

Version v13.2.0 and older also added an erlang repository on CentOS 7. That isn't used and can be safely removed.

Expand Down
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ The following parameters are available in the `rabbitmq` class:
* [`port`](#-rabbitmq--port)
* [`python_package`](#-rabbitmq--python_package)
* [`repos_ensure`](#-rabbitmq--repos_ensure)
* [`require_epel`](#-rabbitmq--require_epel)
* [`service_ensure`](#-rabbitmq--service_ensure)
* [`service_manage`](#-rabbitmq--service_manage)
* [`service_name`](#-rabbitmq--service_name)
Expand Down Expand Up @@ -800,6 +801,14 @@ different ways of handling the erlang deps. See also https://github.com/voxpupu

Default value: `false`

##### <a name="-rabbitmq--require_epel"></a>`require_epel`

Data type: `Boolean`

If this parameter is set, On CentOS / RHEL 7 systems, require the "puppet/epel" module

Default value: `true`

##### <a name="-rabbitmq--service_ensure"></a>`service_ensure`

Data type: `Enum['running', 'stopped']`
Expand Down
64 changes: 25 additions & 39 deletions lib/puppet/type/rabbitmq_policy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# frozen_string_literal: true

# See below; these are variables that we want to auto-convert to integer
# values
CONVERT_TO_INT_VARS = %w[
consumer-timeout
delivery-limit
expires
ha-sync-batch-size
initial-cluster-size
max-length
max-length-bytes
message-ttl
shards-per-node
].freeze

Puppet::Type.newtype(:rabbitmq_policy) do
desc <<~DESC
Type for managing rabbitmq policies
Expand Down Expand Up @@ -97,50 +111,22 @@ def validate_definition(definition)
ha_params = definition['ha-params']
raise ArgumentError, "Invalid ha-params '#{ha_params}' for ha-mode 'exactly'" unless ha_params.to_i.to_s == ha_params
end
if definition.key? 'expires'
expires_val = definition['expires']
raise ArgumentError, "Invalid expires value '#{expires_val}'" unless expires_val.to_i.to_s == expires_val
end
if definition.key? 'message-ttl'
message_ttl_val = definition['message-ttl']
raise ArgumentError, "Invalid message-ttl value '#{message_ttl_val}'" unless message_ttl_val.to_i.to_s == message_ttl_val
end
if definition.key? 'max-length'
max_length_val = definition['max-length']
raise ArgumentError, "Invalid max-length value '#{max_length_val}'" unless max_length_val.to_i.to_s == max_length_val
end
if definition.key? 'max-length-bytes'
max_length_bytes_val = definition['max-length-bytes']
raise ArgumentError, "Invalid max-length-bytes value '#{max_length_bytes_val}'" unless max_length_bytes_val.to_i.to_s == max_length_bytes_val
end
if definition.key? 'shards-per-node'
shards_per_node_val = definition['shards-per-node']
raise ArgumentError, "Invalid shards-per-node value '#{shards_per_node_val}'" unless shards_per_node_val.to_i.to_s == shards_per_node_val
end
if definition.key? 'ha-sync-batch-size'
ha_sync_batch_size_val = definition['ha-sync-batch-size']
raise ArgumentError, "Invalid ha-sync-batch-size value '#{ha_sync_batch_size_val}'" unless ha_sync_batch_size_val.to_i.to_s == ha_sync_batch_size_val
end
if definition.key? 'delivery-limit'
delivery_limit_val = definition['delivery-limit']
raise ArgumentError, "Invalid delivery-limit value '#{delivery_limit_val}'" unless delivery_limit_val.to_i.to_s == delivery_limit_val
end
if definition.key? 'initial-cluster-size' # rubocop:disable Style/GuardClause
initial_cluster_size_val = definition['initial-cluster-size']
raise ArgumentError, "Invalid initial-cluster-size value '#{initial_cluster_size_val}'" unless initial_cluster_size_val.to_i.to_s == initial_cluster_size_val

# Since this pattern is repeated, use a constant to track all the types
# where we need to convert a string value to an unquoted integer explicitly
definition.each do |k, v|
raise ArgumentError, "Invalid #{k} value '#{v}'" if CONVERT_TO_INT_VARS.include?(k) && v.to_i.to_s != v
end
end

def munge_definition(definition)
definition['ha-params'] = definition['ha-params'].to_i if definition['ha-mode'] == 'exactly'
definition['expires'] = definition['expires'].to_i if definition.key? 'expires'
definition['message-ttl'] = definition['message-ttl'].to_i if definition.key? 'message-ttl'
definition['max-length'] = definition['max-length'].to_i if definition.key? 'max-length'
definition['max-length-bytes'] = definition['max-length-bytes'].to_i if definition.key? 'max-length-bytes'
definition['shards-per-node'] = definition['shards-per-node'].to_i if definition.key? 'shards-per-node'
definition['ha-sync-batch-size'] = definition['ha-sync-batch-size'].to_i if definition.key? 'ha-sync-batch-size'
definition['delivery-limit'] = definition['delivery-limit'].to_i if definition.key? 'delivery-limit'
definition['initial-cluster-size'] = definition['initial-cluster-size'].to_i if definition.key? 'initial-cluster-size'

# Again, use a list of types to convert vs. hard-coding each one
definition.each do |k, v|
definition[k] = v.to_i if CONVERT_TO_INT_VARS.include? k
end

definition
end
end
10 changes: 9 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@
# Defaults to false (use system packages). This does not ensure that soft dependencies (like EPEL on RHEL systems) are present.
# It also does not solve the erlang dependency. See https://www.rabbitmq.com/which-erlang.html for a good breakdown of the
# different ways of handling the erlang deps. See also https://github.com/voxpupuli/puppet-rabbitmq/issues/788
# @param require_epel
# If this parameter is set, On CentOS / RHEL 7 systems, require the "puppet/epel" module
# @param service_ensure
# The state of the service.
# @param service_manage
Expand Down Expand Up @@ -453,6 +455,7 @@
Array $archive_options = [],
Array $loopback_users = ['guest'],
Boolean $service_restart = true,
Boolean $require_epel = true,
) {
if $ssl_only and ! $ssl {
fail('$ssl_only => true requires that $ssl => true')
Expand Down Expand Up @@ -507,7 +510,12 @@
default: {
}
}
} elsif ($facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '7') {
} elsif ($facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '7') and $require_epel {
# On later CentOS / RHEL systems, this is not useful since EPEL doesn't
# have the rabbitmq-server package anyway.
#
# Once support for 7 is dropped, we should remove this code and the
# parameter
require epel
}

Expand Down
2 changes: 1 addition & 1 deletion manifests/install/rabbitmqadmin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$python_package = $rabbitmq::python_package
# Some systems (e.g., Ubuntu 16.04) don't ship Python 2 by default
if $rabbitmq::manage_python {
ensure_packages([$python_package])
stdlib::ensure_packages([$python_package])
$rabbitmqadmin_require = [Archive['rabbitmqadmin'], Package[$python_package]]
} else {
$rabbitmqadmin_require = Archive['rabbitmqadmin']
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-rabbitmq",
"version": "13.4.0",
"version": "13.5.0",
"author": "Vox Pupuli",
"summary": "Installs, configures, and manages RabbitMQ.",
"license": "Apache-2.0",
Expand Down
15 changes: 15 additions & 0 deletions spec/classes/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,21 @@
is_expected.to contain_file('rabbitmq.config').with('content' => %r{cluster_nodes.*\['rabbit@hare-1', 'rabbit@hare-2'\], ram})
end
end

describe 'without cluster_nodes and sets appropriate configuration' do
let(:params) do
{
config_cluster: true,
cluster_node_type: 'ram',
erlang_cookie: 'ORIGINAL',
wipe_db_on_cookie_change: true
}
end

it 'for cluster_nodes' do
is_expected.to contain_file('rabbitmq.config').with('content' => %r{cluster_nodes.*\[\], ram})
end
end
end

describe 'rabbitmq-env configuration' do
Expand Down
27 changes: 20 additions & 7 deletions spec/unit/puppet/type/rabbitmq_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
end
end

it 'accepts and convert ha-params for ha-mode exactly' do
it 'accepts and converts ha-params for ha-mode exactly' do
definition = { 'ha-mode' => 'exactly', 'ha-params' => '2' }
policy[:definition] = definition
expect(policy[:definition]['ha-params']).to eq(2)
Expand All @@ -104,7 +104,20 @@
end.to raise_error(Puppet::Error, %r{Invalid ha-params.*nonnumeric.*exactly})
end

it 'accepts and convert the expires value' do
it 'accepts and converts the consumer-timeout value' do
definition = { 'consumer-timeout' => '86400000' }
policy[:definition] = definition
expect(policy[:definition]['consumer-timeout']).to eq(86_400_000)
end

it 'does not accept non-numeric consumer-timeout value' do
definition = { 'consumer-timeout' => 'bogus' }
expect do
policy[:definition] = definition
end.to raise_error(Puppet::Error, %r{Invalid consumer-timeout value.*bogus})
end

it 'accepts and converts the expires value' do
definition = { 'expires' => '1800000' }
policy[:definition] = definition
expect(policy[:definition]['expires']).to eq(1_800_000)
Expand All @@ -117,7 +130,7 @@
end.to raise_error(Puppet::Error, %r{Invalid expires value.*future})
end

it 'accepts and convert the message-ttl value' do
it 'accepts and converts the message-ttl value' do
definition = { 'message-ttl' => '1800000' }
policy[:definition] = definition
expect(policy[:definition]['message-ttl']).to eq(1_800_000)
Expand All @@ -130,7 +143,7 @@
end.to raise_error(Puppet::Error, %r{Invalid message-ttl value.*future})
end

it 'accepts and convert the max-length value' do
it 'accepts and converts the max-length value' do
definition = { 'max-length' => '1800000' }
policy[:definition] = definition
expect(policy[:definition]['max-length']).to eq(1_800_000)
Expand All @@ -143,7 +156,7 @@
end.to raise_error(Puppet::Error, %r{Invalid max-length value.*future})
end

it 'accepts and convert the max-length-bytes value' do
it 'accepts and converts the max-length-bytes value' do
definition = { 'max-length-bytes' => '1800000' }
policy[:definition] = definition
expect(policy[:definition]['max-length-bytes']).to eq(1_800_000)
Expand All @@ -156,7 +169,7 @@
end.to raise_error(Puppet::Error, %r{Invalid max-length-bytes value.*future})
end

it 'accepts and convert the shards-per-node value' do
it 'accepts and converts the shards-per-node value' do
definition = { 'shards-per-node' => '1800000' }
policy[:definition] = definition
expect(policy[:definition]['shards-per-node']).to eq(1_800_000)
Expand All @@ -169,7 +182,7 @@
end.to raise_error(Puppet::Error, %r{Invalid shards-per-node value.*future})
end

it 'accepts and convert the ha-sync-batch-size value' do
it 'accepts and converts the ha-sync-batch-size value' do
definition = { 'ha-sync-batch-size' => '1800000' }
policy[:definition] = definition
expect(policy[:definition]['ha-sync-batch-size']).to eq(1_800_000)
Expand Down
4 changes: 4 additions & 0 deletions templates/rabbitmq.config.epp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
{auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},
<% } -%>
<% if $rabbitmq::config::config_cluster {-%>
<% if !$rabbitmq::config::cluster_nodes.empty {-%>
{cluster_nodes, {['rabbit@<%= $rabbitmq::config::cluster_nodes.join("', 'rabbit@") %>'], <%= $rabbitmq::config::cluster_node_type %>}},
<% } else {%>
{cluster_nodes, {[], <%= $rabbitmq::config::cluster_node_type %>}},
<% } %>
{cluster_partition_handling, <%= $rabbitmq::config::cluster_partition_handling %>},
<% } -%>
{tcp_listen_options, [
Expand Down