Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rabbitmq-plugins list: allow warnings to be suppressed #10865

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,9 +20,16 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do
def merge_defaults(args, opts), do: {args, Map.merge(default_opts(), opts)}

def switches(),
do: [verbose: :boolean, minimal: :boolean, enabled: :boolean, implicitly_enabled: :boolean]
do: [
verbose: :boolean,
minimal: :boolean,
enabled: :boolean,
implicitly_enabled: :boolean,
ignore_warnings: :boolean
]

def aliases(), do: [v: :verbose, m: :minimal, E: :enabled, e: :implicitly_enabled]
def aliases(),
do: [v: :verbose, m: :minimal, E: :enabled, e: :implicitly_enabled, o: :ignore_warnings]

def validate(args, _) when length(args) > 1 do
{:validation_failure, :too_many_args}
Expand All @@ -48,15 +55,21 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do
end

def run([pattern], %{node: node_name} = opts) do
%{verbose: verbose, minimal: minimal, enabled: only_enabled, implicitly_enabled: all_enabled} =
%{
verbose: verbose,
minimal: minimal,
enabled: only_enabled,
implicitly_enabled: all_enabled,
ignore_warnings: ignore_warnings
} =
opts

all = PluginHelpers.list(opts)
enabled = PluginHelpers.read_enabled(opts)

missing = MapSet.difference(MapSet.new(enabled), MapSet.new(PluginHelpers.plugin_names(all)))

case Enum.empty?(missing) do
case Enum.empty?(missing) or ignore_warnings do
true ->
:ok

Expand Down Expand Up @@ -108,18 +121,21 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do

def banner([pattern], _), do: "Listing plugins with pattern \"#{pattern}\" ..."

def usage, do: "list [pattern] [--verbose] [--minimal] [--enabled] [--implicitly-enabled]"
def usage,
do:
"list [pattern] [--verbose] [--minimal] [--enabled] [--implicitly-enabled] [--ignore-warnings]"

def usage_additional() do
[
["<pattern>", "only list plugins that match a regular expression pattern"],
["--verbose", "output more information"],
[
"--minimal",
"only print plugin names. Most useful in compbination with --silent and --enabled."
"only print plugin names. Most useful in combination with --silent and --enabled."
],
["--enabled", "only list enabled plugins"],
["--implicitly-enabled", "include plugins enabled as dependencies of other plugins"]
["--implicitly-enabled", "include plugins enabled as dependencies of other plugins"],
["--ignore-warnings", "do not print warnings e.g. for plugins missing"]
]
end

Expand Down Expand Up @@ -186,6 +202,12 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do
end

defp default_opts() do
%{minimal: false, verbose: false, enabled: false, implicitly_enabled: false}
%{
minimal: false,
verbose: false,
enabled: false,
implicitly_enabled: false,
ignore_warnings: false
}
end
end
Expand Up @@ -195,7 +195,9 @@ defmodule RabbitMQ.CLI.Plugins.Helpers do
all_plugin_names = Enum.map(all, &plugin_name/1)
missing = MapSet.difference(MapSet.new(plugins), MapSet.new(all_plugin_names))

case Enum.empty?(missing) do
ignore_warnings = Map.get(opts, :ignore_warnings, false)

case Enum.empty?(missing) or ignore_warnings do
true ->
case :rabbit_file.write_term_file(to_charlist(plugins_file), [plugins]) do
:ok ->
Expand Down
56 changes: 54 additions & 2 deletions deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs
Expand Up @@ -7,6 +7,7 @@
defmodule ListPluginsCommandTest do
use ExUnit.Case, async: false
import TestHelper
import ExUnit.CaptureIO

@command RabbitMQ.CLI.Plugins.Commands.ListCommand

Expand Down Expand Up @@ -38,7 +39,7 @@ defmodule ListPluginsCommandTest do
{:ok, [enabled_plugins]} = :file.consult(plugins_file)

IO.puts(
"plugins list tests will assume tnat #{Enum.join(enabled_plugins, ",")} is the list of enabled plugins to revert to"
"plugins list tests will assume that #{Enum.join(enabled_plugins, ",")} is the list of enabled plugins to revert to"
)

opts = %{
Expand All @@ -48,7 +49,8 @@ defmodule ListPluginsCommandTest do
minimal: false,
verbose: false,
enabled: false,
implicitly_enabled: false
implicitly_enabled: false,
ignore_warnings: false
}

on_exit(fn ->
Expand Down Expand Up @@ -444,4 +446,54 @@ defmodule ListPluginsCommandTest do

assert_plugin_states(actual_plugins2, expected_plugins2)
end

test "run: lists all plugins with missing plugins warning control", context do
opts = Map.replace(context[:opts], :ignore_warnings, true)
context = Map.replace(context, :opts, opts)

missing_plugin = :rabbitmq_non_existent

reset_enabled_plugins_to_preconfigured_defaults(context)

set_enabled_plugins(
[:rabbitmq_federation, missing_plugin],
:online,
context[:opts][:node],
context[:opts]
)

on_exit(fn ->
set_enabled_plugins(
[:rabbitmq_stomp, :rabbitmq_federation],
:online,
context[:opts][:node],
context[:opts]
)
end)

expected_plugins = [
%{name: :rabbitmq_federation, enabled: :enabled, running: true},
%{name: :rabbitmq_stomp, enabled: :not_enabled, running: false}
]

opts = context[:opts]

assert capture_io(fn ->
%{
plugins: actual_plugins
} = @command.run([".*"], opts)

assert_plugin_states(actual_plugins, expected_plugins)
end) =~ ~s//

opts = Map.replace(opts, :ignore_warnings, false)

assert capture_io(fn ->
%{
plugins: actual_plugins
} = @command.run([".*"], opts)

assert_plugin_states(actual_plugins, expected_plugins)
end) =~ ~s/WARNING - plugins currently enabled but missing: #{missing_plugin}\n/
end
end