diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/commands/list_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/commands/list_command.ex index a148bf94a73e..135de684080a 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/commands/list_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/commands/list_command.ex @@ -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} @@ -48,7 +55,13 @@ 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) @@ -56,7 +69,7 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do 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 @@ -108,7 +121,9 @@ 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 [ @@ -116,10 +131,11 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do ["--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 @@ -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 diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/plugins_helpers.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/plugins_helpers.ex index 61f24b8eea74..fbbaa0d178f7 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/plugins_helpers.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/plugins_helpers.ex @@ -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 -> diff --git a/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs b/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs index 6124b299848e..abc2af947024 100644 --- a/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs +++ b/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs @@ -7,6 +7,7 @@ defmodule ListPluginsCommandTest do use ExUnit.Case, async: false import TestHelper + import ExUnit.CaptureIO @command RabbitMQ.CLI.Plugins.Commands.ListCommand @@ -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 = %{ @@ -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 -> @@ -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