2016-06-23 01:00:21 +08:00
|
|
|
## The contents of this file are subject to the Mozilla Public License
|
|
|
|
## Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
## compliance with the License. You may obtain a copy of the License
|
2019-03-20 16:13:07 +08:00
|
|
|
## at https://www.mozilla.org/MPL/
|
2016-06-23 01:00:21 +08:00
|
|
|
##
|
|
|
|
## Software distributed under the License is distributed on an "AS IS"
|
|
|
|
## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
## the License for the specific language governing rights and
|
|
|
|
## limitations under the License.
|
|
|
|
##
|
|
|
|
## The Original Code is RabbitMQ.
|
|
|
|
##
|
|
|
|
## The Initial Developer of the Original Code is GoPivotal, Inc.
|
2019-12-29 00:35:38 +08:00
|
|
|
## Copyright (c) 2007-2020 Pivotal Software, Inc. All rights reserved.
|
2016-06-23 01:00:21 +08:00
|
|
|
|
|
|
|
defmodule EnablePluginsCommandTest 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.EnableCommand
|
|
|
|
|
|
|
|
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 enable 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 enable 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])
|
|
|
|
|
|
|
|
{
|
|
|
|
: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
|
|
|
|
|
2017-08-07 21:04:30 +08:00
|
|
|
test "validate: not specifying any plugins to enable is reported as invalid", context do
|
2016-06-23 01:00:21 +08:00
|
|
|
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
|
|
|
|
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
|
|
|
|
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 "if node is inaccessible, writes enabled plugins file and reports implicitly enabled plugin list", context do
|
2016-08-11 15:41:38 +08:00
|
|
|
# Clears enabled plugins file
|
2016-12-07 01:14:40 +08:00
|
|
|
set_enabled_plugins([], :offline, :nonode, context[:opts])
|
2016-06-23 01:00:21 +08:00
|
|
|
|
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_stomp],
|
|
|
|
%{mode: :offline, enabled: [:rabbitmq_stomp], set: [:rabbitmq_stomp]}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream)
|
2017-01-26 20:21:20 +08:00
|
|
|
check_plugins_enabled([:rabbitmq_stomp], context)
|
2016-09-07 23:22:23 +08:00
|
|
|
assert [:amqp_client, :rabbitmq_federation, :rabbitmq_stomp] ==
|
2016-08-09 23:26:05 +08:00
|
|
|
currently_active_plugins(context)
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|
|
|
|
|
2016-08-11 15:41:38 +08:00
|
|
|
test "in offline mode, writes enabled plugins and reports implicitly enabled plugin list", context do
|
|
|
|
# Clears enabled plugins file
|
2016-12-07 01:14:40 +08:00
|
|
|
set_enabled_plugins([], :offline, :nonode, context[:opts])
|
2016-06-23 01:00:21 +08:00
|
|
|
|
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_stomp],
|
|
|
|
%{mode: :offline, enabled: [:rabbitmq_stomp], set: [:rabbitmq_stomp]}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream)
|
2017-01-26 20:21:20 +08:00
|
|
|
check_plugins_enabled([:rabbitmq_stomp], context)
|
2016-08-11 06:27:13 +08:00
|
|
|
assert_equal_sets(
|
2016-09-07 23:22:23 +08:00
|
|
|
[:amqp_client, :rabbitmq_federation, :rabbitmq_stomp],
|
2016-08-11 06:27:13 +08:00
|
|
|
currently_active_plugins(context))
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|
|
|
|
|
2016-08-11 15:41:38 +08:00
|
|
|
test "adds additional plugins to those already enabled", context do
|
|
|
|
# Clears enabled plugins file
|
2016-12-07 01:14:40 +08:00
|
|
|
set_enabled_plugins([], :offline, :nonode, context[:opts])
|
2016-06-23 01:00:21 +08:00
|
|
|
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream0} =
|
|
|
|
@command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{offline: true, online: false}))
|
2017-02-27 22:52:40 +08:00
|
|
|
assert [[:rabbitmq_stomp],
|
|
|
|
%{mode: :offline, enabled: [:rabbitmq_stomp], set: [:rabbitmq_stomp]}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream0)
|
2017-01-26 20:21:20 +08:00
|
|
|
check_plugins_enabled([:rabbitmq_stomp], context)
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream1} =
|
|
|
|
@command.run(["rabbitmq_federation"], Map.merge(context[:opts], %{offline: true, online: false}))
|
2017-02-27 22:52:40 +08:00
|
|
|
assert [[:rabbitmq_federation, :rabbitmq_stomp],
|
2016-12-07 20:55:00 +08:00
|
|
|
%{mode: :offline, enabled: [:rabbitmq_federation],
|
2017-02-27 22:52:40 +08:00
|
|
|
set: [:rabbitmq_federation, :rabbitmq_stomp]}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream1)
|
2017-01-26 20:21:20 +08:00
|
|
|
check_plugins_enabled([:rabbitmq_stomp, :rabbitmq_federation], context)
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|
|
|
|
|
2016-08-11 15:41:38 +08:00
|
|
|
test "updates plugin list and starts newly enabled plugins", context do
|
|
|
|
# Clears enabled plugins file and stop all plugins
|
2016-12-07 01:14:40 +08:00
|
|
|
set_enabled_plugins([], :online, context[:opts][:node], context[:opts])
|
2016-06-23 01:00:21 +08:00
|
|
|
|
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_stomp],
|
2016-12-07 20:55:00 +08:00
|
|
|
%{mode: :online,
|
2017-02-27 22:52:40 +08:00
|
|
|
started: [:rabbitmq_stomp], stopped: [],
|
|
|
|
enabled: [:rabbitmq_stomp],
|
|
|
|
set: [:rabbitmq_stomp]}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream0)
|
2016-08-23 21:28:34 +08:00
|
|
|
|
2017-01-26 20:21:20 +08:00
|
|
|
check_plugins_enabled([:rabbitmq_stomp], context)
|
2016-09-07 23:22:23 +08:00
|
|
|
assert_equal_sets([:amqp_client, :rabbitmq_stomp], currently_active_plugins(context))
|
2016-06-23 01:00:21 +08:00
|
|
|
|
2016-12-07 20:55:00 +08:00
|
|
|
{:stream, test_stream1} =
|
|
|
|
@command.run(["rabbitmq_federation"], context[:opts])
|
2017-02-27 22:52:40 +08:00
|
|
|
assert [[:rabbitmq_federation, :rabbitmq_stomp],
|
2016-12-07 20:55:00 +08:00
|
|
|
%{mode: :online,
|
|
|
|
started: [:rabbitmq_federation], stopped: [],
|
|
|
|
enabled: [:rabbitmq_federation],
|
2017-02-27 22:52:40 +08:00
|
|
|
set: [:rabbitmq_federation, :rabbitmq_stomp]}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream1)
|
2016-08-11 06:27:13 +08:00
|
|
|
|
2017-01-26 20:21:20 +08:00
|
|
|
check_plugins_enabled([:rabbitmq_stomp, :rabbitmq_federation], context)
|
2016-09-07 23:22:23 +08:00
|
|
|
assert_equal_sets([:amqp_client, :rabbitmq_federation, :rabbitmq_stomp], currently_active_plugins(context))
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|
|
|
|
|
2016-08-11 15:41:38 +08:00
|
|
|
test "can enable multiple plugins at once", context do
|
|
|
|
# Clears plugins file and stop all plugins
|
2016-12-07 01:14:40 +08:00
|
|
|
set_enabled_plugins([], :online, context[:opts][:node], context[:opts])
|
2016-06-23 01:00:21 +08:00
|
|
|
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream} =
|
|
|
|
@command.run(["rabbitmq_stomp", "rabbitmq_federation"], context[:opts])
|
2017-02-27 22:52:40 +08:00
|
|
|
assert [[:rabbitmq_federation, :rabbitmq_stomp],
|
2016-12-07 20:55:00 +08:00
|
|
|
%{mode: :online,
|
2017-02-27 22:52:40 +08:00
|
|
|
started: [:rabbitmq_federation, :rabbitmq_stomp], stopped: [],
|
|
|
|
enabled: [:rabbitmq_federation, :rabbitmq_stomp],
|
|
|
|
set: [:rabbitmq_federation, :rabbitmq_stomp]}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream)
|
2017-01-26 20:21:20 +08:00
|
|
|
check_plugins_enabled([:rabbitmq_stomp, :rabbitmq_federation], context)
|
2016-08-11 06:27:13 +08:00
|
|
|
|
2016-09-07 23:22:23 +08:00
|
|
|
assert_equal_sets([:amqp_client, :rabbitmq_federation, :rabbitmq_stomp], currently_active_plugins(context))
|
2016-06-23 01:00:21 +08:00
|
|
|
end
|
|
|
|
|
2016-08-11 15:41:38 +08:00
|
|
|
test "does not enable an already implicitly enabled plugin", context do
|
|
|
|
# Clears enabled plugins file and stop all plugins
|
2016-12-07 01:14:40 +08:00
|
|
|
set_enabled_plugins([:rabbitmq_federation], :online, context[:opts][:node], context[:opts])
|
2016-12-07 20:55:00 +08:00
|
|
|
assert {:stream, test_stream} =
|
|
|
|
@command.run(["amqp_client"], 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: [],
|
|
|
|
enabled: [],
|
2017-02-27 22:52:40 +08:00
|
|
|
set: [:rabbitmq_federation]}] ==
|
2016-12-07 20:55:00 +08:00
|
|
|
Enum.to_list(test_stream)
|
2017-01-26 20:21:20 +08:00
|
|
|
check_plugins_enabled([:rabbitmq_federation], context)
|
2016-08-11 15:41:38 +08:00
|
|
|
assert [:amqp_client, :rabbitmq_federation] ==
|
2016-08-09 23:26:05 +08:00
|
|
|
currently_active_plugins(context)
|
2016-06-23 01:00:21 +08:00
|
|
|
|
|
|
|
end
|
2016-08-11 06:27:13 +08:00
|
|
|
|
2017-01-27 22:55:09 +08:00
|
|
|
test "run: does not enable plugins with unmet version requirements", context do
|
2017-01-26 20:21:20 +08:00
|
|
|
set_enabled_plugins([], :online, context[:opts][:node], context[:opts])
|
|
|
|
|
|
|
|
plugins_directory = fixture_plugins_path("plugins_with_version_requirements")
|
|
|
|
opts = get_opts_with_plugins_directories(context, [plugins_directory])
|
|
|
|
switch_plugins_directories(context[:opts][:plugins_dir], opts[:plugins_dir])
|
|
|
|
|
2018-11-16 00:38:25 +08:00
|
|
|
{:stream, _} =
|
|
|
|
@command.run(["mock_rabbitmq_plugin_for_3_8"], opts)
|
|
|
|
check_plugins_enabled([:mock_rabbitmq_plugin_for_3_8], context)
|
2017-01-26 20:21:20 +08:00
|
|
|
|
2018-11-16 00:38:25 +08:00
|
|
|
# Not changed
|
|
|
|
{:error, _version_error} = @command.run(["mock_rabbitmq_plugin_for_3_7"], opts)
|
|
|
|
check_plugins_enabled([:mock_rabbitmq_plugin_for_3_8], context)
|
2017-01-27 22:55:09 +08:00
|
|
|
|
2017-01-26 20:21:20 +08:00
|
|
|
end
|
|
|
|
|
2017-01-27 22:55:09 +08:00
|
|
|
test "run: does not enable plugins with unmet version requirements even when enabling all plugins", context do
|
2017-01-27 00:28:01 +08:00
|
|
|
set_enabled_plugins([], :online, context[:opts][:node], context[:opts])
|
|
|
|
|
|
|
|
plugins_directory = fixture_plugins_path("plugins_with_version_requirements")
|
|
|
|
opts = get_opts_with_plugins_directories(context, [plugins_directory])
|
|
|
|
opts = Map.merge(opts, %{all: true})
|
|
|
|
switch_plugins_directories(context[:opts][:plugins_dir], opts[:plugins_dir])
|
|
|
|
|
2017-01-27 22:55:09 +08:00
|
|
|
{:error, _version_error} = @command.run([], opts)
|
2017-01-26 20:21:20 +08:00
|
|
|
|
2017-01-27 22:55:09 +08:00
|
|
|
check_plugins_enabled([], context)
|
2016-08-11 06:27:13 +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
|