Skip to content

Commit a7509f3

Browse files
committed
rabbit_ct_broker_helpers: Use CLI from secondary umbrella accordingly
[Why] When we interact with a RabbitMQ node using the CLI in a testcase, we need to use its own CLI, not the one from the first node. The reason is that the CLI from the first node will use code from a different possibly incompatible version of the code when it communicates with another node in the context of mixed-version testing. [How] We derive the path to the CLI from other variables, depending on the use of make(1) or Bazel.
1 parent 7d06f80 commit a7509f3

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,60 @@ rabbitmqctl(Config, Node, Args) ->
10801080
rabbitmqctl(Config, Node, Args, infinity).
10811081

10821082
rabbitmqctl(Config, Node, Args, Timeout) ->
1083-
Rabbitmqctl = ?config(rabbitmqctl_cmd, Config),
1083+
%% We want to use the CLI from the given node if there is a secondary
1084+
%% umbrella being configured.
1085+
I = get_node_index(Config, Node),
1086+
CanUseSecondary = (I + 1) rem 2 =:= 0,
1087+
BazelRunSecCmd = rabbit_ct_helpers:get_config(
1088+
Config, rabbitmq_run_secondary_cmd),
1089+
UseSecondaryUmbrella = case ?config(secondary_umbrella, Config) of
1090+
false ->
1091+
case BazelRunSecCmd of
1092+
undefined -> false;
1093+
_ -> CanUseSecondary
1094+
end;
1095+
_ ->
1096+
CanUseSecondary
1097+
end,
1098+
Rabbitmqctl = case UseSecondaryUmbrella of
1099+
true ->
1100+
case BazelRunSecCmd of
1101+
undefined ->
1102+
SrcDir = ?config(
1103+
secondary_rabbit_srcdir,
1104+
Config),
1105+
SecDepsDir = ?config(
1106+
secondary_erlang_mk_depsdir,
1107+
Config),
1108+
SecNewScriptsDir = filename:join(
1109+
[SecDepsDir,
1110+
SrcDir,
1111+
"sbin"]),
1112+
SecOldScriptsDir = filename:join(
1113+
[SecDepsDir,
1114+
"rabbit",
1115+
"scripts"]),
1116+
SecNewScriptsDirExists = filelib:is_dir(
1117+
SecNewScriptsDir),
1118+
SecScriptsDir =
1119+
case SecNewScriptsDirExists of
1120+
true -> SecNewScriptsDir;
1121+
false -> SecOldScriptsDir
1122+
end,
1123+
rabbit_misc:format(
1124+
"~ts/rabbitmqctl", [SecScriptsDir]);
1125+
_ ->
1126+
BazelSecScriptsDir = filename:dirname(
1127+
BazelRunSecCmd),
1128+
filename:join(
1129+
[BazelSecScriptsDir,
1130+
"sbin",
1131+
"rabbitmqctl"])
1132+
end;
1133+
false ->
1134+
?config(rabbitmqctl_cmd, Config)
1135+
end,
1136+
10841137
NodeConfig = get_node_config(Config, Node),
10851138
Nodename = ?config(nodename, NodeConfig),
10861139
Env0 = [
@@ -1138,6 +1191,23 @@ rabbitmq_queues(Config, Node, Args) ->
11381191
%% Other helpers.
11391192
%% -------------------------------------------------------------------
11401193

1194+
get_node_index(Config, Node) when is_atom(Node) andalso Node =/= undefined ->
1195+
NodeConfigs = get_node_configs(Config),
1196+
get_node_index1(NodeConfigs, Node, 0);
1197+
get_node_index(_Config, I) when is_integer(I) andalso I >= 0 ->
1198+
I.
1199+
1200+
get_node_index1([NodeConfig | Rest], Node, I) ->
1201+
case ?config(nodename, NodeConfig) of
1202+
Node ->
1203+
I;
1204+
_ ->
1205+
case ?config(initial_nodename, NodeConfig) of
1206+
Node -> I;
1207+
_ -> get_node_index1(Rest, Node, I + 1)
1208+
end
1209+
end.
1210+
11411211
get_node_configs(Config) ->
11421212
?config(rmq_nodes, Config).
11431213

0 commit comments

Comments
 (0)