From 9bd176a564396a85c3b289e2f6f75620a3405bf2 Mon Sep 17 00:00:00 2001 From: Ayanda Dube Date: Wed, 27 Mar 2024 11:51:35 +0000 Subject: [PATCH 1/5] add --no-warn option to plugins list command to optionally allow avoiding warning banner --- .../rabbitmq/cli/plugins/commands/list_command.ex | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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..76bf57aabbe0 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,9 @@ 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, no_warn: :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: :no_warn] def validate(args, _) when length(args) > 1 do {:validation_failure, :too_many_args} @@ -48,7 +48,7 @@ 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, no_warn: no_warn} = opts all = PluginHelpers.list(opts) @@ -56,7 +56,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 no_warn) do true -> :ok @@ -108,7 +108,7 @@ 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] [--no-warn]" def usage_additional() do [ @@ -119,7 +119,8 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do "only print plugin names. Most useful in compbination 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"], + ["--no-warn", "do not print warnings e.g. for plugins missings"] ] end @@ -186,6 +187,6 @@ 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, no_warn: false} end end From b285fecf4c9180923b7898e1e07e5c9c0c0e2d10 Mon Sep 17 00:00:00 2001 From: Ayanda Dube Date: Wed, 27 Mar 2024 12:29:53 +0000 Subject: [PATCH 2/5] add list plugins with --no-warn option tests --- .../rabbitmq/cli/plugins/plugins_helpers.ex | 4 +- .../plugins/list_plugins_command_test.exs | 51 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) 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..334d810bc183 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 + no_warn = Map.get(opts, :no_warn, false) + + case (Enum.empty?(missing) or no_warn) 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..3ba102ffbffe 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 @@ -48,7 +49,8 @@ defmodule ListPluginsCommandTest do minimal: false, verbose: false, enabled: false, - implicitly_enabled: false + implicitly_enabled: false, + no_warn: false } on_exit(fn -> @@ -444,4 +446,51 @@ 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], :no_warn, 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, :no_warn, 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 From 477a690169a2469ee52770813d7613bd7d80778e Mon Sep 17 00:00:00 2001 From: Ayanda Dube Date: Wed, 27 Mar 2024 12:32:12 +0000 Subject: [PATCH 3/5] fix a few typos --- .../lib/rabbitmq/cli/plugins/commands/list_command.ex | 4 ++-- deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 76bf57aabbe0..a1cd944e0dce 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 @@ -116,11 +116,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"], - ["--no-warn", "do not print warnings e.g. for plugins missings"] + ["--no-warn", "do not print warnings e.g. for plugins missing"] ] end 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 3ba102ffbffe..c86f62aa6d07 100644 --- a/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs +++ b/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs @@ -39,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 = %{ From 1990def5beffd6ef80857875397115809eac1c39 Mon Sep 17 00:00:00 2001 From: Ayanda Dube Date: Wed, 27 Mar 2024 12:35:40 +0000 Subject: [PATCH 4/5] mix format updated source files --- .../cli/plugins/commands/list_command.ex | 21 ++++++++++--- .../rabbitmq/cli/plugins/plugins_helpers.ex | 2 +- .../plugins/list_plugins_command_test.exs | 31 ++++++++++--------- 3 files changed, 35 insertions(+), 19 deletions(-) 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 a1cd944e0dce..582f30a11b15 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,7 +20,13 @@ 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, no_warn: :boolean] + do: [ + verbose: :boolean, + minimal: :boolean, + enabled: :boolean, + implicitly_enabled: :boolean, + no_warn: :boolean + ] def aliases(), do: [v: :verbose, m: :minimal, E: :enabled, e: :implicitly_enabled, o: :no_warn] @@ -48,7 +54,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, no_warn: no_warn} = + %{ + verbose: verbose, + minimal: minimal, + enabled: only_enabled, + implicitly_enabled: all_enabled, + no_warn: no_warn + } = opts all = PluginHelpers.list(opts) @@ -56,7 +68,7 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do missing = MapSet.difference(MapSet.new(enabled), MapSet.new(PluginHelpers.plugin_names(all))) - case (Enum.empty?(missing) or no_warn) do + case Enum.empty?(missing) or no_warn do true -> :ok @@ -108,7 +120,8 @@ 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] [--no-warn]" + def usage, + do: "list [pattern] [--verbose] [--minimal] [--enabled] [--implicitly-enabled] [--no-warn]" def usage_additional() do [ 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 334d810bc183..fd018900d319 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/plugins_helpers.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/plugins_helpers.ex @@ -197,7 +197,7 @@ defmodule RabbitMQ.CLI.Plugins.Helpers do no_warn = Map.get(opts, :no_warn, false) - case (Enum.empty?(missing) or no_warn) do + case Enum.empty?(missing) or no_warn 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 c86f62aa6d07..2b0b8f368c60 100644 --- a/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs +++ b/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs @@ -454,7 +454,13 @@ defmodule ListPluginsCommandTest do 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]) + + set_enabled_plugins( + [:rabbitmq_federation, missing_plugin], + :online, + context[:opts][:node], + context[:opts] + ) on_exit(fn -> set_enabled_plugins( @@ -473,24 +479,21 @@ defmodule ListPluginsCommandTest do opts = context[:opts] assert capture_io(fn -> - %{ - plugins: actual_plugins - } = @command.run([".*"], opts) - - assert_plugin_states(actual_plugins, expected_plugins) + %{ + plugins: actual_plugins + } = @command.run([".*"], opts) - end) =~ ~s// + assert_plugin_states(actual_plugins, expected_plugins) + end) =~ ~s// opts = Map.replace(opts, :no_warn, 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/ + %{ + 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 From b0c4840c7f6163e9d70a512d256f767db9b587ca Mon Sep 17 00:00:00 2001 From: Ayanda Dube Date: Wed, 27 Mar 2024 14:36:34 +0000 Subject: [PATCH 5/5] rename flag to --ignore-warnings & update formatting with mix --- .../cli/plugins/commands/list_command.ex | 22 +++++++++++++------ .../rabbitmq/cli/plugins/plugins_helpers.ex | 4 ++-- .../plugins/list_plugins_command_test.exs | 6 ++--- 3 files changed, 20 insertions(+), 12 deletions(-) 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 582f30a11b15..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 @@ -25,10 +25,11 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do minimal: :boolean, enabled: :boolean, implicitly_enabled: :boolean, - no_warn: :boolean + ignore_warnings: :boolean ] - def aliases(), do: [v: :verbose, m: :minimal, E: :enabled, e: :implicitly_enabled, o: :no_warn] + 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} @@ -59,7 +60,7 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do minimal: minimal, enabled: only_enabled, implicitly_enabled: all_enabled, - no_warn: no_warn + ignore_warnings: ignore_warnings } = opts @@ -68,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) or no_warn do + case Enum.empty?(missing) or ignore_warnings do true -> :ok @@ -121,7 +122,8 @@ 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] [--no-warn]" + do: + "list [pattern] [--verbose] [--minimal] [--enabled] [--implicitly-enabled] [--ignore-warnings]" def usage_additional() do [ @@ -133,7 +135,7 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do ], ["--enabled", "only list enabled plugins"], ["--implicitly-enabled", "include plugins enabled as dependencies of other plugins"], - ["--no-warn", "do not print warnings e.g. for plugins missing"] + ["--ignore-warnings", "do not print warnings e.g. for plugins missing"] ] end @@ -200,6 +202,12 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do end defp default_opts() do - %{minimal: false, verbose: false, enabled: false, implicitly_enabled: false, no_warn: 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 fd018900d319..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,9 +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)) - no_warn = Map.get(opts, :no_warn, false) + ignore_warnings = Map.get(opts, :ignore_warnings, false) - case Enum.empty?(missing) or no_warn do + 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 2b0b8f368c60..abc2af947024 100644 --- a/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs +++ b/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs @@ -50,7 +50,7 @@ defmodule ListPluginsCommandTest do verbose: false, enabled: false, implicitly_enabled: false, - no_warn: false + ignore_warnings: false } on_exit(fn -> @@ -448,7 +448,7 @@ defmodule ListPluginsCommandTest do end test "run: lists all plugins with missing plugins warning control", context do - opts = Map.replace(context[:opts], :no_warn, true) + opts = Map.replace(context[:opts], :ignore_warnings, true) context = Map.replace(context, :opts, opts) missing_plugin = :rabbitmq_non_existent @@ -486,7 +486,7 @@ defmodule ListPluginsCommandTest do assert_plugin_states(actual_plugins, expected_plugins) end) =~ ~s// - opts = Map.replace(opts, :no_warn, false) + opts = Map.replace(opts, :ignore_warnings, false) assert capture_io(fn -> %{