From 96b62a3bb27960de2eaa169e86302d7b920d24ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Wed, 28 Jun 2017 16:49:04 +0200 Subject: [PATCH] rabbit_ct_broker_helpers: Use rabbitmq-plugins(8) to play with plugins ... instead of calling rabbit_plugins_main module directly. This way we are sure to test the same command as regular user. Moreover, this also works with the new CLI where rabbit_plugins_main is gone. --- .../src/rabbit_ct_broker_helpers.erl | 28 +++++++++------- .../src/rabbit_ct_helpers.erl | 33 +++++++++++++++++++ 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl b/deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl index 22900daaf5..2263c54ef3 100644 --- a/deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl +++ b/deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl @@ -1166,21 +1166,25 @@ clear_global_parameter(Config, Node, Name) -> %% ------------------------------------------------------------------- enable_plugin(Config, Node, Plugin) -> - plugin_action(Config, Node, enable, [Plugin], []). + plugin_action(Config, Node, [enable, Plugin]). disable_plugin(Config, Node, Plugin) -> - plugin_action(Config, Node, disable, [Plugin], []). + plugin_action(Config, Node, [disable, Plugin]). -plugin_action(Config, Node, Command, Args, Opts) -> - PluginsFile = rabbit_ct_broker_helpers:get_node_config(Config, Node, - enabled_plugins_file), - PluginsDir = rabbit_ct_broker_helpers:get_node_config(Config, Node, - plugins_dir), - Nodename = rabbit_ct_broker_helpers:get_node_config(Config, Node, - nodename), - rabbit_ct_broker_helpers:rpc(Config, Node, - rabbit_plugins_main, action, - [Command, Nodename, Args, Opts, PluginsFile, PluginsDir]). +plugin_action(Config, Node, Args) -> + Rabbitmqplugins = ?config(rabbitmq_plugins_cmd, Config), + NodeConfig = get_node_config(Config, Node), + Nodename = ?config(nodename, NodeConfig), + Env = [ + {"RABBITMQ_PID_FILE", ?config(pid_file, NodeConfig)}, + {"RABBITMQ_MNESIA_DIR", ?config(mnesia_dir, NodeConfig)}, + {"RABBITMQ_PLUGINS_DIR", ?config(plugins_dir, NodeConfig)}, + {"RABBITMQ_ENABLED_PLUGINS_FILE", + ?config(enabled_plugins_file, NodeConfig)} + ], + Cmd = [Rabbitmqplugins, "-n", Nodename | Args], + {ok, _} = rabbit_ct_helpers:exec(Cmd, [{env, Env}]), + ok. %% ------------------------------------------------------------------- diff --git a/deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl b/deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl index 384f607234..cdad2c2980 100644 --- a/deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl +++ b/deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl @@ -69,6 +69,7 @@ run_setup_steps(Config, ExtraSteps) -> fun ensure_make_cmd/1, fun ensure_erl_call_cmd/1, fun ensure_rabbitmqctl_cmd/1, + fun ensure_rabbitmq_plugins_cmd/1, fun ensure_ssl_certs/1, fun start_long_running_testsuite_monitor/1 ], @@ -256,6 +257,38 @@ ensure_rabbitmqctl_cmd(Config) -> end end. +ensure_rabbitmq_plugins_cmd(Config) -> + Rabbitmqplugins = case get_config(Config, rabbitmq_plugins_cmd) of + undefined -> + case os:getenv("RABBITMQ_PLUGINS") of + false -> + SrcDir = ?config(rabbit_srcdir, Config), + R = filename:join(SrcDir, "scripts/rabbitmq-plugins"), + case filelib:is_file(R) of + true -> R; + false -> false + end; + R -> + R + end; + R -> + R + end, + Error = {skip, "rabbitmq_plugins required, " ++ + "please set RABBITMQ_PLUGINS or 'rabbitmq_plugins_cmd' in ct config"}, + case Rabbitmqplugins of + false -> + Error; + _ -> + Cmd = [Rabbitmqplugins], + case exec(Cmd, [drop_stdout]) of + {error, 64, _} -> + set_config(Config, {rabbitmq_plugins_cmd, Rabbitmqplugins}); + _ -> + Error + end + end. + ensure_ssl_certs(Config) -> SrcDir = ?config(rabbitmq_ct_helpers_srcdir, Config), CertsMakeDir = filename:join([SrcDir, "tools", "tls-certs"]),