2020-07-12 02:23:07 +08:00
|
|
|
## This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
## License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
2016-06-23 01:00:21 +08:00
|
|
|
##
|
2020-03-10 22:39:56 +08:00
|
|
|
## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
|
2016-06-23 01:00:21 +08:00
|
|
|
|
|
|
|
defmodule DisablePluginsCommandTest do
|
|
|
|
use ExUnit.Case, async: false
|
|
|
|
import TestHelper
|
|
|
|
|
2018-12-19 20:54:23 +08:00
|
|
|
alias RabbitMQ.CLI.Core.ExitCodes
|
|
|
|
|
2016-06-23 01:00:21 +08:00
|
|
|
@command RabbitMQ.CLI.Plugins.Commands.DisableCommand
|
|
|
|
|
|
|
|
setup_all do
|
2016-11-15 01:52:08 +08:00
|
|
|
RabbitMQ.CLI.Core.Distribution.start()
|
2017-01-24 20:33:48 +08:00
|
|
|
node = get_rabbit_hostname()
|
2017-06-07 23:21:53 +08:00
|
|
|
|
2016-06-23 01:00:21 +08:00
|
|
|
{:ok, plugins_file} = :rabbit_misc.rpc_call(node,
|
|
|
|
:application, :get_env,
|
|
|
|
[:rabbit, :enabled_plugins_file])
|
|
|
|
{:ok, plugins_dir} = :rabbit_misc.rpc_call(node,
|
|
|
|
:application, :get_env,
|
|
|
|
[:rabbit, :plugins_dir])
|
2016-10-25 20:23:00 +08:00
|
|
|
rabbitmq_home = :rabbit_misc.rpc_call(node, :code, :lib_dir, [:rabbit])
|
2016-06-23 01:00:21 +08:00
|
|
|
|
2019-12-11 18:52:34 +08:00
|
|
|
IO.puts("plugins disable tests default env: enabled plugins = #{plugins_file}, plugins dir = #{plugins_dir}, RabbitMQ home directory = #{rabbitmq_home}")
|
|
|
|
|
2016-06-23 01:00:21 +08:00
|
|
|
{:ok, [enabled_plugins]} = :file.consult(plugins_file)
|
2019-12-11 18:52:34 +08:00
|
|
|
IO.puts("plugins disable tests will assume tnat #{Enum.join(enabled_plugins, ",")} is the list of enabled plugins to revert to")
|
2016-06-23 01:00:21 +08:00
|
|
|
|
|
|
|
opts = %{enabled_plugins_file: plugins_file,
|
|
|
|
plugins_dir: plugins_dir,
|
|
|
|
rabbitmq_home: rabbitmq_home,
|
2017-11-28 02:49:08 +08:00
|
|
|
online: false, offline: false,
|
2016-12-30 01:14:07 +08:00
|
|
|
all: false}
|
2016-06-23 01:00:21 +08:00
|
|
|
|
|
|
|
on_exit(fn ->
|
2017-01-24 20:33:48 +08:00
|
|
|
set_enabled_plugins(enabled_plugins, :online, get_rabbit_hostname(), opts)
|
2016-06-23 01:00:21 +08:00
|
|
|
end)
|
|
|
|
|
|
|
|
{:ok, opts: opts}
|
|
|
|
end
|
|
|
|
|
|
|
|
setup context do
|
2016-12-07 01:14:40 +08:00
|
|
|
set_enabled_plugins([:rabbitmq_stomp, :rabbitmq_federation],
|
|
|
|
:online,
|
2017-01-24 20:33:48 +08:00
|
|
|
get_rabbit_hostname(),
|
2016-06-23 01:00:21 +08:00
|
|
|
context[:opts])
|
|
|
|
|
2017-06-07 23:21:53 +08:00
|
|
|
|
2016-06-23 01:00:21 +08:00
|
|
|
{
|
|
|
|
:ok,
|
|
|
|
opts: Map.merge(context[:opts], %{
|
2017-01-24 20:33:48 +08:00
|
|
|
node: get_rabbit_hostname(),
|
2017-08-08 08:21:07 +08:00
|
|
|
timeout: 1000
|
2016-06-23 01:00:21 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "validate: specifying both --online and --offline is reported as invalid", context do
|
|
|
|
assert match?(
|
|
|
|
{:validation_failure, {:bad_argument, _}},
|
|
|
|
@command.validate(["a"], Map.merge(context[:opts], %{online: true, offline: true}))
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "validate: not specifying plugins to enable is reported as invalid", context do
|
|
|
|
assert match?(
|
2019-01-23 20:20:24 +08:00
|
|
|
{:validation_failure, :not_enough_args},
|
2016-08-11 04:23:58 +08:00
|
|
|
@command.validate([], Map.merge(context[:opts], %{online: true, offline: false}))
|
2016-06-23 01:00:21 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-08-07 21:04:30 +08:00
|
|
|
test "validate_execution_environment: specifying a non-existent enabled_plugins_file is fine", context do
|
2017-08-07 19:47:17 +08:00
|
|
|
assert @command.validate_execution_environment(["a"], Map.merge(context[:opts], %{enabled_plugins_file: "none"})) == :ok
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|
|
|
|
|
2017-08-07 21:04:30 +08:00
|
|
|
test "validate_execution_environment: specifying a non-existent plugins_dir is reported as an error", context do
|
2017-08-07 19:47:17 +08:00
|
|
|
assert @command.validate_execution_environment(["a"], Map.merge(context[:opts], %{plugins_dir: "none"})) ==
|
2017-08-09 06:11:14 +08:00
|
|
|
{:validation_failure, :plugins_dir_does_not_exist}
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|
|
|
|
|
2019-02-24 15:10:14 +08:00
|
|
|
test "node is inaccessible, writes out enabled plugins file and returns implicitly enabled plugin list", context do
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream} =
|
|
|
|
@command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{node: :nonode}))
|
2017-02-27 22:52:40 +08:00
|
|
|
assert [[:rabbitmq_federation],
|
|
|
|
%{mode: :offline, disabled: [:rabbitmq_stomp], set: [:rabbitmq_federation]}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream)
|
2016-08-11 15:41:38 +08:00
|
|
|
assert {:ok, [[:rabbitmq_federation]]} == :file.consult(context[:opts][:enabled_plugins_file])
|
2016-09-07 23:22:23 +08:00
|
|
|
assert [:amqp_client, :rabbitmq_federation, :rabbitmq_stomp] ==
|
2016-06-23 01:00:21 +08:00
|
|
|
Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
|
|
|
|
end
|
|
|
|
|
2016-08-11 15:41:38 +08:00
|
|
|
test "in offline mode, writes out enabled plugins and reports implicitly enabled plugin list", context do
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream} = @command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{offline: true, online: false}))
|
2017-02-27 22:52:40 +08:00
|
|
|
assert [[:rabbitmq_federation],
|
|
|
|
%{mode: :offline, disabled: [:rabbitmq_stomp], set: [:rabbitmq_federation]}] == Enum.to_list(test_stream)
|
2016-08-11 15:41:38 +08:00
|
|
|
assert {:ok, [[:rabbitmq_federation]]} == :file.consult(context[:opts][:enabled_plugins_file])
|
2016-09-07 23:22:23 +08:00
|
|
|
assert [:amqp_client, :rabbitmq_federation, :rabbitmq_stomp] ==
|
2016-06-23 01:00:21 +08:00
|
|
|
Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
|
|
|
|
end
|
|
|
|
|
2016-08-11 15:41:38 +08:00
|
|
|
test "in offline mode , removes implicitly enabled plugins when last explicitly enabled one is removed", context do
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream0} =
|
|
|
|
@command.run(["rabbitmq_federation"], Map.merge(context[:opts], %{offline: true, online: false}))
|
2017-02-27 22:52:40 +08:00
|
|
|
assert [[:rabbitmq_stomp],
|
|
|
|
%{mode: :offline, disabled: [:rabbitmq_federation], set: [:rabbitmq_stomp]}] == Enum.to_list(test_stream0)
|
2016-09-07 23:22:23 +08:00
|
|
|
assert {:ok, [[:rabbitmq_stomp]]} == :file.consult(context[:opts][:enabled_plugins_file])
|
2016-06-23 01:00:21 +08:00
|
|
|
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream1} =
|
|
|
|
@command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{offline: true, online: false}))
|
|
|
|
assert [[],
|
2017-02-27 22:52:40 +08:00
|
|
|
%{mode: :offline, disabled: [:rabbitmq_stomp], set: []}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream1)
|
2016-06-23 01:00:21 +08:00
|
|
|
assert {:ok, [[]]} = :file.consult(context[:opts][:enabled_plugins_file])
|
|
|
|
end
|
|
|
|
|
2016-08-11 15:41:38 +08:00
|
|
|
test "updates plugin list and stops disabled plugins", context do
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream0} =
|
|
|
|
@command.run(["rabbitmq_stomp"], context[:opts])
|
2017-02-27 22:52:40 +08:00
|
|
|
assert [[:rabbitmq_federation],
|
2016-12-07 20:55:00 +08:00
|
|
|
%{mode: :online,
|
|
|
|
started: [], stopped: [:rabbitmq_stomp],
|
|
|
|
disabled: [:rabbitmq_stomp],
|
2017-02-27 22:52:40 +08:00
|
|
|
set: [:rabbitmq_federation]}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream0)
|
2016-08-11 15:41:38 +08:00
|
|
|
assert {:ok, [[:rabbitmq_federation]]} == :file.consult(context[:opts][:enabled_plugins_file])
|
|
|
|
assert [:amqp_client, :rabbitmq_federation] ==
|
2016-06-23 01:00:21 +08:00
|
|
|
Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
|
|
|
|
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream1} =
|
|
|
|
@command.run(["rabbitmq_federation"], context[:opts])
|
|
|
|
assert [[],
|
|
|
|
%{mode: :online,
|
2017-02-27 22:52:40 +08:00
|
|
|
started: [], stopped: [:rabbitmq_federation],
|
|
|
|
disabled: [:rabbitmq_federation],
|
2016-12-07 20:55:00 +08:00
|
|
|
set: []}] ==
|
|
|
|
Enum.to_list(test_stream1)
|
2016-08-11 15:41:38 +08:00
|
|
|
assert {:ok, [[]]} == :file.consult(context[:opts][:enabled_plugins_file])
|
|
|
|
assert Enum.empty?(Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, [])))
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|
|
|
|
|
2016-08-11 15:41:38 +08:00
|
|
|
test "can disable multiple plugins at once", context do
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream} =
|
|
|
|
@command.run(["rabbitmq_stomp", "rabbitmq_federation"], context[:opts])
|
|
|
|
assert [[],
|
|
|
|
%{mode: :online,
|
2017-02-27 22:52:40 +08:00
|
|
|
started: [], stopped: [:rabbitmq_federation, :rabbitmq_stomp],
|
|
|
|
disabled: [:rabbitmq_federation, :rabbitmq_stomp],
|
2016-12-07 20:55:00 +08:00
|
|
|
set: []}] ==
|
|
|
|
Enum.to_list(test_stream)
|
2016-08-11 15:41:38 +08:00
|
|
|
assert {:ok, [[]]} == :file.consult(context[:opts][:enabled_plugins_file])
|
|
|
|
assert Enum.empty?(Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, [])))
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|
|
|
|
|
2016-08-11 15:41:38 +08:00
|
|
|
test "disabling a dependency disables all plugins that depend on it", context do
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream} = @command.run(["amqp_client"], context[:opts])
|
|
|
|
assert [[],
|
|
|
|
%{mode: :online,
|
2017-02-27 22:52:40 +08:00
|
|
|
started: [], stopped: [:rabbitmq_federation, :rabbitmq_stomp],
|
|
|
|
disabled: [:rabbitmq_federation, :rabbitmq_stomp],
|
2016-12-07 20:55:00 +08:00
|
|
|
set: []}] ==
|
|
|
|
Enum.to_list(test_stream)
|
2016-08-11 15:41:38 +08:00
|
|
|
assert {:ok, [[]]} == :file.consult(context[:opts][:enabled_plugins_file])
|
|
|
|
assert Enum.empty?(Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, [])))
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|
|
|
|
|
2018-12-19 20:54:23 +08:00
|
|
|
test "formats enabled plugins mismatch errors", context do
|
|
|
|
err = {:enabled_plugins_mismatch, '/tmp/a/cli/path', '/tmp/a/server/path'}
|
|
|
|
assert {:error, ExitCodes.exit_dataerr(),
|
|
|
|
"Could not update enabled plugins file at /tmp/a/cli/path: target node #{context[:opts][:node]} uses a different path (/tmp/a/server/path)"}
|
|
|
|
== @command.output({:error, err}, context[:opts])
|
|
|
|
end
|
|
|
|
|
|
|
|
test "formats enabled plugins write errors", context do
|
|
|
|
err1 = {:cannot_write_enabled_plugins_file, "/tmp/a/path", :eacces}
|
|
|
|
assert {:error, ExitCodes.exit_dataerr(),
|
|
|
|
"Could not update enabled plugins file at /tmp/a/path: the file does not exist or permission was denied (EACCES)"} ==
|
|
|
|
@command.output({:error, err1}, context[:opts])
|
|
|
|
|
|
|
|
err2 = {:cannot_write_enabled_plugins_file, "/tmp/a/path", :enoent}
|
|
|
|
assert {:error, ExitCodes.exit_dataerr(),
|
|
|
|
"Could not update enabled plugins file at /tmp/a/path: the file does not exist (ENOENT)"} ==
|
|
|
|
@command.output({:error, err2}, context[:opts])
|
|
|
|
end
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|