From a56f9cae61f6b8f4a7dd7b621b32826d3269936a Mon Sep 17 00:00:00 2001 From: kjnilsson Date: Wed, 20 Feb 2019 17:28:26 +0000 Subject: [PATCH] rabbitmq-queues: add --errors-only to grow command For consistency with shrink [#162782801] --- .../cli/queues/commands/grow_command.ex | 19 ++++++++++++++----- .../test/queues/grow_command_test.exs | 6 ++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/queues/commands/grow_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/queues/commands/grow_command.ex index c3fc4d42b5..01de7c603c 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/queues/commands/grow_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/queues/commands/grow_command.ex @@ -19,13 +19,15 @@ defmodule RabbitMQ.CLI.Queues.Commands.GrowCommand do @behaviour RabbitMQ.CLI.CommandBehaviour defp default_opts, do: %{vhost_pattern: ".*", - queue_pattern: ".*"} + queue_pattern: ".*", + errors_only: false} def switches(), do: [ - vhost_pattern: :string, - queue_pattern: :string - ] + vhost_pattern: :string, + queue_pattern: :string, + errors_only: :boolean + ] def merge_defaults(args, opts) do {args, Map.merge(default_opts(), opts)} @@ -52,7 +54,8 @@ defmodule RabbitMQ.CLI.Queues.Commands.GrowCommand do def run([node, strategy], %{node: node_name, vhost_pattern: vhost_pat, - queue_pattern: queue_pat}) do + queue_pattern: queue_pat, + errors_only: errors_only}) do case :rabbit_misc.rpc_call(node_name, :rabbit_quorum_queue, :grow, [ to_atom(node), vhost_pat, @@ -60,6 +63,12 @@ defmodule RabbitMQ.CLI.Queues.Commands.GrowCommand do to_atom(strategy)]) do {:error, _} = error -> error; {:badrpc, _} = error -> error; + results when errors_only -> + for {{:resource, vhost, _kind, name}, {:errors, _, _} = res} <- results, + do: [{:vhost, vhost}, + {:name, name}, + {:size, format_size res}, + {:result, format_result res}] results -> for {{:resource, vhost, _kind, name}, res} <- results, do: [{:vhost, vhost}, diff --git a/deps/rabbitmq_cli/test/queues/grow_command_test.exs b/deps/rabbitmq_cli/test/queues/grow_command_test.exs index 968efda973..7f7ac7053d 100644 --- a/deps/rabbitmq_cli/test/queues/grow_command_test.exs +++ b/deps/rabbitmq_cli/test/queues/grow_command_test.exs @@ -30,14 +30,16 @@ defmodule RabbitMQ.CLI.Queues.Commands.GrowCommandTest do node: get_rabbit_hostname(), timeout: context[:test_timeout] || 30000, vhost_pattern: ".*", - queue_pattern: ".*" + queue_pattern: ".*", + errors_only: false }} end test "merge_defaults: defaults to reporting complete results" do assert @command.merge_defaults([], %{}) == {[], %{vhost_pattern: ".*", - queue_pattern: ".*"}} + queue_pattern: ".*", + errors_only: false}} end test "validate: when no arguments are provided, returns a failure" do