diff --git a/lib/facter/erl_ssl_path.rb b/lib/facter/erl_ssl_path.rb index c8f41f69b..0035e1048 100644 --- a/lib/facter/erl_ssl_path.rb +++ b/lib/facter/erl_ssl_path.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Fact to get the ssl path for the erlang distribution in the current # system as described in the RabbitMQ docs [1]. # diff --git a/lib/facter/rabbitmq_clustername.rb b/lib/facter/rabbitmq_clustername.rb index 3f2de6647..2f43ab8e5 100644 --- a/lib/facter/rabbitmq_clustername.rb +++ b/lib/facter/rabbitmq_clustername.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Facter.add(:rabbitmq_clustername) do setcode do if Facter::Util::Resolution.which('rabbitmqctl') diff --git a/lib/facter/rabbitmq_nodename.rb b/lib/facter/rabbitmq_nodename.rb index e9316966e..812443cbf 100644 --- a/lib/facter/rabbitmq_nodename.rb +++ b/lib/facter/rabbitmq_nodename.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + Facter.add(:rabbitmq_nodename) do setcode do if Facter::Util::Resolution.which('rabbitmqctl') rabbitmq_nodename = Facter::Core::Execution.execute('rabbitmqctl status 2>&1') begin - %r{^Status of node '?([\w\.\-]+@[\w\.\-]+)'?}.match(rabbitmq_nodename)[1] - rescue + %r{^Status of node '?([\w.\-]+@[\w.\-]+)'?}.match(rabbitmq_nodename)[1] + rescue StandardError Facter.debug("Error: rabbitmq_nodename facter failed. Output was #{rabbitmq_nodename}") end end diff --git a/lib/facter/rabbitmq_plugins_dirs.rb b/lib/facter/rabbitmq_plugins_dirs.rb index 05630eadf..b9c2d2880 100644 --- a/lib/facter/rabbitmq_plugins_dirs.rb +++ b/lib/facter/rabbitmq_plugins_dirs.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + Facter.add(:rabbitmq_plugins_dirs) do setcode do if Facter::Util::Resolution.which('rabbitmqctl') rabbitmq_pluginsdirs_env = Facter::Core::Execution.execute("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'") - rabbitmq_plugins_dirs_match = %r{^\{ok\,\"(\/.+\/\w+)}.match(rabbitmq_pluginsdirs_env) + rabbitmq_plugins_dirs_match = %r{^\{ok,"(/.+/\w+)}.match(rabbitmq_pluginsdirs_env) rabbitmq_plugins_dirs_match[1].split(':') if rabbitmq_plugins_dirs_match end end diff --git a/lib/facter/rabbitmq_version.rb b/lib/facter/rabbitmq_version.rb index 5c5585c0c..d48d9fbb6 100644 --- a/lib/facter/rabbitmq_version.rb +++ b/lib/facter/rabbitmq_version.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + Facter.add(:rabbitmq_version) do setcode do if Facter::Util::Resolution.which('rabbitmqadmin') rabbitmq_version = Facter::Core::Execution.execute('rabbitmqadmin --version 2>&1') - %r{^rabbitmqadmin ([\w\.]+)}.match(rabbitmq_version).to_a[1] + %r{^rabbitmqadmin ([\w.]+)}.match(rabbitmq_version).to_a[1] end end end diff --git a/lib/puppet/provider/rabbitmq_binding/rabbitmqadmin.rb b/lib/puppet/provider/rabbitmq_binding/rabbitmqadmin.rb index 2a3fc13b2..91be82579 100644 --- a/lib/puppet/provider/rabbitmq_binding/rabbitmqadmin.rb +++ b/lib/puppet/provider/rabbitmq_binding/rabbitmqadmin.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'puppet' require 'digest' @@ -10,11 +12,7 @@ mk_resource_methods def should_vhost - if @should_vhost - @should_vhost - else - @should_vhost = resource[:vhost] - end + @should_vhost || @should_vhost = resource[:vhost] end def self.all_vhosts @@ -35,14 +33,15 @@ def self.instances all_bindings(vhost).map do |line| source_name, destination_name, destination_type, routing_key, arguments = line.split(%r{\t}) # Convert output of arguments from the rabbitmqctl command to a json string. - if !arguments.nil? + if arguments.nil? + arguments = '{}' + else arguments = arguments.gsub(%r{^\[(.*)\]$}, '').gsub(%r{\{("(?:.|\\")*?"),}, '{\1:').gsub(%r{\},\{}, ',') arguments = '{}' if arguments == '' - else - arguments = '{}' end hashed_name = Digest::SHA256.hexdigest format('%s@%s@%s@%s', source_name, destination_name, vhost, routing_key) next if source_name.empty? + binding = { source: source_name, destination: destination_name, diff --git a/lib/puppet/provider/rabbitmq_cli.rb b/lib/puppet/provider/rabbitmq_cli.rb index 2a663f873..5421ae514 100644 --- a/lib/puppet/provider/rabbitmq_cli.rb +++ b/lib/puppet/provider/rabbitmq_cli.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Puppet::Provider::RabbitmqCli < Puppet::Provider initvars @@ -38,7 +40,7 @@ def self.rabbitmq_version return @rabbitmq_version if defined? @rabbitmq_version output = rabbitmqctl('-q', 'status') - version = output.match(%r{RabbitMQ.*?([\d\.]+)}) + version = output.match(%r{RabbitMQ.*?([\d.]+)}) @rabbitmq_version = version[1] if version @rabbitmq_version end @@ -56,9 +58,9 @@ def self.rabbitmqctl_list(resource, *opts) def self.rabbitmq_running rabbitmqctl('-q', 'status') - return true + true rescue Puppet::ExecutionFailure, Timeout::Error - return false + false end # Retry the given code block 'count' retries or until the @@ -66,25 +68,22 @@ def self.rabbitmq_running # Limit each query time by 'timeout'. # For example: # users = self.class.run_with_retries { rabbitmqctl 'list_users' } - def self.run_with_retries(count = 30, step = 6, timeout = 10) + def self.run_with_retries(count = 30, step = 6, timeout = 10, &block) count.times do |_n| - begin - output = Timeout.timeout(timeout) do - yield - end - rescue Puppet::ExecutionFailure, Timeout::Error - Puppet.debug 'Command failed, retrying' - sleep step - else - Puppet.debug 'Command succeeded' - return output - end + output = Timeout.timeout(timeout, &block) + rescue Puppet::ExecutionFailure, Timeout::Error + Puppet.debug 'Command failed, retrying' + sleep step + else + Puppet.debug 'Command succeeded' + return output end raise Puppet::Error, "Command is still failing after #{count * step} seconds expired!" end def self.define_instance_method(name) return if method_defined?(name) + define_method(name) do |*args, &block| self.class.send(name, *args, &block) end diff --git a/lib/puppet/provider/rabbitmq_cluster/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_cluster/rabbitmqctl.rb index 3f09f1265..a64677e9e 100644 --- a/lib/puppet/provider/rabbitmq_cluster/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_cluster/rabbitmqctl.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmq_cli')) Puppet::Type.type(:rabbitmq_cluster).provide( :rabbitmqctl, diff --git a/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb b/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb index 47dfdd348..71637cb1e 100644 --- a/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb +++ b/lib/puppet/provider/rabbitmq_erlang_cookie/ruby.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet' require 'set' Puppet::Type.type(:rabbitmq_erlang_cookie).provide(:ruby) do @@ -13,7 +15,7 @@ def content=(value) raise('The current erlang cookie needs to change. In order to do this the RabbitMQ database needs to be wiped. Please set force => true to allow this to happen automatically.') unless resource[:force] == :true # Danger! Puppet::Type.type(:service).new(name: resource[:service_name]).provider.stop - FileUtils.rm_rf(resource[:rabbitmq_home] + File::SEPARATOR + 'mnesia') + FileUtils.rm_rf("#{resource[:rabbitmq_home]}#{File::SEPARATOR}mnesia") File.open(resource[:path], 'w') do |cookie| cookie.chmod(0o400) cookie.write(value) diff --git a/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb b/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb index 75ac3b5e0..86300e069 100644 --- a/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb +++ b/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb @@ -1,14 +1,12 @@ +# frozen_string_literal: true + require 'puppet' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmq_cli')) Puppet::Type.type(:rabbitmq_exchange).provide(:rabbitmqadmin, parent: Puppet::Provider::RabbitmqCli) do confine feature: :posix def should_vhost - if @should_vhost - @should_vhost - else - @should_vhost = resource[:name].split('@')[1] - end + @should_vhost || @should_vhost = resource[:name].split('@')[1] end def self.all_vhosts @@ -19,7 +17,7 @@ def self.all_exchanges(vhost) exchange_list = run_with_retries do rabbitmqctl_list('exchanges', '-p', vhost, 'name', 'type', 'internal', 'durable', 'auto_delete', 'arguments') end - exchange_list.split(%r{\n}).reject { |exchange| exchange =~ %r{^federation:} } + exchange_list.split(%r{\n}).grep_v(%r{^federation:}) end def self.instances @@ -34,11 +32,11 @@ def self.instances name = '' end # Convert output of arguments from the rabbitmqctl command to a json string. - if !arguments.nil? + if arguments.nil? + arguments = '{}' + else arguments = arguments.gsub(%r{^\[(.*)\]$}, '').gsub(%r{\{("(?:.|\\")*?"),}, '{\1:').gsub(%r{\},\{}, ',') arguments = '{}' if arguments == '' - else - arguments = '{}' end exchange = { type: type, @@ -57,7 +55,7 @@ def self.instances def self.prefetch(resources) packages = instances - resources.keys.each do |name| + resources.each_key do |name| if (provider = packages.find { |pkg| pkg.name == name }) resources[name].provider = provider end diff --git a/lib/puppet/provider/rabbitmq_parameter/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_parameter/rabbitmqctl.rb index 8f08a3bf3..1cb74d508 100644 --- a/lib/puppet/provider/rabbitmq_parameter/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_parameter/rabbitmqctl.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'puppet/util/package' @@ -25,6 +27,7 @@ def self.instances all_vhosts.each do |vhost| all_parameters(vhost).map do |line| raise Puppet::Error, "cannot parse line from list_parameter:#{line}" unless line =~ %r{^(\S+)\s+(\S+)\s+(\S+)$} + parameter = { ensure: :present, component_name: Regexp.last_match(1), @@ -39,7 +42,7 @@ def self.instances def self.prefetch(resources) packages = instances - resources.keys.each do |name| + resources.each_key do |name| Puppet.info "Calling prefetch: #{name}" if (provider = packages.find { |pkg| pkg.name == name }) resources[name].provider = provider diff --git a/lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb b/lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb index b8bab7e4b..af04e91a6 100644 --- a/lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb +++ b/lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/util/package' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmq_cli')) @@ -11,6 +13,7 @@ def self.instances plugin_list.split(%r{\n}).map do |line| raise Puppet::Error, "Cannot parse invalid plugins line: #{line}" unless line =~ %r{^(\S+)$} + new(name: Regexp.last_match(1)) end end diff --git a/lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb index 2082c7c31..ffd7b6b07 100644 --- a/lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'puppet/util/package' @@ -7,7 +9,7 @@ # cache policies def self.policies(vhost, name) - @policies = {} unless @policies + @policies ||= {} unless @policies[vhost] @policies[vhost] = {} policy_list = run_with_retries do @@ -30,6 +32,7 @@ def self.policies(vhost, name) policy_list.split(%r{\n}).each do |line| raise Puppet::Error, "cannot parse line from list_policies:#{line}" unless line =~ regex + n = Regexp.last_match(2) applyto = Regexp.last_match(applyto_index) || 'all' priority = Regexp.last_match(6) @@ -107,6 +110,7 @@ def priority=(_priority) def set_policy return if @set_policy + @set_policy = true resource[:applyto] ||= applyto resource[:definition] ||= definition diff --git a/lib/puppet/provider/rabbitmq_queue/rabbitmqadmin.rb b/lib/puppet/provider/rabbitmq_queue/rabbitmqadmin.rb index 67eafa367..8a4118b51 100644 --- a/lib/puppet/provider/rabbitmq_queue/rabbitmqadmin.rb +++ b/lib/puppet/provider/rabbitmq_queue/rabbitmqadmin.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'puppet' @@ -6,11 +8,7 @@ confine feature: :posix def should_vhost - if @should_vhost - @should_vhost - else - @should_vhost = resource[:name].rpartition('@').last - end + @should_vhost || @should_vhost = resource[:name].rpartition('@').last end def self.all_vhosts @@ -26,13 +24,14 @@ def self.instances all_vhosts.each do |vhost| all_queues(vhost).map do |line| next if line =~ %r{^federation:} + name, durable, auto_delete, arguments = line.split("\t") # Convert output of arguments from the rabbitmqctl command to a json string. - if !arguments.nil? + if arguments.nil? + arguments = '{}' + else arguments = arguments.gsub(%r{^\[(.*)\]$}, '').gsub(%r{\{("(?:.|\\")*?"),}, '{\1:').gsub(%r{\},\{}, ',') arguments = '{}' if arguments == '' - else - arguments = '{}' end queue = { durable: durable, @@ -49,7 +48,7 @@ def self.instances def self.prefetch(resources) packages = instances - resources.keys.each do |name| + resources.each_key do |name| if (provider = packages.find { |pkg| pkg.name == name }) resources[name].provider = provider end diff --git a/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb index 2321124db..f0c5efb71 100644 --- a/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmq_cli')) Puppet::Type.type(:rabbitmq_user).provide( :rabbitmqctl, @@ -17,6 +19,7 @@ def self.instances user_list.split(%r{\n}).map do |line| raise Puppet::Error, "Cannot parse invalid user line: #{line}" unless line =~ %r{^(\S+)\s+\[(.*?)\]$} + user = Regexp.last_match(1) tags = Regexp.last_match(2).split(%r{,\s*}) new( @@ -88,6 +91,7 @@ def tags=(tags) def admin usertags = get_user_tags raise Puppet::Error, "Could not match line '#{resource[:name]} (true|false)' from list_users (perhaps you are running on an older version of rabbitmq that does not support admin users?)" unless usertags + (:true if usertags.include?('administrator')) || :false end @@ -111,6 +115,7 @@ def admin=(state) def flush return if @property_flush.empty? + tags = @property_flush[:tags] || @resource[:tags] tags << admin_tag if @resource[:admin] == :true rabbitmqctl('set_user_tags', @resource[:name], tags) diff --git a/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb index 185a01d00..13abe7e42 100644 --- a/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_user_permissions/rabbitmqctl.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmq_cli')) Puppet::Type.type(:rabbitmq_user_permissions).provide(:rabbitmqctl, parent: Puppet::Provider::RabbitmqCli) do confine feature: :posix # cache users permissions def self.users(name, vhost) - @users = {} unless @users + @users ||= {} unless @users[name] @users[name] = {} user_permission_list = run_with_retries do @@ -13,6 +15,7 @@ def self.users(name, vhost) user_permission_list.split(%r{\n}).each do |line| line = strip_backslashes(line) raise Puppet::Error, "cannot parse line from list_user_permissions:#{line}" unless line =~ %r{^(\S+)\s+(\S*)\s+(\S*)\s+(\S*)$} + @users[name][Regexp.last_match(1)] = { configure: Regexp.last_match(2), read: Regexp.last_match(4), write: Regexp.last_match(3) } end @@ -25,19 +28,11 @@ def users(name, vhost) end def should_user - if @should_user - @should_user - else - @should_user = resource[:name].split('@')[0] - end + @should_user || @should_user = resource[:name].split('@')[0] end def should_vhost - if @should_vhost - @should_vhost - else - @should_vhost = resource[:name].split('@')[1] - end + @should_vhost || @should_vhost = resource[:name].split('@')[1] end def create diff --git a/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb b/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb index 92ed78647..668b9bb47 100644 --- a/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb +++ b/lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rabbitmq_cli')) Puppet::Type.type(:rabbitmq_vhost).provide(:rabbitmqctl, parent: Puppet::Provider::RabbitmqCli) do confine feature: :posix @@ -9,6 +11,7 @@ def self.instances vhost_list.split(%r{\n}).map do |line| raise Puppet::Error, "Cannot parse invalid vhost line: #{line}" unless line =~ %r{^(\S+)$} + new(name: Regexp.last_match(1)) end end diff --git a/lib/puppet/type/rabbitmq_binding.rb b/lib/puppet/type/rabbitmq_binding.rb index 08ac83870..88f6db35a 100644 --- a/lib/puppet/type/rabbitmq_binding.rb +++ b/lib/puppet/type/rabbitmq_binding.rb @@ -1,42 +1,44 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_binding) do - desc <<-DESC -Native type for managing rabbitmq bindings - -@example Create a rabbitmq_binding - rabbitmq_binding { 'myexchange@myqueue@myvhost': - user => 'dan', - password => 'bar', - destination_type => 'queue', - routing_key => '#', - arguments => {}, - ensure => present, - } - -@example Create bindings with same source / destination / vhost but different routing key using individual parameters -rabbitmq_binding { 'binding 1': - ensure => present, - source => 'myexchange', - destination => 'myqueue', - vhost => 'myvhost', - user => 'dan', - password => 'bar', - destination_type => 'queue', - routing_key => 'key1', - arguments => {}, -} - -rabbitmq_binding { 'binding 2': - ensure => present, - source => 'myexchange', - destination => 'myqueue', - vhost => 'myvhost', - user => 'dan', - password => 'bar', - destination_type => 'queue', - routing_key => 'key2', - arguments => {}, -} -DESC + desc <<~DESC + Native type for managing rabbitmq bindings + + @example Create a rabbitmq_binding + rabbitmq_binding { 'myexchange@myqueue@myvhost': + user => 'dan', + password => 'bar', + destination_type => 'queue', + routing_key => '#', + arguments => {}, + ensure => present, + } + + @example Create bindings with same source / destination / vhost but different routing key using individual parameters + rabbitmq_binding { 'binding 1': + ensure => present, + source => 'myexchange', + destination => 'myqueue', + vhost => 'myvhost', + user => 'dan', + password => 'bar', + destination_type => 'queue', + routing_key => 'key1', + arguments => {}, + } + + rabbitmq_binding { 'binding 2': + ensure => present, + source => 'myexchange', + destination => 'myqueue', + vhost => 'myvhost', + user => 'dan', + password => 'bar', + destination_type => 'queue', + routing_key => 'key2', + arguments => {}, + } + DESC ensurable do defaultto(:present) @@ -158,9 +160,7 @@ def setup_autorequire(type) destination_type = value(:destination_type) if type == 'exchange' rval = ["#{self[:source]}@#{self[:vhost]}"] - if destination_type == type - rval.push("#{self[:destination]}@#{self[:vhost]}") - end + rval.push("#{self[:destination]}@#{self[:vhost]}") if destination_type == type else rval = if destination_type == type ["#{self[:destination]}@#{self[:vhost]}"] @@ -178,12 +178,8 @@ def validate_argument(argument) # Validate that we have both source and destination now that these are not # necessarily only coming from the resource title. validate do - if !self[:source] && provider.source == :absent - raise ArgumentError, '`source` must be defined' - end + raise ArgumentError, '`source` must be defined' if !self[:source] && provider.source == :absent - if !self[:destination] && provider.destination == :absent - raise ArgumentError, '`destination` must be defined' - end + raise ArgumentError, '`destination` must be defined' if !self[:destination] && provider.destination == :absent end end diff --git a/lib/puppet/type/rabbitmq_cluster.rb b/lib/puppet/type/rabbitmq_cluster.rb index f48106567..b215cf023 100644 --- a/lib/puppet/type/rabbitmq_cluster.rb +++ b/lib/puppet/type/rabbitmq_cluster.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_cluster) do - desc <<-DESC -Native type for managing rabbitmq cluster - -@example Configure a cluster, rabbit_cluster - rabbitmq_cluster { 'rabbit_cluster': - init_node => 'host1' - } - -@example Optional parameter tags will set further rabbitmq tags like monitoring, policymaker, etc. - To set the cluster name use cluster_name. - rabbitmq_cluster { 'rabbit_cluster': - init_node => 'host1', - node_disc_type => 'ram', - } -DESC + desc <<~DESC + Native type for managing rabbitmq cluster + + @example Configure a cluster, rabbit_cluster + rabbitmq_cluster { 'rabbit_cluster': + init_node => 'host1' + } + + @example Optional parameter tags will set further rabbitmq tags like monitoring, policymaker, etc. + To set the cluster name use cluster_name. + rabbitmq_cluster { 'rabbit_cluster': + init_node => 'host1', + node_disc_type => 'ram', + } + DESC ensurable do defaultto(:present) diff --git a/lib/puppet/type/rabbitmq_erlang_cookie.rb b/lib/puppet/type/rabbitmq_erlang_cookie.rb index 690c91be8..65fb2c3bf 100644 --- a/lib/puppet/type/rabbitmq_erlang_cookie.rb +++ b/lib/puppet/type/rabbitmq_erlang_cookie.rb @@ -1,15 +1,17 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_erlang_cookie) do - desc <<-DESC -Type to manage the rabbitmq erlang cookie securely - -This is essentially a private type used by the rabbitmq::config class -to manage the erlang cookie. It replaces the rabbitmq_erlang_cookie fact -from earlier versions of this module. It manages the content of the cookie -usually located at "${rabbitmq_home}/.erlang.cookie", which includes -stopping the rabbitmq service and wiping out the database at -"${rabbitmq_home}/mnesia" if the user agrees to it. We don't recommend using -this type directly. -DESC + desc <<~DESC + Type to manage the rabbitmq erlang cookie securely + + This is essentially a private type used by the rabbitmq::config class + to manage the erlang cookie. It replaces the rabbitmq_erlang_cookie fact + from earlier versions of this module. It manages the content of the cookie + usually located at "${rabbitmq_home}/.erlang.cookie", which includes + stopping the rabbitmq service and wiping out the database at + "${rabbitmq_home}/mnesia" if the user agrees to it. We don't recommend using + this type directly. + DESC newparam(:path, namevar: true) diff --git a/lib/puppet/type/rabbitmq_exchange.rb b/lib/puppet/type/rabbitmq_exchange.rb index 4f274f2ad..f797d3651 100644 --- a/lib/puppet/type/rabbitmq_exchange.rb +++ b/lib/puppet/type/rabbitmq_exchange.rb @@ -1,21 +1,23 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_exchange) do - desc <<-DESC -Native type for managing rabbitmq exchanges + desc <<~DESC + Native type for managing rabbitmq exchanges -@example Create a rabbitmq_exchange - rabbitmq_exchange { 'myexchange@myvhost': - user => 'dan', - password => 'bar', - type => 'topic', - ensure => present, - internal => false, - auto_delete => false, - durable => true, - arguments => { - hash-header => 'message-distribution-hash' - } - } -DESC + @example Create a rabbitmq_exchange + rabbitmq_exchange { 'myexchange@myvhost': + user => 'dan', + password => 'bar', + type => 'topic', + ensure => present, + internal => false, + auto_delete => false, + durable => true, + arguments => { + hash-header => 'message-distribution-hash' + } + } + DESC ensurable do defaultto(:present) @@ -73,9 +75,7 @@ end validate do - if self[:ensure] == :present && self[:type].nil? - raise ArgumentError, "must set type when creating exchange for #{self[:name]} whose type is #{self[:type]}" - end + raise ArgumentError, "must set type when creating exchange for #{self[:name]} whose type is #{self[:type]}" if self[:ensure] == :present && self[:type].nil? end autorequire(:rabbitmq_vhost) do diff --git a/lib/puppet/type/rabbitmq_parameter.rb b/lib/puppet/type/rabbitmq_parameter.rb index da685a845..502ba25ed 100644 --- a/lib/puppet/type/rabbitmq_parameter.rb +++ b/lib/puppet/type/rabbitmq_parameter.rb @@ -1,37 +1,39 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_parameter) do - desc <<-DESC -Type for managing rabbitmq parameters - -@example Create some rabbitmq_parameter resources - rabbitmq_parameter { 'documentumShovel@/': - component_name => '', - value => { - 'src-uri' => 'amqp://', - 'src-queue' => 'my-queue', - 'dest-uri' => 'amqp://remote-server', - 'dest-queue' => 'another-queue', - }, - } - rabbitmq_parameter { 'documentumFed@/': - component_name => 'federation-upstream', - value => { - 'uri' => 'amqp://myserver', - 'expires' => '360000', - }, - } - rabbitmq_parameter { 'documentumShovelNoMunging@/': - component_name => '', - value => { - 'src-uri' => 'amqp://', - 'src-exchange' => 'my-exchange', - 'src-exchange-key' => '6', - 'src-queue' => 'my-queue', - 'dest-uri' => 'amqp://remote-server', - 'dest-exchange' => 'another-exchange', - }, - autoconvert => false, - } -DESC + desc <<~DESC + Type for managing rabbitmq parameters + + @example Create some rabbitmq_parameter resources + rabbitmq_parameter { 'documentumShovel@/': + component_name => '', + value => { + 'src-uri' => 'amqp://', + 'src-queue' => 'my-queue', + 'dest-uri' => 'amqp://remote-server', + 'dest-queue' => 'another-queue', + }, + } + rabbitmq_parameter { 'documentumFed@/': + component_name => 'federation-upstream', + value => { + 'uri' => 'amqp://myserver', + 'expires' => '360000', + }, + } + rabbitmq_parameter { 'documentumShovelNoMunging@/': + component_name => '', + value => { + 'src-uri' => 'amqp://', + 'src-exchange' => 'my-exchange', + 'src-exchange-key' => '6', + 'src-queue' => 'my-queue', + 'dest-uri' => 'amqp://remote-server', + 'dest-exchange' => 'another-exchange', + }, + autoconvert => false, + } + DESC ensurable do defaultto(:present) @@ -94,15 +96,15 @@ def validate_component_name(value) def validate_value(value) raise ArgumentError, 'Invalid value' unless [Hash].include?(value.class) + value.each do |_k, v| - unless [String, TrueClass, FalseClass, Array].include?(v.class) - raise ArgumentError, 'Invalid value' - end + raise ArgumentError, 'Invalid value' unless [String, TrueClass, FalseClass, Array].include?(v.class) end end def munge_value(value) return value if value(:autoconvert) == :false + value.each do |k, v| value[k] = v.to_i if v =~ %r{\A[-+]?[0-9]+\z} end diff --git a/lib/puppet/type/rabbitmq_plugin.rb b/lib/puppet/type/rabbitmq_plugin.rb index f9d592c89..4ca83c312 100644 --- a/lib/puppet/type/rabbitmq_plugin.rb +++ b/lib/puppet/type/rabbitmq_plugin.rb @@ -1,21 +1,23 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_plugin) do - desc <<-DESC -manages rabbitmq plugins + desc <<~DESC + manages rabbitmq plugins -@example query all currently enabled plugins - $ puppet resource rabbitmq_plugin + @example query all currently enabled plugins + $ puppet resource rabbitmq_plugin -@example Ensure a rabbitmq_plugin resource - rabbitmq_plugin {'rabbitmq_stomp': - ensure => present, - } + @example Ensure a rabbitmq_plugin resource + rabbitmq_plugin {'rabbitmq_stomp': + ensure => present, + } -@example Ensure a rabbitmq_plugin offline resource (with RabbitMQ version >=3.4.0) - rabbitmq_plugin {'rabbitmq_stomp': - ensure => present, - mode => 'offline', - } -DESC + @example Ensure a rabbitmq_plugin offline resource (with RabbitMQ version >=3.4.0) + rabbitmq_plugin {'rabbitmq_stomp': + ensure => present, + mode => 'offline', + } + DESC ensurable do defaultto(:present) @@ -43,6 +45,7 @@ defaultto '0022' munge do |value| raise Puppet::Error, "The umask specification is invalid: #{value.inspect}" unless value =~ %r{^0?[0-7]{1,3}$} + return value.to_i(8) end end diff --git a/lib/puppet/type/rabbitmq_policy.rb b/lib/puppet/type/rabbitmq_policy.rb index a118525a3..f85f1ca8c 100644 --- a/lib/puppet/type/rabbitmq_policy.rb +++ b/lib/puppet/type/rabbitmq_policy.rb @@ -1,18 +1,20 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_policy) do - desc <<-DESC -Type for managing rabbitmq policies + desc <<~DESC + Type for managing rabbitmq policies -@example Create a rabbitmq_policy - rabbitmq_policy { 'ha-all@myvhost': - pattern => '.*', - priority => 0, - applyto => 'all', - definition => { - 'ha-mode' => 'all', - 'ha-sync-mode' => 'automatic', - }, - } -DESC + @example Create a rabbitmq_policy + rabbitmq_policy { 'ha-all@myvhost': + pattern => '.*', + priority => 0, + applyto => 'all', + definition => { + 'ha-mode' => 'all', + 'ha-sync-mode' => 'automatic', + }, + } + DESC ensurable do defaultto(:present) @@ -78,95 +80,58 @@ def validate_pattern(value) end def validate_definition(definition) - unless [Hash].include?(definition.class) - raise ArgumentError, 'Invalid definition' - end + raise ArgumentError, 'Invalid definition' unless [Hash].include?(definition.class) + definition.each do |k, v| if k == 'ha-params' && definition['ha-mode'] == 'nodes' - unless [Array].include?(v.class) - raise ArgumentError, "Invalid definition, value #{v} for key #{k} is not an array" - end + raise ArgumentError, "Invalid definition, value #{v} for key #{k} is not an array" unless [Array].include?(v.class) else - unless [String].include?(v.class) - raise ArgumentError, "Invalid definition, value #{v} is not a string" - end + raise ArgumentError, "Invalid definition, value #{v} is not a string" unless [String].include?(v.class) end end if definition['ha-mode'] == 'exactly' ha_params = definition['ha-params'] - unless ha_params.to_i.to_s == ha_params - raise ArgumentError, "Invalid ha-params '#{ha_params}' for ha-mode 'exactly'" - end + 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'] - unless expires_val.to_i.to_s == expires_val - raise ArgumentError, "Invalid expires value '#{expires_val}'" - end + 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'] - unless message_ttl_val.to_i.to_s == message_ttl_val - raise ArgumentError, "Invalid message-ttl value '#{message_ttl_val}'" - end + 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'] - unless max_length_val.to_i.to_s == max_length_val - raise ArgumentError, "Invalid max-length value '#{max_length_val}'" - end + 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'] - unless max_length_bytes_val.to_i.to_s == max_length_bytes_val - raise ArgumentError, "Invalid max-length-bytes value '#{max_length_bytes_val}'" - end + 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'] - unless shards_per_node_val.to_i.to_s == shards_per_node_val - raise ArgumentError, "Invalid shards-per-node value '#{shards_per_node_val}'" - end + 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'] - unless ha_sync_batch_size_val.to_i.to_s == ha_sync_batch_size_val - raise ArgumentError, "Invalid ha-sync-batch-size value '#{ha_sync_batch_size_val}'" - end + 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' # rubocop:disable Style/GuardClause delivery_limit_val = definition['delivery-limit'] - unless delivery_limit_val.to_i.to_s == delivery_limit_val - raise ArgumentError, "Invalid delivery-limit value '#{delivery_limit_val}'" - end + raise ArgumentError, "Invalid delivery-limit value '#{delivery_limit_val}'" unless delivery_limit_val.to_i.to_s == delivery_limit_val end end def munge_definition(definition) - if definition['ha-mode'] == 'exactly' - definition['ha-params'] = definition['ha-params'].to_i - end - if definition.key? 'expires' - definition['expires'] = definition['expires'].to_i - end - if definition.key? 'message-ttl' - definition['message-ttl'] = definition['message-ttl'].to_i - end - if definition.key? 'max-length' - definition['max-length'] = definition['max-length'].to_i - end - if definition.key? 'max-length-bytes' - definition['max-length-bytes'] = definition['max-length-bytes'].to_i - end - if definition.key? 'shards-per-node' - definition['shards-per-node'] = definition['shards-per-node'].to_i - end - if definition.key? 'ha-sync-batch-size' - definition['ha-sync-batch-size'] = definition['ha-sync-batch-size'].to_i - end - if definition.key? 'delivery-limit' - definition['delivery-limit'] = definition['delivery-limit'].to_i - end + 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 end end diff --git a/lib/puppet/type/rabbitmq_queue.rb b/lib/puppet/type/rabbitmq_queue.rb index 63fc19ba5..bc7ec029c 100644 --- a/lib/puppet/type/rabbitmq_queue.rb +++ b/lib/puppet/type/rabbitmq_queue.rb @@ -1,20 +1,22 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_queue) do - desc <<-DESC -Native type for managing rabbitmq queue + desc <<~DESC + Native type for managing rabbitmq queue -@example Create a rabbitmq_queue - rabbitmq_queue { 'myqueue@myvhost': - ensure => present, - user => 'dan', - password => 'bar', - durable => true, - auto_delete => false, - arguments => { - x-message-ttl => 123, - x-dead-letter-exchange => 'other' - }, - } -DESC + @example Create a rabbitmq_queue + rabbitmq_queue { 'myqueue@myvhost': + ensure => present, + user => 'dan', + password => 'bar', + durable => true, + auto_delete => false, + arguments => { + x-message-ttl => 123, + x-dead-letter-exchange => 'other' + }, + } + DESC ensurable do defaultto(:present) diff --git a/lib/puppet/type/rabbitmq_user.rb b/lib/puppet/type/rabbitmq_user.rb index 21120f942..2fa81e939 100644 --- a/lib/puppet/type/rabbitmq_user.rb +++ b/lib/puppet/type/rabbitmq_user.rb @@ -1,24 +1,26 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_user) do - desc <<-DESC -Native type for managing rabbitmq users - -@example query all current users - $ puppet resource rabbitmq_user - -@example Configure a user, dan - rabbitmq_user { 'dan': - admin => true, - password => 'bar', - } - -@example Optional parameter tags will set further rabbitmq tags like monitoring, policymaker, etc. - To set the administrator tag use admin-flag. - rabbitmq_user { 'dan': - admin => true, - password => 'bar', - tags => ['monitoring', 'tag1'], - } -DESC + desc <<~DESC + Native type for managing rabbitmq users + + @example query all current users + $ puppet resource rabbitmq_user + + @example Configure a user, dan + rabbitmq_user { 'dan': + admin => true, + password => 'bar', + } + + @example Optional parameter tags will set further rabbitmq tags like monitoring, policymaker, etc. + To set the administrator tag use admin-flag. + rabbitmq_user { 'dan': + admin => true, + password => 'bar', + tags => ['monitoring', 'tag1'], + } + DESC ensurable do defaultto(:present) @@ -71,13 +73,9 @@ def should_to_s(_value) newproperty(:tags, array_matching: :all) do desc 'additional tags for the user' validate do |value| - unless value =~ %r{^\S+$} - raise ArgumentError, "Invalid tag: #{value.inspect}" - end + raise ArgumentError, "Invalid tag: #{value.inspect}" unless value =~ %r{^\S+$} - if value == 'administrator' - raise ArgumentError, 'must use admin property instead of administrator tag' - end + raise ArgumentError, 'must use admin property instead of administrator tag' if value == 'administrator' end defaultto [] diff --git a/lib/puppet/type/rabbitmq_user_permissions.rb b/lib/puppet/type/rabbitmq_user_permissions.rb index a1fc92986..7ec46a375 100644 --- a/lib/puppet/type/rabbitmq_user_permissions.rb +++ b/lib/puppet/type/rabbitmq_user_permissions.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_user_permissions) do - desc <<-DESC -Type for managing rabbitmq user permissions + desc <<~DESC + Type for managing rabbitmq user permissions -@example Define some rabbitmq_user_permissions - rabbitmq_user_permissions { 'dan@myvhost': - configure_permission => '.*', - read_permission => '.*', - write_permission => '.*', - } -DESC + @example Define some rabbitmq_user_permissions + rabbitmq_user_permissions { 'dan@myvhost': + configure_permission => '.*', + read_permission => '.*', + write_permission => '.*', + } + DESC ensurable do defaultto(:present) diff --git a/lib/puppet/type/rabbitmq_vhost.rb b/lib/puppet/type/rabbitmq_vhost.rb index 8e9407e93..16809b008 100644 --- a/lib/puppet/type/rabbitmq_vhost.rb +++ b/lib/puppet/type/rabbitmq_vhost.rb @@ -1,15 +1,17 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:rabbitmq_vhost) do - desc <<-DESC -Native type for managing rabbitmq vhosts + desc <<~DESC + Native type for managing rabbitmq vhosts -@example query all current vhosts - $ puppet resource rabbitmq_vhost` + @example query all current vhosts + $ puppet resource rabbitmq_vhost` -@example Create a rabbitmq_vhost - rabbitmq_vhost { 'myvhost': - ensure => present, - } -DESC + @example Create a rabbitmq_vhost + rabbitmq_vhost { 'myvhost': + ensure => present, + } + DESC ensurable do defaultto(:present) diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 80e352a7e..e6886b6aa 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'rabbitmq class:' do @@ -121,12 +123,15 @@ class { 'rabbitmq': describe service(service_name) do it { is_expected.to be_running } end + describe port(5672) do it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end + describe port(15_672) do it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end + describe port(25_672) do xit 'Is on 55672 instead on older rmq versions' do is_expected.to be_listening.on('0.0.0.0').with('tcp') @@ -151,13 +156,16 @@ class { 'rabbitmq': describe service(service_name) do it { is_expected.to be_running } end + describe port(5672) do it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } end + describe port(15_672) do it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } end # This listens on all interfaces regardless of these settings + describe port(25_672) do xit 'Is on 55672 instead on older rmq versions' do is_expected.to be_listening.on('0.0.0.0').with('tcp') @@ -186,9 +194,11 @@ class { 'rabbitmq': describe service(service_name) do it { is_expected.to be_running } end + describe port(5671) do it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end + describe port(15_671) do it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end @@ -212,12 +222,15 @@ class { 'rabbitmq': describe service(service_name) do it { is_expected.to be_running } end + describe port(5672) do it { is_expected.to be_listening.on('0.0.0.0').with('tcp') } end + describe port(15_672) do it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } end + describe port(25_672) do xit 'Is on 55672 instead on older rmq versions' do is_expected.to be_listening.on('0.0.0.0').with('tcp') diff --git a/spec/acceptance/clustering_spec.rb b/spec/acceptance/clustering_spec.rb index 634992909..bf0452c46 100644 --- a/spec/acceptance/clustering_spec.rb +++ b/spec/acceptance/clustering_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'rabbitmq clustering' do @@ -26,6 +28,7 @@ class { 'erlang': epel_enable => true} it { is_expected.not_to contain 'TESTCOOKIE' } end end + context 'rabbitmq::wipe_db_on_cookie_change => true' do it 'runs successfully' do pp = <<-EOS @@ -67,7 +70,6 @@ class { 'erlang': epel_enable => true} expect(r.stdout).to match(%r!({cluster_name,<<"rabbit_cluster">>}|^Cluster name: rabbit_cluster$)!) expect(r.exit_code).to be_zero end - # rubocop:enable RSpec/MultipleExpectations end end end diff --git a/spec/acceptance/delete_guest_user_spec.rb b/spec/acceptance/delete_guest_user_spec.rb index f8a6bc0f4..15bdff93f 100644 --- a/spec/acceptance/delete_guest_user_spec.rb +++ b/spec/acceptance/delete_guest_user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'rabbitmq with delete_guest_user' do diff --git a/spec/acceptance/parameter_spec.rb b/spec/acceptance/parameter_spec.rb index 85d31c639..e7ac8773d 100644 --- a/spec/acceptance/parameter_spec.rb +++ b/spec/acceptance/parameter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'rabbitmq parameter on a vhost:' do @@ -35,12 +37,12 @@ class { 'rabbitmq': apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end + it 'has the parameter' do shell('rabbitmqctl list_parameters -p fedhost') do |r| expect(r.stdout).to match(%r{federation-upstream.*documentumFed.*expires.*3600000}) expect(r.exit_code).to be_zero end end - # rubocop:enable RSpec/MultipleExpectations end end diff --git a/spec/acceptance/policy_spec.rb b/spec/acceptance/policy_spec.rb index f13af54d3..1cd126344 100644 --- a/spec/acceptance/policy_spec.rb +++ b/spec/acceptance/policy_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'rabbitmq policy on a vhost:' do @@ -46,6 +48,7 @@ class { 'rabbitmq': apply_manifest(pp, catch_failures: true) expect(apply_manifest(pp, catch_changes: true).exit_code).to be_zero end + it 'has the policy' do shell('rabbitmqctl list_policies -p myhost') do |r| expect(r.stdout).to match(%r{myhost.*ha-all.*ha-sync-mode}) @@ -53,6 +56,5 @@ class { 'rabbitmq': expect(r.exit_code).to be_zero end end - # rubocop:enable RSpec/MultipleExpectations end end diff --git a/spec/acceptance/queue_spec.rb b/spec/acceptance/queue_spec.rb index 0cb4f16c4..2934796e9 100644 --- a/spec/acceptance/queue_spec.rb +++ b/spec/acceptance/queue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'rabbitmq binding:' do @@ -59,6 +61,7 @@ class { 'rabbitmq': apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end + it 'has the binding' do shell('rabbitmqctl list_bindings -q -p host1') do |r| expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\s#}) @@ -72,7 +75,6 @@ class { 'rabbitmq': expect(r.exit_code).to be_zero end end - # rubocop:enable RSpec/MultipleExpectations end context 'create multiple bindings when same source / destination / vhost but different routing keys' do @@ -147,6 +149,7 @@ class { 'rabbitmq': apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end + it 'has the bindings' do shell('rabbitmqctl list_bindings -q -p host1') do |r| expect(r.stdout).to match(%r{exchange1\sexchange\squeue1\squeue\stest1}) @@ -154,7 +157,6 @@ class { 'rabbitmq': expect(r.exit_code).to be_zero end end - # rubocop:enable RSpec/MultipleExpectations it 'puppet resource shows a binding' do shell('puppet resource rabbitmq_binding') do |r| @@ -222,6 +224,7 @@ class { 'rabbitmq': apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end + it 'has the binding' do shell('rabbitmqctl list_bindings -q -p host2') do |r| expect(r.stdout).to match(%r{exchange2\sexchange\squeue2\squeue\s#}) @@ -235,6 +238,5 @@ class { 'rabbitmq': expect(r.exit_code).to be_zero end end - # rubocop:enable RSpec/MultipleExpectations end end diff --git a/spec/acceptance/rabbitmqadmin_spec.rb b/spec/acceptance/rabbitmqadmin_spec.rb index 149e42374..fa127f1b4 100644 --- a/spec/acceptance/rabbitmqadmin_spec.rb +++ b/spec/acceptance/rabbitmqadmin_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'rabbitmq::install::rabbitmqadmin class' do diff --git a/spec/acceptance/user_spec.rb b/spec/acceptance/user_spec.rb index 7b8e24517..a8d369218 100644 --- a/spec/acceptance/user_spec.rb +++ b/spec/acceptance/user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'rabbitmq user:' do @@ -24,13 +26,13 @@ class { 'rabbitmq': apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end + it 'has the user' do shell('rabbitmqctl list_users -q') do |r| expect(r.stdout).to match(%r{dan.*administrator}) expect(r.exit_code).to be_zero end end - # rubocop:enable RSpec/MultipleExpectations end context 'destroy user resource' do diff --git a/spec/acceptance/vhost_spec.rb b/spec/acceptance/vhost_spec.rb index 16a63d839..782e33df9 100644 --- a/spec/acceptance/vhost_spec.rb +++ b/spec/acceptance/vhost_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'rabbitmq vhost:' do @@ -23,12 +25,12 @@ class { 'rabbitmq': apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end + it 'has the vhost' do shell('rabbitmqctl list_vhosts') do |r| expect(r.stdout).to match(%r{myhost}) expect(r.exit_code).to be_zero end end - # rubocop:enable RSpec/MultipleExpectations end end diff --git a/spec/classes/rabbitmq_spec.rb b/spec/classes/rabbitmq_spec.rb index 8cab1f2b1..f065552e1 100644 --- a/spec/classes/rabbitmq_spec.rb +++ b/spec/classes/rabbitmq_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'rabbitmq' do @@ -20,9 +22,8 @@ it { is_expected.to contain_class('rabbitmq::service') } it { is_expected.to contain_package(name).with_ensure('installed').with_name(name) } - if facts[:os]['family'] == 'Suse' - it { is_expected.to contain_package('rabbitmq-server-plugins') } - end + + it { is_expected.to contain_package('rabbitmq-server-plugins') } if facts[:os]['family'] == 'Suse' context 'with default params' do it { is_expected.not_to contain_class('rabbitmq::repo::apt') } @@ -86,9 +87,9 @@ describe 'it sets up an apt::source' do it { is_expected.to contain_apt__source('rabbitmq').with( - 'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{facts[:os]['name'].downcase}", - 'repos' => 'main', - 'key' => "{\"id\"=>\"8C695B0219AFDEB04A058ED8F4E789204D206F89\", \"source\"=>\"https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey\", \"content\"=>#{expected_key_apt_source_key_content}}" + 'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{facts[:os]['name'].downcase}", + 'repos' => 'main', + 'key' => "{\"id\"=>\"8C695B0219AFDEB04A058ED8F4E789204D206F89\", \"source\"=>\"https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey\", \"content\"=>#{expected_key_apt_source_key_content}}" ) } end @@ -106,9 +107,9 @@ describe 'it sets up an apt::source and pin' do it { is_expected.to contain_apt__source('rabbitmq').with( - 'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{facts[:os]['name'].downcase}", - 'repos' => 'main', - 'key' => "{\"id\"=>\"8C695B0219AFDEB04A058ED8F4E789204D206F89\", \"source\"=>\"https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey\", \"content\"=>#{expected_key_apt_source_key_content}}" + 'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{facts[:os]['name'].downcase}", + 'repos' => 'main', + 'key' => "{\"id\"=>\"8C695B0219AFDEB04A058ED8F4E789204D206F89\", \"source\"=>\"https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey\", \"content\"=>#{expected_key_apt_source_key_content}}" ) } @@ -116,7 +117,7 @@ is_expected.to contain_apt__pin('rabbitmq').with( 'packages' => '*', 'priority' => '700', - 'origin' => 'packagecloud.io' + 'origin' => 'packagecloud.io' ) } end @@ -226,6 +227,7 @@ is_expected.to contain_package('rabbitmqadmin').with_name('blub') end end + if facts[:os]['family'] == 'Archlinux' it 'installs a package called rabbitmqadmin' do is_expected.to contain_package('rabbitmqadmin').with_name('rabbitmqadmin') @@ -239,13 +241,10 @@ is_expected.to contain_archive('rabbitmqadmin').with_source('http://1.1.1.1:15672/cli/rabbitmqadmin') end end - if %w[RedHat Debian SUSE].include?(facts[:os]['family']) - it { is_expected.to contain_package('python') } - end - if %w[FreeBSD OpenBSD].include?(facts[:os]['family']) - it { is_expected.to contain_package('python2') } - end + it { is_expected.to contain_package('python') } if %w[RedHat Debian SUSE].include?(facts[:os]['family']) + it { is_expected.to contain_package('python2') } if %w[FreeBSD OpenBSD].include?(facts[:os]['family']) end + context 'with manage_python false' do let(:params) { { manage_python: false } } @@ -267,6 +266,7 @@ is_expected.to contain_archive('rabbitmqadmin').with_source('http://127.0.0.1:15672/cli/rabbitmqadmin') end end + context 'with service_manage set to true, node_ip_address = undef, and default user/pass specified', unless: facts[:osfamily] == 'Archlinux' do let(:params) { { admin_enable: true, default_user: 'foobar', default_pass: 'hunter2', node_ip_address: :undef } } @@ -278,6 +278,7 @@ ) end end + context 'with service_manage set to true and default user/pass specified', unless: facts[:osfamily] == 'Archlinux' do let(:params) { { admin_enable: true, default_user: 'foobar', default_pass: 'hunter2', management_ip_address: '1.1.1.1' } } @@ -289,6 +290,7 @@ ) end end + context 'with service_manage set to true and archive_options set', unless: facts[:osfamily] == 'Archlinux' do let(:params) do { @@ -305,8 +307,9 @@ ) end end + context 'with service_manage set to true and management port specified', unless: facts[:osfamily] == 'Archlinux' do - # note that the 2.x management port is 55672 not 15672 + # NOTE: that the 2.x management port is 55672 not 15672 let(:params) { { admin_enable: true, management_port: 55_672, management_ip_address: '1.1.1.1' } } it 'we use the correct URL to rabbitmqadmin' do @@ -317,8 +320,9 @@ ) end end + context 'with ipv6, service_manage set to true and management port specified', unless: facts[:osfamily] == 'Archlinux' do - # note that the 2.x management port is 55672 not 15672 + # NOTE: that the 2.x management port is 55672 not 15672 let(:params) { { admin_enable: true, management_port: 55_672, management_ip_address: '::1' } } it 'we use the correct URL to rabbitmqadmin' do @@ -329,6 +333,7 @@ ) end end + context 'with service_manage set to false' do let(:params) { { admin_enable: true, service_manage: false } } @@ -343,9 +348,9 @@ it { is_expected.to contain_file('/etc/rabbitmq').with( 'ensure' => 'directory', - 'owner' => 'rabbitmq', - 'group' => 'rabbitmq', - 'mode' => '2755' + 'owner' => 'rabbitmq', + 'group' => 'rabbitmq', + 'mode' => '2755' ) } end @@ -355,7 +360,7 @@ is_expected.to contain_file('rabbitmq.config').with( 'owner' => 'rabbitmq', 'group' => 'rabbitmq', - 'mode' => '0640' + 'mode' => '0640' ) } end @@ -364,9 +369,9 @@ it { is_expected.to contain_file('/etc/rabbitmq/ssl').with( 'ensure' => 'directory', - 'owner' => 'rabbitmq', - 'group' => 'rabbitmq', - 'mode' => '2750' + 'owner' => 'rabbitmq', + 'group' => 'rabbitmq', + 'mode' => '2750' ) } end @@ -395,7 +400,7 @@ let(:params) do { config_cluster: true, - cluster_nodes: ['hare-1', 'hare-2'], + cluster_nodes: %w[hare-1 hare-2], cluster_node_type: 'ram', wipe_db_on_cookie_change: false } @@ -405,7 +410,7 @@ let(:params) do { config_cluster: true, - cluster_nodes: ['hare-1', 'hare-2'], + cluster_nodes: %w[hare-1 hare-2], cluster_node_type: 'ram', erlang_cookie: 'TESTCOOKIE', wipe_db_on_cookie_change: true @@ -446,7 +451,7 @@ let(:params) do { config_cluster: true, - cluster_nodes: ['hare-1', 'hare-2'], + cluster_nodes: %w[hare-1 hare-2], cluster_node_type: 'ram', erlang_cookie: 'ORIGINAL', wipe_db_on_cookie_change: true @@ -471,13 +476,13 @@ let(:params) do { environment_variables: { 'NODE_IP_ADDRESS' => '1.1.1.1', - 'NODE_PORT' => '5656', - 'NODENAME' => 'HOSTNAME', - 'SERVICENAME' => 'RabbitMQ', - 'CONSOLE_LOG' => 'RabbitMQ.debug', - 'CTL_ERL_ARGS' => 'verbose', - 'SERVER_ERL_ARGS' => 'v', - 'SERVER_START_ARGS' => 'debug' + 'NODE_PORT' => '5656', + 'NODENAME' => 'HOSTNAME', + 'SERVICENAME' => 'RabbitMQ', + 'CONSOLE_LOG' => 'RabbitMQ.debug', + 'CTL_ERL_ARGS' => 'verbose', + 'SERVER_ERL_ARGS' => 'v', + 'SERVER_START_ARGS' => 'debug' } } end @@ -505,7 +510,7 @@ it 'removes the user' do is_expected.to contain_rabbitmq_user('guest').with( - 'ensure' => 'absent', + 'ensure' => 'absent', 'provider' => 'rabbitmqctl' ) end @@ -527,6 +532,7 @@ is_expected.to contain_file('rabbitmq.config').without('content' => %r{stomp}) end end + describe 'stomp when set' do let(:params) { { config_stomp: true, stomp_port: 5679 } } @@ -534,6 +540,7 @@ is_expected.to contain_file('rabbitmq.config').with('content' => %r{rabbitmq_stomp.*tcp_listeners, \[5679\]}m) end end + describe 'stomp when set ssl port w/o ssl enabled' do let(:params) { { config_stomp: true, stomp_port: 5679, ssl: false, ssl_stomp_port: 5680 } } @@ -541,6 +548,7 @@ is_expected.to contain_file('rabbitmq.config').without('content' => %r{rabbitmq_stomp.*ssl_listeners, \[5680\]}m) end end + describe 'stomp when set with ssl' do let(:params) { { config_stomp: true, stomp_port: 5679, ssl: true, ssl_stomp_port: 5680 } } @@ -734,6 +742,7 @@ end it { is_expected.to contain_rabbitmq_plugin('rabbitmq_management') } + it 'sets rabbitmq_managment opts to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[}) @@ -760,6 +769,7 @@ end it { is_expected.to contain_rabbitmq_plugin('rabbitmq_management') } + it 'sets rabbitmq_managment opts to specified values' do is_expected.to contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[}) is_expected.to contain_file('rabbitmq.config').with_content(%r{listener, \[}) @@ -936,6 +946,7 @@ %r{dhfile,} ) end + it 'sets non ssl port for management port' do is_expected.to contain_file('rabbitmq.config').with_content( %r{port, 13142} @@ -994,11 +1005,13 @@ %r{dhfile,} ) end + it 'sets ssl managment port to specified values' do is_expected.to contain_file('rabbitmq.config').with_content( %r{port, 13141} ) end + it 'sets ssl options in the rabbitmqadmin.conf' do is_expected.to contain_file('rabbitmqadmin.conf').with_content( %r{ssl_ca_cert_file\s=\s/path/to/cacert} @@ -1098,6 +1111,7 @@ is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"}) is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key}) end + it 'does not set TCP listener environment defaults' do is_expected.to contain_file('rabbitmq-env.config'). \ without_content(%r{NODE_PORT=}). \ @@ -1183,7 +1197,7 @@ ssl_cacert: '/path/to/cacert', ssl_cert: '/path/to/cert', ssl_key: '/path/to/key', - ssl_ciphers: ['ECDHE-RSA-AES256-SHA', 'DHE-RSA-AES256-SHA'] } + ssl_ciphers: %w[ECDHE-RSA-AES256-SHA DHE-RSA-AES256-SHA] } end it 'sets ssl ciphers to specified values' do @@ -1443,6 +1457,7 @@ is_expected.to contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/management_cert"\},}) is_expected.to contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/management_key"\}}) end + it 'sets ssl options in the rabbitmqadmin.conf' do is_expected.to contain_file('rabbitmqadmin.conf').with_content( %r{ssl_ca_cert_file\s=\s/path/to/management_cacert} @@ -1490,7 +1505,7 @@ let(:params) do { ipv6: true, environment_variables: { 'RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS' => '"some quoted args"', - 'RABBITMQ_CTL_ERL_ARGS' => '"other quoted args"' } } + 'RABBITMQ_CTL_ERL_ARGS' => '"other quoted args"' } } end it 'enables inet6 distribution and quote properly' do @@ -1504,7 +1519,7 @@ let(:params) do { ipv6: true, environment_variables: { 'RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS' => 'foo', - 'RABBITMQ_CTL_ERL_ARGS' => 'bar' } } + 'RABBITMQ_CTL_ERL_ARGS' => 'bar' } } end it 'enables inet6 distribution and quote properly' do @@ -1532,7 +1547,7 @@ { ipv6: true, ssl_erl_dist: true, environment_variables: { 'RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS' => '"some quoted args"', - 'RABBITMQ_CTL_ERL_ARGS' => '"other quoted args"' } } + 'RABBITMQ_CTL_ERL_ARGS' => '"other quoted args"' } } end it 'enables inet6 distribution and quote properly' do @@ -1547,7 +1562,7 @@ { ipv6: true, ssl_erl_dist: true, environment_variables: { 'RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS' => 'foo', - 'RABBITMQ_CTL_ERL_ARGS' => 'bar' } } + 'RABBITMQ_CTL_ERL_ARGS' => 'bar' } } end it 'enables inet6 distribution and quote properly' do @@ -1562,10 +1577,10 @@ let(:params) do { config_variables: { 'hipe_compile' => true, - 'vm_memory_high_watermark' => 0.4, - 'frame_max' => 131_072, - 'collect_statistics' => 'none', - 'auth_mechanisms' => "['PLAIN', 'AMQPLAIN']" + 'vm_memory_high_watermark' => 0.4, + 'frame_max' => 131_072, + 'collect_statistics' => 'none', + 'auth_mechanisms' => "['PLAIN', 'AMQPLAIN']" } } end @@ -1696,7 +1711,7 @@ it 'removes the user' do is_expected.to contain_rabbitmq_user('guest').with( - 'ensure' => 'absent', + 'ensure' => 'absent', 'provider' => 'rabbitmqctl' ) end @@ -1724,7 +1739,7 @@ it 'sets the loopback_users parameter in the config file' do is_expected.to contain_file('rabbitmq.config'). \ - with_content(%r{\{loopback_users, \[<<\"user1\">>, <<\"user2\">>\]\}}) + with_content(%r{\{loopback_users, \[<<"user1">>, <<"user2">>\]\}}) end end @@ -1734,11 +1749,11 @@ describe 'service with default params' do it { is_expected.to contain_service('rabbitmq-server').with( - 'ensure' => 'running', - 'enable' => 'true', - 'hasstatus' => 'true', + 'ensure' => 'running', + 'enable' => 'true', + 'hasstatus' => 'true', 'hasrestart' => 'true', - 'name' => name + 'name' => name ) } end @@ -1757,8 +1772,8 @@ it { is_expected.to contain_service('rabbitmq-server').with( - 'ensure' => 'stopped', - 'enable' => false + 'ensure' => 'stopped', + 'enable' => false ) } end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index eb2564317..94706e396 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'voxpupuli/acceptance/spec_helper_acceptance' configure_beaker do |host| diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index 41ef97e02..b0fca3a88 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + add_custom_fact :rabbitmq_version, '3.6.1' # puppet-rabbitmq add_custom_fact :erl_ssl_path, '/usr/lib64/erlang/lib/ssl-7.3.3.1/ebin' # puppet-rabbitmq diff --git a/spec/unit/facter/util/fact_erl_ssl_path_spec.rb b/spec/unit/facter/util/fact_erl_ssl_path_spec.rb index 0717533bf..ebd57b577 100644 --- a/spec/unit/facter/util/fact_erl_ssl_path_spec.rb +++ b/spec/unit/facter/util/fact_erl_ssl_path_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Facter::Util::Fact do diff --git a/spec/unit/facter/util/fact_rabbitmq_clustername_spec.rb b/spec/unit/facter/util/fact_rabbitmq_clustername_spec.rb index 1f7488430..abd3228d1 100644 --- a/spec/unit/facter/util/fact_rabbitmq_clustername_spec.rb +++ b/spec/unit/facter/util/fact_rabbitmq_clustername_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Facter::Util::Fact do @@ -40,25 +42,25 @@ context 'rabbitmq is not running' do it do - error_string = <<-EOS -Status of node 'monty@rabbit-1' ... -Error: unable to connect to node 'monty@rabbit-1': nodedown + error_string = <<~EOS + Status of node 'monty@rabbit-1' ... + Error: unable to connect to node 'monty@rabbit-1': nodedown -DIAGNOSTICS -=========== + DIAGNOSTICS + =========== -attempted to contact: ['monty@rabbit-1'] + attempted to contact: ['monty@rabbit-1'] -monty@rabbit-1: - * connected to epmd (port 4369) on centos-7-x64 - * epmd reports: node 'rabbit' not running at all - no other nodes on centos-7-x64 - * suggestion: start the node + monty@rabbit-1: + * connected to epmd (port 4369) on centos-7-x64 + * epmd reports: node 'rabbit' not running at all + no other nodes on centos-7-x64 + * suggestion: start the node -current node details: -- node name: 'rabbitmq-cli-73@centos-7-x64' -- home dir: /var/lib/rabbitmq -- cookie hash: 6WdP0nl6d3HYqA5vTKMkIg== + current node details: + - node name: 'rabbitmq-cli-73@centos-7-x64' + - home dir: /var/lib/rabbitmq + - cookie hash: 6WdP0nl6d3HYqA5vTKMkIg== EOS Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true) diff --git a/spec/unit/facter/util/fact_rabbitmq_nodename_spec.rb b/spec/unit/facter/util/fact_rabbitmq_nodename_spec.rb index 0abf83361..344581965 100644 --- a/spec/unit/facter/util/fact_rabbitmq_nodename_spec.rb +++ b/spec/unit/facter/util/fact_rabbitmq_nodename_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Facter::Util::Fact do @@ -46,25 +48,25 @@ context 'rabbitmq is not running' do it do - error_string = <<-EOS -Status of node 'monty@rabbit-1' ... -Error: unable to connect to node 'monty@rabbit-1': nodedown + error_string = <<~EOS + Status of node 'monty@rabbit-1' ... + Error: unable to connect to node 'monty@rabbit-1': nodedown -DIAGNOSTICS -=========== + DIAGNOSTICS + =========== -attempted to contact: ['monty@rabbit-1'] + attempted to contact: ['monty@rabbit-1'] -monty@rabbit-1: - * connected to epmd (port 4369) on centos-7-x64 - * epmd reports: node 'rabbit' not running at all - no other nodes on centos-7-x64 - * suggestion: start the node + monty@rabbit-1: + * connected to epmd (port 4369) on centos-7-x64 + * epmd reports: node 'rabbit' not running at all + no other nodes on centos-7-x64 + * suggestion: start the node -current node details: -- node name: 'rabbitmq-cli-73@centos-7-x64' -- home dir: /var/lib/rabbitmq -- cookie hash: 6WdP0nl6d3HYqA5vTKMkIg== + current node details: + - node name: 'rabbitmq-cli-73@centos-7-x64' + - home dir: /var/lib/rabbitmq + - cookie hash: 6WdP0nl6d3HYqA5vTKMkIg== EOS Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true) diff --git a/spec/unit/facter/util/fact_rabbitmq_plugins_dirs_spec.rb b/spec/unit/facter/util/fact_rabbitmq_plugins_dirs_spec.rb index 57c41047c..04a10e358 100644 --- a/spec/unit/facter/util/fact_rabbitmq_plugins_dirs_spec.rb +++ b/spec/unit/facter/util/fact_rabbitmq_plugins_dirs_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Facter::Util::Fact do diff --git a/spec/unit/facter/util/fact_rabbitmq_version_spec.rb b/spec/unit/facter/util/fact_rabbitmq_version_spec.rb index 26dfbae62..68c6b6b7c 100644 --- a/spec/unit/facter/util/fact_rabbitmq_version_spec.rb +++ b/spec/unit/facter/util/fact_rabbitmq_version_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Facter::Util::Fact do @@ -13,6 +15,7 @@ expect(Facter.fact(:rabbitmq_version).value).to eq('3.6.0') end end + context 'with invalid value' do it do Facter::Util::Resolution.expects(:which).with('rabbitmqadmin').returns(true) @@ -20,6 +23,7 @@ expect(Facter.fact(:rabbitmq_version).value).to be_nil end end + context 'rabbitmqadmin is not in path' do it do Facter::Util::Resolution.expects(:which).with('rabbitmqadmin').returns(false) diff --git a/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb b/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb index 26b5e28c9..c92384e93 100644 --- a/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:rabbitmq_binding).provider(:rabbitmqadmin) @@ -14,14 +16,14 @@ describe '#instances' do it 'returns instances' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT provider_class.expects(:rabbitmqctl_list).with( 'bindings', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments' - ).returns <<-EOT -exchange\tdst_queue\tqueue\t*\t[] -EOT + ).returns <<~EOT + exchange\tdst_queue\tqueue\t*\t[] + EOT instances = provider_class.instances expect(instances.size).to eq(1) expect(instances.map do |prov| @@ -40,17 +42,17 @@ } ]) end - # rubocop:enable RSpec/MultipleExpectations + it 'returns multiple instances' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT provider_class.expects(:rabbitmqctl_list).with( 'bindings', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments' - ).returns <<-EOT -exchange\tdst_queue\tqueue\trouting_one\t[] -exchange\tdst_queue\tqueue\trouting_two\t[] -EOT + ).returns <<~EOT + exchange\tdst_queue\tqueue\trouting_one\t[] + exchange\tdst_queue\tqueue\trouting_two\t[] + EOT instances = provider_class.instances expect(instances.size).to eq(2) expect(instances.map do |prov| @@ -76,7 +78,6 @@ ]) end end - # rubocop:enable RSpec/MultipleExpectations describe 'Test for prefetch error' do let(:resource) do @@ -91,28 +92,28 @@ end it 'exists' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT provider_class.expects(:rabbitmqctl_list).with( 'bindings', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments' - ).returns <<-EOT -exchange\tdst_queue\tqueue\t*\t[] -EOT + ).returns <<~EOT + exchange\tdst_queue\tqueue\t*\t[] + EOT provider_class.prefetch({}) end it 'matches' do # Test resource to match against - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT provider_class.expects(:rabbitmqctl_list).with( 'bindings', '-p', '/', 'source_name', 'destination_name', 'destination_kind', 'routing_key', 'arguments' - ).returns <<-EOT -exchange\tdst_queue\tqueue\t*\t[] -EOT + ).returns <<~EOT + exchange\tdst_queue\tqueue\t*\t[] + EOT provider_class.prefetch('binding1' => resource) end diff --git a/spec/unit/puppet/provider/rabbitmq_cli_spec.rb b/spec/unit/puppet/provider/rabbitmq_cli_spec.rb index 1f5d16404..d710a40b0 100644 --- a/spec/unit/puppet/provider/rabbitmq_cli_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_cli_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet/provider/rabbitmq_cli' diff --git a/spec/unit/puppet/provider/rabbitmq_cluster/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_cluster/rabbitmqctl_spec.rb index f59cda96b..0e5a19e35 100644 --- a/spec/unit/puppet/provider/rabbitmq_cluster/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_cluster/rabbitmqctl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:rabbitmq_cluster).provider(:rabbitmqctl) diff --git a/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb b/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb index c2b4d774e..ad993f142 100644 --- a/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:rabbitmq_exchange).provider(:rabbitmqadmin) @@ -17,20 +19,20 @@ let(:provider) { provider_class.new(resource) } it 'returns instances' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT - provider_class.expects(:rabbitmqctl_list).with('exchanges', '-p', '/', 'name', 'type', 'internal', 'durable', 'auto_delete', 'arguments').returns <<-EOT - direct false true false [] -amq.direct direct false true false [] -amq.fanout fanout false true false [] -amq.headers headers false true false [] -amq.match headers false true false [] -amq.rabbitmq.log topic true true false [] -amq.rabbitmq.trace topic true true false [] -amq.topic topic false true false [] -test.headers x-consistent-hash false true false [{"hash-header","message-distribution-hash"}] -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT + provider_class.expects(:rabbitmqctl_list).with('exchanges', '-p', '/', 'name', 'type', 'internal', 'durable', 'auto_delete', 'arguments').returns <<~EOT + direct false true false [] + amq.direct direct false true false [] + amq.fanout fanout false true false [] + amq.headers headers false true false [] + amq.match headers false true false [] + amq.rabbitmq.log topic true true false [] + amq.rabbitmq.trace topic true true false [] + amq.topic topic false true false [] + test.headers x-consistent-hash false true false [{"hash-header","message-distribution-hash"}] + EOT instances = provider_class.instances expect(instances.size).to eq(9) end diff --git a/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_federation_spec.rb b/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_federation_spec.rb index 1cd4f6ba9..1aac95c4f 100644 --- a/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_federation_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_federation_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:rabbitmq_parameter).provider(:rabbitmqctl) @@ -7,8 +9,8 @@ name: 'documentumFederation@/', component_name: 'federation', value: { - 'uri' => 'amqp://', - 'expires' => '360000' + 'uri' => 'amqp://', + 'expires' => '360000' } ) end @@ -24,12 +26,12 @@ end it 'matches' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT - provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<-EOT -federation documentumFederation {"uri":"amqp://","expires":360000} -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT + provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<~EOT + federation documentumFederation {"uri":"amqp://","expires":360000} + EOT provider_class.prefetch('documentumFederation@/' => resource) end end @@ -40,17 +42,17 @@ end it 'fail with invalid output from list' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT provider.class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns 'foobar' expect { provider_class.instances }.to raise_error Puppet::Error, %r{cannot parse line from list_parameter} end it 'return no instance' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns '' instances = provider_class.instances expect(instances.size).to eq(0) diff --git a/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb index 609e6e319..5fd3306f4 100644 --- a/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:rabbitmq_parameter).provider(:rabbitmqctl) @@ -7,9 +9,9 @@ name: 'documentumShovel@/', component_name: 'shovel', value: { - 'src-uri' => 'amqp://', - 'src-queue' => 'my-queue', - 'dest-uri' => 'amqp://remote-server', + 'src-uri' => 'amqp://', + 'src-queue' => 'my-queue', + 'dest-uri' => 'amqp://remote-server', 'dest-queue' => 'another-queue' } ) @@ -26,12 +28,12 @@ end it 'matches' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT - provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<-EOT -shovel documentumShovel {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT + provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<~EOT + shovel documentumShovel {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} + EOT provider_class.prefetch('documentumShovel@/' => resource) end end @@ -42,28 +44,29 @@ end it 'fail with invalid output from list' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT provider.class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns 'foobar' expect { provider_class.instances }.to raise_error Puppet::Error, %r{cannot parse line from list_parameter} end it 'return no instance' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns '' instances = provider_class.instances expect(instances.size).to eq(0) end + it 'return one instance' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT - provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<-EOT -shovel documentumShovel {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT + provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<~EOT + shovel documentumShovel {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} + EOT instances = provider_class.instances expect(instances.size).to eq(1) expect(instances.map do |prov| @@ -78,24 +81,24 @@ name: 'documentumShovel@/', component_name: 'shovel', value: { - 'src-uri' => 'amqp://', - 'src-queue' => 'my-queue', - 'dest-uri' => 'amqp://remote-server', + 'src-uri' => 'amqp://', + 'src-queue' => 'my-queue', + 'dest-uri' => 'amqp://remote-server', 'dest-queue' => 'another-queue' } } ] ) end - # rubocop:enable RSpec/MultipleExpectations + it 'return multiple instances' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT - provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<-EOT -shovel documentumShovel1 {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} -shovel documentumShovel2 {"src-uri":["amqp://cl1","amqp://cl2"],"src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT + provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<~EOT + shovel documentumShovel1 {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} + shovel documentumShovel2 {"src-uri":["amqp://cl1","amqp://cl2"],"src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} + EOT instances = provider_class.instances expect(instances.size).to eq(2) expect(instances.map do |prov| @@ -110,9 +113,9 @@ name: 'documentumShovel1@/', component_name: 'shovel', value: { - 'src-uri' => 'amqp://', - 'src-queue' => 'my-queue', - 'dest-uri' => 'amqp://remote-server', + 'src-uri' => 'amqp://', + 'src-queue' => 'my-queue', + 'dest-uri' => 'amqp://remote-server', 'dest-queue' => 'another-queue' } }, @@ -120,9 +123,9 @@ name: 'documentumShovel2@/', component_name: 'shovel', value: { - 'src-uri' => ['amqp://cl1', 'amqp://cl2'], - 'src-queue' => 'my-queue', - 'dest-uri' => 'amqp://remote-server', + 'src-uri' => ['amqp://cl1', 'amqp://cl2'], + 'src-queue' => 'my-queue', + 'dest-uri' => 'amqp://remote-server', 'dest-queue' => 'another-queue' } } @@ -131,13 +134,13 @@ end it 'return different instances' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT - provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<-EOT -shovel documentumShovel1 {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} -federation documentumFederation2 {"uri":"amqp://","expires":"360000"} -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT + provider_class.expects(:rabbitmqctl_list).with('parameters', '-p', '/').returns <<~EOT + shovel documentumShovel1 {"src-uri":"amqp://","src-queue":"my-queue","dest-uri":"amqp://remote-server","dest-queue":"another-queue"} + federation documentumFederation2 {"uri":"amqp://","expires":"360000"} + EOT instances = provider_class.instances expect(instances.size).to eq(2) expect(instances.map do |prov| @@ -152,9 +155,9 @@ name: 'documentumShovel1@/', component_name: 'shovel', value: { - 'src-uri' => 'amqp://', - 'src-queue' => 'my-queue', - 'dest-uri' => 'amqp://remote-server', + 'src-uri' => 'amqp://', + 'src-queue' => 'my-queue', + 'dest-uri' => 'amqp://remote-server', 'dest-queue' => 'another-queue' } }, @@ -162,14 +165,13 @@ name: 'documentumFederation2@/', component_name: 'federation', value: { - 'uri' => 'amqp://', - 'expires' => '360000' + 'uri' => 'amqp://', + 'expires' => '360000' } } ] ) end - # rubocop:enable RSpec/MultipleExpectations end describe '#create' do diff --git a/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb index 54cd6ede5..ec2e7a4f1 100644 --- a/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:rabbitmq_plugin).provider(:rabbitmqplugins) @@ -27,6 +29,7 @@ provider.expects(:rabbitmqplugins).with('enable', 'foo') provider.create end + it 'calls rabbitmqplugins to enable with offline' do provider.resource[:mode] = :offline provider.class.expects(:rabbitmq_version).returns '3.4.0' @@ -34,6 +37,7 @@ provider.expects(:rabbitmqplugins).with('enable', 'foo', '--offline') provider.create end + it 'calls rabbitmqplugins to enable with online' do provider.resource[:mode] = :online provider.class.expects(:rabbitmq_version).returns '3.4.0' @@ -41,6 +45,7 @@ provider.expects(:rabbitmqplugins).with('enable', 'foo', '--online') provider.create end + it 'calls rabbitmqplugins to enable with best' do provider.resource[:mode] = :best provider.class.expects(:rabbitmq_version).returns '3.4.0' @@ -57,6 +62,7 @@ provider.expects(:rabbitmqplugins).with('enable', 'foo') provider.create end + it 'calls rabbitmqplugins to enable with offline' do provider.resource[:mode] = :offline provider.class.expects(:rabbitmq_version).returns '3.3.9' @@ -64,6 +70,7 @@ provider.expects(:rabbitmqplugins).with('enable', 'foo') provider.create end + it 'calls rabbitmqplugins to enable with online' do provider.resource[:mode] = :online provider.class.expects(:rabbitmq_version).returns '3.3.9' @@ -71,6 +78,7 @@ provider.expects(:rabbitmqplugins).with('enable', 'foo') provider.create end + it 'calls rabbitmqplugins to enable with best' do provider.resource[:mode] = :best provider.class.expects(:rabbitmq_version).returns '3.3.9' diff --git a/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb index 45a53aacd..91bf5aaa1 100644 --- a/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_policy).provider(:rabbitmqctl) do @@ -47,15 +49,15 @@ context 'with RabbitMQ version >=3.7.0' do it 'matches policies from list' do provider.class.expects(:rabbitmq_version).returns '3.7.0' - provider.class.expects(:rabbitmqctl_list).with('policies', '-p', '/').returns <<-EOT -/ ha-all .* all {"ha-mode":"all","ha-sync-mode":"automatic"} 0 -/ test .* exchanges {"ha-mode":"all"} 0 -EOT + provider.class.expects(:rabbitmqctl_list).with('policies', '-p', '/').returns <<~EOT + / ha-all .* all {"ha-mode":"all","ha-sync-mode":"automatic"} 0 + / test .* exchanges {"ha-mode":"all"} 0 + EOT expect(provider.exists?).to eq(applyto: 'all', pattern: '.*', priority: '0', definition: { - 'ha-mode' => 'all', + 'ha-mode' => 'all', 'ha-sync-mode' => 'automatic' }) end @@ -64,15 +66,15 @@ context 'with RabbitMQ version >=3.2.0 and < 3.7.0' do it 'matches policies from list' do provider.class.expects(:rabbitmq_version).returns '3.6.9' - provider.class.expects(:rabbitmqctl_list).with('policies', '-p', '/').returns <<-EOT -/ ha-all all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 -/ test exchanges .* {"ha-mode":"all"} 0 -EOT + provider.class.expects(:rabbitmqctl_list).with('policies', '-p', '/').returns <<~EOT + / ha-all all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 + / test exchanges .* {"ha-mode":"all"} 0 + EOT expect(provider.exists?).to eq(applyto: 'all', pattern: '.*', priority: '0', definition: { - 'ha-mode' => 'all', + 'ha-mode' => 'all', 'ha-sync-mode' => 'automatic' }) end @@ -81,15 +83,15 @@ context 'with RabbitMQ version <3.2.0' do it 'matches policies from list (<3.2.0)' do provider.class.expects(:rabbitmq_version).returns '3.1.5' - provider.class.expects(:rabbitmqctl_list).with('policies', '-p', '/').returns <<-EOT -/ ha-all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 -/ test .* {"ha-mode":"all"} 0 -EOT + provider.class.expects(:rabbitmqctl_list).with('policies', '-p', '/').returns <<~EOT + / ha-all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0 + / test .* {"ha-mode":"all"} 0 + EOT expect(provider.exists?).to eq(applyto: 'all', pattern: '.*', priority: '0', definition: { - 'ha-mode' => 'all', + 'ha-mode' => 'all', 'ha-sync-mode' => 'automatic' }) end diff --git a/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb b/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb index 722ad7809..6cfd69bbb 100644 --- a/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:rabbitmq_queue).provider(:rabbitmqadmin) @@ -13,13 +15,13 @@ let(:provider) { provider_class.new(resource) } it 'returns instances' do - provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -/ -EOT - provider_class.expects(:rabbitmqctl_list).with('queues', '-p', '/', 'name', 'durable', 'auto_delete', 'arguments').returns <<-EOT -test true false [] -test2 true false [{"x-message-ttl",342423},{"x-expires",53253232},{"x-max-length",2332},{"x-max-length-bytes",32563324242},{"x-dead-letter-exchange","amq.direct"},{"x-dead-letter-routing-key","test.routing"}] -EOT + provider_class.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + / + EOT + provider_class.expects(:rabbitmqctl_list).with('queues', '-p', '/', 'name', 'durable', 'auto_delete', 'arguments').returns <<~EOT + test true false [] + test2 true false [{"x-message-ttl",342423},{"x-expires",53253232},{"x-max-length",2332},{"x-max-length-bytes",32563324242},{"x-dead-letter-exchange","amq.direct"},{"x-dead-letter-routing-key","test.routing"}] + EOT instances = provider_class.instances expect(instances.size).to eq(2) end diff --git a/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb index 1db362c02..ec8e04877 100644 --- a/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:rabbitmq_user).provider(:rabbitmqctl) @@ -21,10 +23,12 @@ describe '#self.instances' do it { expect(provider.class.instances.size).to eq(3) } + it 'returns an array of users' do users = provider.class.instances.map(&:name) expect(users).to match_array(%w[rmq_x rmq_y rmq_z]) end + it 'returns the expected tags' do tags = provider.class.instances.first.get(:tags) expect(tags).to match_array(%w[disk storage]) @@ -40,6 +44,7 @@ provider.expects(:rabbitmqctl).with('add_user', 'rmq_x', 'secret') provider.create end + context 'no password supplied' do let(:resource) do Puppet::Type.type(:rabbitmq_user).new( @@ -69,13 +74,13 @@ provider.class.stubs(:rabbitmqctl).with( 'eval', 'rabbit_access_control:check_user_pass_login(list_to_binary("rmq_x"), list_to_binary("secret")).' - ).returns <<-EOT -{ok,{user,<<"rmq_x">>,[],rabbit_auth_backend_internal, - {internal_user,<<"rmq_x">>, - <<193,81,62,182,129,135,196,89,148,87,227,48,86,2,154, - 192,52,119,214,177>>, - []}}} -EOT + ).returns <<~EOT + {ok,{user,<<"rmq_x">>,[],rabbit_auth_backend_internal, + {internal_user,<<"rmq_x">>, + <<193,81,62,182,129,135,196,89,148,87,227,48,86,2,154, + 192,52,119,214,177>>, + []}}} + EOT end it do @@ -88,10 +93,10 @@ provider.class.stubs(:rabbitmqctl).with( 'eval', 'rabbit_access_control:check_user_pass_login(list_to_binary("rmq_x"), list_to_binary("nottherightone")).' - ).returns <<-EOT -{refused,"user '~s' - invalid credentials",[<<"rmq_x">>]} -...done. -EOT + ).returns <<~EOT + {refused,"user '~s' - invalid credentials",[<<"rmq_x">>]} + ...done. + EOT end it do diff --git a/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb index e37ac6781..bdc694398 100644 --- a/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Puppet::Type.type(:rabbitmq_user_permissions).provider(:rabbitmqctl)' do @@ -12,54 +14,61 @@ after do provider_class.instance_variable_set(:@users, nil) end + it 'matches user permissions from list' do - provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<-EOT -bar 1 2 3 -EOT + provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<~EOT + bar 1 2 3 + EOT expect(provider.exists?).to eq(configure: '1', write: '2', read: '3') end + it 'matches user permissions with empty columns' do - provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<-EOT -bar 3 -EOT + provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<~EOT + bar 3 + EOT expect(provider.exists?).to eq(configure: '', write: '', read: '3') end + it 'does not match user permissions with more than 3 columns' do - provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<-EOT -bar 1 2 3 4 -EOT + provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<~EOT + bar 1 2 3 4 + EOT expect { provider.exists? }.to raise_error(Puppet::Error, %r{cannot parse line from list_user_permissions}) end + it 'does not match an empty list' do provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<-EOT -EOT + EOT expect(provider.exists?).to eq(nil) end + it 'creates default permissions' do provider.instance_variable_set(:@should_vhost, 'bar') provider.instance_variable_set(:@should_user, 'foo') provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', "''", "''", "''") provider.create end + it 'destroys permissions' do provider.instance_variable_set(:@should_vhost, 'bar') provider.instance_variable_set(:@should_user, 'foo') provider.expects(:rabbitmqctl).with('clear_permissions', '-p', 'bar', 'foo') provider.destroy end + { configure_permission: '1', write_permission: '2', read_permission: '3' }.each do |k, v| - it "should be able to retrieve #{k}" do - provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<-EOT -bar 1 2 3 -EOT + it "is able to retrieve #{k}" do + provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<~EOT + bar 1 2 3 + EOT expect(provider.send(k)).to eq(v) end end { configure_permission: '1', write_permission: '2', read_permission: '3' }.each do |k, v| - it "should be able to retrieve #{k} after exists has been called" do - provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<-EOT -bar 1 2 3 -EOT + it "is able to retrieve #{k} after exists has been called" do + provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<~EOT + bar 1 2 3 + EOT provider.exists? expect(provider.send(k)).to eq(v) end @@ -67,19 +76,19 @@ { configure_permission: %w[foo 2 3], read_permission: %w[1 2 foo], write_permission: %w[1 foo 3] }.each do |perm, columns| - it "should be able to sync #{perm}" do - provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<-EOT -bar 1 2 3 -EOT + it "is able to sync #{perm}" do + provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<~EOT + bar 1 2 3 + EOT provider.resource[perm] = 'foo' provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', *columns) provider.send("#{perm}=".to_sym, 'foo') end end it 'onlies call set_permissions once' do - provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<-EOT -bar 1 2 3 -EOT + provider.class.expects(:rabbitmqctl_list).with('user_permissions', 'foo').returns <<~EOT + bar 1 2 3 + EOT provider.resource[:configure_permission] = 'foo' provider.resource[:read_permission] = 'foo' provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', 'foo', '2', 'foo').once diff --git a/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb b/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb index 5bc82f0ce..b87a9f877 100644 --- a/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb +++ b/spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:rabbitmq_vhost).provider(:rabbitmqctl) @@ -10,32 +12,36 @@ let(:provider) { provider_class.new(resource) } it 'matches vhost names' do - provider.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -Listing vhosts ... -foo -...done. -EOT + provider.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + Listing vhosts ... + foo + ...done. + EOT expect(provider.exists?).to eq(true) end + it 'does not match if no vhosts on system' do - provider.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -Listing vhosts ... -...done. -EOT + provider.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + Listing vhosts ... + ...done. + EOT expect(provider.exists?).to eq(false) end + it 'does not match if no matching vhosts on system' do - provider.expects(:rabbitmqctl_list).with('vhosts').returns <<-EOT -Listing vhosts ... -fooey -...done. -EOT + provider.expects(:rabbitmqctl_list).with('vhosts').returns <<~EOT + Listing vhosts ... + fooey + ...done. + EOT expect(provider.exists?).to eq(false) end + it 'calls rabbitmqctl to create' do provider.expects(:rabbitmqctl).with('add_vhost', 'foo') provider.create end + it 'calls rabbitmqctl to create' do provider.expects(:rabbitmqctl).with('delete_vhost', 'foo') provider.destroy diff --git a/spec/unit/puppet/type/rabbitmq_binding_spec.rb b/spec/unit/puppet/type/rabbitmq_binding_spec.rb index 14b882487..fd8e95246 100644 --- a/spec/unit/puppet/type/rabbitmq_binding_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_binding_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_binding) do let(:binding) do @@ -11,11 +13,13 @@ binding[:name] = 'dan@dude@pl' expect(binding[:name]).to eq('dan@dude@pl') end + it 'requires a name' do expect do Puppet::Type.type(:rabbitmq_binding).new({}) end.to raise_error(Puppet::Error, 'Title or name must be provided') end + it 'errors when missing source' do expect do Puppet::Type.type(:rabbitmq_binding).new( @@ -24,6 +28,7 @@ ) end.to raise_error(Puppet::Error, %r{`source` must be defined}) end + it 'errors when missing destination' do expect do Puppet::Type.type(:rabbitmq_binding).new( @@ -32,14 +37,17 @@ ) end.to raise_error(Puppet::Error, %r{`destination` must be defined}) end + it 'accepts an binding destination_type' do binding[:destination_type] = :exchange expect(binding[:destination_type]).to eq(:exchange) end + it 'accepts a user' do binding[:user] = :root expect(binding[:user]).to eq(:root) end + it 'accepts a password' do binding[:password] = :PaSsw0rD expect(binding[:password]).to eq(:PaSsw0rD) diff --git a/spec/unit/puppet/type/rabbitmq_cluster_spec.rb b/spec/unit/puppet/type/rabbitmq_cluster_spec.rb index 2a0257037..e71b283a7 100644 --- a/spec/unit/puppet/type/rabbitmq_cluster_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_cluster_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_cluster) do let(:rabbitmq_cluster) do @@ -8,19 +10,23 @@ rabbitmq_cluster[:name] = 'test_cluster' expect(rabbitmq_cluster[:name]).to eq('test_cluster') end + it 'requires a name' do expect do Puppet::Type.type(:rabbitmq_cluster).new({}) end.to raise_error(Puppet::Error, 'Title or name must be provided') end + it 'check if init_node set to host1' do rabbitmq_cluster[:init_node] = 'host1' expect(rabbitmq_cluster[:init_node]).to eq('host1') end + it 'try to set node_disc_type to ram' do rabbitmq_cluster[:node_disc_type] = 'ram' expect(rabbitmq_cluster[:node_disc_type]).to eq('ram') end + it 'node_disc_type not set should default to disc' do rabbitmq_cluster[:name] = 'test_cluster' expect(rabbitmq_cluster[:node_disc_type]).to eq('disc') diff --git a/spec/unit/puppet/type/rabbitmq_exchange_spec.rb b/spec/unit/puppet/type/rabbitmq_exchange_spec.rb index e1be271df..731fb9682 100644 --- a/spec/unit/puppet/type/rabbitmq_exchange_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_exchange_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_exchange) do let(:exchange) do @@ -14,16 +16,19 @@ exchange[:name] = 'dan@pl' expect(exchange[:name]).to eq('dan@pl') end + it 'requires a name' do expect do Puppet::Type.type(:rabbitmq_exchange).new({}) end.to raise_error(Puppet::Error, 'Title or name must be provided') end + it 'does not allow whitespace in the name' do expect do exchange[:name] = 'b r' end.to raise_error(Puppet::Error, %r{Valid values match}) end + it 'does not allow names without @' do expect do exchange[:name] = 'b_r' @@ -34,11 +39,13 @@ exchange[:type] = :direct expect(exchange[:type]).to eq(:direct) end + it 'requires a type' do expect do Puppet::Type.type(:rabbitmq_exchange).new(name: 'foo@bar') end.to raise_error(%r{.*must set type when creating exchange.*}) end + it 'does not require a type when destroying' do expect do Puppet::Type.type(:rabbitmq_exchange).new(name: 'foo@bar', ensure: :absent) diff --git a/spec/unit/puppet/type/rabbitmq_parameter_spec.rb b/spec/unit/puppet/type/rabbitmq_parameter_spec.rb index 9d5f4c784..f03b2c42e 100644 --- a/spec/unit/puppet/type/rabbitmq_parameter_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_parameter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_parameter) do let(:parameter) do diff --git a/spec/unit/puppet/type/rabbitmq_plugin_spec.rb b/spec/unit/puppet/type/rabbitmq_plugin_spec.rb index 642116842..3d55f58ff 100644 --- a/spec/unit/puppet/type/rabbitmq_plugin_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_plugin_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_plugin) do let(:plugin) do @@ -8,29 +10,36 @@ plugin[:name] = 'plugin-name' expect(plugin[:name]).to eq('plugin-name') end + it 'accepts a mode of offline' do plugin[:mode] = 'offline' expect(plugin[:mode]).to eq(:offline) end + it 'accepts a mode of online' do plugin[:mode] = 'online' expect(plugin[:mode]).to eq(:online) end + it 'accepts a mode of best' do plugin[:mode] = 'best' expect(plugin[:mode]).to eq(:best) end + it 'requires a name' do expect do Puppet::Type.type(:rabbitmq_plugin).new({}) end.to raise_error(Puppet::Error, 'Title or name must be provided') end + it 'defaults to a umask of 0022' do expect(plugin[:umask]).to eq(0o022) end + it 'defaults to a mode of best' do expect(plugin[:mode]).to eq(:best) end + it 'does not allow a non-octal value to be specified' do expect do plugin[:umask] = '198' diff --git a/spec/unit/puppet/type/rabbitmq_policy_spec.rb b/spec/unit/puppet/type/rabbitmq_policy_spec.rb index ae1186352..0506ea136 100644 --- a/spec/unit/puppet/type/rabbitmq_policy_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_policy_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_policy) do let(:policy) do @@ -44,7 +46,7 @@ end it 'accepts valid value for applyto' do - [:all, :exchanges, :queues].each do |v| + %i[all exchanges queues].each do |v| policy[:applyto] = v expect(policy[:applyto]).to eq(v) end diff --git a/spec/unit/puppet/type/rabbitmq_queue_spec.rb b/spec/unit/puppet/type/rabbitmq_queue_spec.rb index 625c3fe3e..3b1a583d5 100644 --- a/spec/unit/puppet/type/rabbitmq_queue_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_queue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_queue) do let(:queue) do @@ -15,16 +17,19 @@ queue[:name] = 'dan@pl' expect(queue[:name]).to eq('dan@pl') end + it 'requires a name' do expect do Puppet::Type.type(:rabbitmq_queue).new({}) end.to raise_error(Puppet::Error, 'Title or name must be provided') end + it 'does not allow whitespace in the name' do expect do queue[:name] = 'b r' end.to raise_error(Puppet::Error, %r{Valid values match}) end + it 'does not allow names without @' do expect do queue[:name] = 'b_r' diff --git a/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb b/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb index ae9852081..52cbccd78 100644 --- a/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_user_permissions) do let(:perms) do @@ -8,36 +10,42 @@ perms[:name] = 'dan@bar' expect(perms[:name]).to eq('dan@bar') end + it 'requires a name' do expect do Puppet::Type.type(:rabbitmq_user_permissions).new({}) end.to raise_error(Puppet::Error, 'Title or name must be provided') end + it 'fails when names dont have a @' do expect do perms[:name] = 'bar' end.to raise_error(Puppet::Error, %r{Valid values match}) end - [:configure_permission, :read_permission, :write_permission].each do |param| + + %i[configure_permission read_permission write_permission].each do |param| it 'does not default to anything' do expect(perms[param]).to eq(nil) end - it "should accept a valid regex for #{param}" do + + it "accepts a valid regex for #{param}" do perms[param] = '.*?' expect(perms[param]).to eq('.*?') end - it "should accept an empty string for #{param}" do + + it "accepts an empty string for #{param}" do perms[param] = '' expect(perms[param]).to eq('') end - it "should not accept invalid regex for #{param}" do + + it "does not accept invalid regex for #{param}" do expect do perms[param] = '*' end.to raise_error(Puppet::Error, %r{Invalid regexp}) end end { rabbitmq_vhost: 'dan@test', rabbitmq_user: 'test@dan' }.each do |k, v| - it "should autorequire #{k}" do + it "autorequires #{k}" do vhost = if k == :rabbitmq_vhost Puppet::Type.type(k).new(name: 'test') else @@ -52,5 +60,4 @@ expect(rel.target.ref).to eq(perm.ref) end end - # rubocop:enable RSpec/MultipleExpectations end diff --git a/spec/unit/puppet/type/rabbitmq_user_spec.rb b/spec/unit/puppet/type/rabbitmq_user_spec.rb index eaa72d0f5..b95e15372 100644 --- a/spec/unit/puppet/type/rabbitmq_user_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_user) do let(:user) do @@ -8,24 +10,29 @@ user[:name] = 'dan' expect(user[:name]).to eq('dan') end + it 'admin is false when :admin is not set' do user[:name] = 'dan' expect(user[:admin]).to eq(:false) end + it 'accepts a password' do user[:password] = 'foo' expect(user[:password]).to eq('foo') end + it 'requires a name' do expect do Puppet::Type.type(:rabbitmq_user).new({}) end.to raise_error(Puppet::Error, 'Title or name must be provided') end + it 'does not allow whitespace in the name' do expect do user[:name] = 'b r' end.to raise_error(Puppet::Error, %r{Valid values match}) end + [true, false, 'true', 'false'].each do |val| it "admin property should accept #{val}" do user[:admin] = val @@ -37,11 +44,13 @@ user[:admin] = 'yes' end.to raise_error(Puppet::Error, %r{Invalid value}) end + it 'does not accept tags with spaces' do expect do user[:tags] = ['policy maker'] end.to raise_error(Puppet::Error, %r{Invalid tag}) end + it 'does not accept the administrator tag' do expect do user[:tags] = ['administrator'] diff --git a/spec/unit/puppet/type/rabbitmq_vhost_spec.rb b/spec/unit/puppet/type/rabbitmq_vhost_spec.rb index 38337b17a..17686a812 100644 --- a/spec/unit/puppet/type/rabbitmq_vhost_spec.rb +++ b/spec/unit/puppet/type/rabbitmq_vhost_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:rabbitmq_vhost) do let(:vhost) do @@ -8,11 +10,13 @@ vhost[:name] = 'dan' expect(vhost[:name]).to eq('dan') end + it 'requires a name' do expect do Puppet::Type.type(:rabbitmq_vhost).new({}) end.to raise_error(Puppet::Error, 'Title or name must be provided') end + it 'does not allow whitespace in the name' do expect do vhost[:name] = 'b r'