Skip to content

Commit

Permalink
Merge pull request #4245 from esl/cets_persistent_cluster_id
Browse files Browse the repository at this point in the history
Fix starting cets for persistent_cluster_id
  • Loading branch information
JanuszJakubiec committed Aug 6, 2024
2 parents 0f5700b + 51a380e commit 344108f
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 68 deletions.
31 changes: 26 additions & 5 deletions big_tests/tests/ejabberd_node_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
-export([init/1, init/2,
node_cwd/2,
restart_application/1, restart_application/2,
ensure_started_application/1, ensure_started_application/2,
call_fun/3, call_fun/4,
call_ctl/2, call_ctl/3,
call_ctl_with_args/3,
file_exists/1, file_exists/2,
backup_config_file/1, backup_config_file/2,
restore_config_file/1, restore_config_file/2,
modify_config_file/2, modify_config_file/4,
replace_config_file/1, replace_config_file/2,
get_cwd/2]).

-include_lib("common_test/include/ct.hrl").
Expand Down Expand Up @@ -73,9 +75,18 @@ restart_application(ApplicationName) ->

-spec restart_application(node(), atom()) -> ok.
restart_application(Node, ApplicationName) ->
ok = ejabberd_node_utils:call_fun(Node, application, stop, [ApplicationName]),
ok = ejabberd_node_utils:call_fun(Node, application, start, [ApplicationName]).
ok = call_fun(Node, application, stop, [ApplicationName]),
ok = call_fun(Node, application, start, [ApplicationName]).

-spec ensure_started_application(atom()) -> ok.
ensure_started_application(ApplicationName) ->
Node = distributed_helper:mim(),
ensure_started_application(Node#{timeout => timer:seconds(30)}, ApplicationName).

-spec ensure_started_application(node(), atom()) -> ok.
ensure_started_application(Node, ApplicationName) ->
call_fun(Node, application, stop, [ApplicationName]),
ok = call_fun(Node, application, start, [ApplicationName]).

-spec backup_config_file(ct_config()) -> ct_config().
backup_config_file(Config) ->
Expand Down Expand Up @@ -166,7 +177,17 @@ modify_config_file(Host, VarsToChange, Config, Format) ->

RPCSpec = distributed_helper:Host(),
NewCfgPath = update_config_path(RPCSpec, Format),
ok = ejabberd_node_utils:call_fun(RPCSpec, file, write_file, [NewCfgPath, TemplatedConfig]).
ok = call_fun(RPCSpec, file, write_file, [NewCfgPath, TemplatedConfig]).

-spec replace_config_file(binary()) -> ok.
replace_config_file(TomlContent) ->
Node = distributed_helper:mim(),
replace_config_file(Node, TomlContent).

-spec replace_config_file(distributed_helper:node_spec(), binary()) -> ok.
replace_config_file(RPCSpec, TomlContent) ->
NewCfgPath = update_config_path(RPCSpec, toml),
ok = call_fun(RPCSpec, file, write_file, [NewCfgPath, TomlContent]).

read_vars(File) ->
{ok, Terms} = file:consult(File),
Expand Down Expand Up @@ -204,10 +225,10 @@ update_config_path(RPCSpec, Format) ->
end.

get_config_path(RPCSpec) ->
ejabberd_node_utils:call_fun(RPCSpec, os, getenv, ["EJABBERD_CONFIG_PATH"]).
call_fun(RPCSpec, os, getenv, ["EJABBERD_CONFIG_PATH"]).

set_config_path(RPCSpec, Path) ->
ejabberd_node_utils:call_fun(RPCSpec, os, putenv, ["EJABBERD_CONFIG_PATH", Path]).
call_fun(RPCSpec, os, putenv, ["EJABBERD_CONFIG_PATH", Path]).

vars_file(toml) -> "vars-toml.config".

Expand Down
40 changes: 35 additions & 5 deletions big_tests/tests/persistent_cluster_id_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

%% test cases
-export([
can_start_with_cluster_id_in_cets_only/1,
all_nodes_in_the_cluster_have_the_same_cluster_id/1,
id_persists_after_restart/1,
same_cluster_id_in_backend_and_mnesia/1,
Expand All @@ -30,6 +31,7 @@

all() ->
[
{group, cets},
{group, mnesia},
{group, rdbms}
].
Expand All @@ -46,6 +48,7 @@ tests() ->

groups() ->
[
{cets, [], [can_start_with_cluster_id_in_cets_only]},
{mnesia, [], [all_nodes_in_the_cluster_have_the_same_cluster_id]},
{rdbms, [], tests()}
].
Expand All @@ -65,15 +68,21 @@ end_per_suite(_Config) ->
group(_Groupname) ->
[].

init_per_group(mnesia, Config) ->
case not mongoose_helper:is_rdbms_enabled(host_type()) of
init_per_group(rdbms, Config) ->
case mongoose_helper:is_rdbms_enabled(host_type()) of
true -> Config;
false -> {skip, require_rdbms}
end;
init_per_group(_, Config) ->
case not mongoose_helper:is_rdbms_enabled(host_type()) of
true ->
Config;
false -> {skip, require_no_rdbms}
end;
init_per_group(_Groupname, Config) ->
case mongoose_helper:is_rdbms_enabled(host_type()) of
init_per_group(mnesia, Config) ->
case not mongoose_helper:is_rdbms_enabled(host_type()) of
true -> Config;
false -> {skip, require_rdbms}
false -> {skip, require_no_rdbms}
end.

end_per_group(_Groupname, _Config) ->
Expand All @@ -82,12 +91,19 @@ end_per_group(_Groupname, _Config) ->
%%%===================================================================
%%% Testcase specific setup/teardown
%%%===================================================================
init_per_testcase(can_start_with_cluster_id_in_cets_only, Config) ->
Config1 = ejabberd_node_utils:init(Config),
ejabberd_node_utils:backup_config_file(Config1),
Config1;
init_per_testcase(all_nodes_in_the_cluster_have_the_same_cluster_id, Config) ->
distributed_helper:add_node_to_cluster(mim2(), Config),
Config;
init_per_testcase(_TestCase, Config) ->
Config.

end_per_testcase(can_start_with_cluster_id_in_cets_only, Config) ->
ejabberd_node_utils:restore_config_file(Config),
ejabberd_node_utils:ensure_started_application(mongooseim);
end_per_testcase(all_nodes_in_the_cluster_have_the_same_cluster_id, Config) ->
distributed_helper:remove_node_from_cluster(mim2(), Config),
Config;
Expand All @@ -97,6 +113,20 @@ end_per_testcase(_TestCase, _Config) ->
%%%===================================================================
%%% Individual Test Cases (from groups() definition)
%%%===================================================================

can_start_with_cluster_id_in_cets_only(_Config) ->
Toml = "[general]
hosts = [\"example.com\"]
default_server_domain = \"example.com\"
sm_backend = \"cets\"
s2s_backend = \"cets\"
component_backend = \"cets\"
[internal_databases.cets]
backend = \"file\"
node_list_file = \"etc/cets_disco.txt\"",
ejabberd_node_utils:replace_config_file(Toml),
ejabberd_node_utils:restart_application(mongooseim).

all_nodes_in_the_cluster_have_the_same_cluster_id(_Config) ->
{ok, ID_mim1} = mongoose_helper:successful_rpc(
mim(), mongoose_cluster_id, get_cached_cluster_id, []),
Expand Down
2 changes: 1 addition & 1 deletion doc/authentication-methods/dummy.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ where `Base` is `base_time` and `Variance` is `variance`, as configured below.

```toml
[auth.dummy]
base = 5
base_time = 5
variance = 10
```
2 changes: 1 addition & 1 deletion rel/files/mongooseim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EJABBERD_STATUS_PATH="{{mongooseim_status_dir}}/status"
export EJABBERD_STATUS_PATH="$EJABBERD_STATUS_PATH"

EJABBERD_SO_PATH=`ls -dt "$RUNNER_BASE_DIR"/lib/mongooseim-*/priv/lib | head -1`
EJABBERD_CONFIG_PATH="$RUNNER_ETC_DIR"/mongooseim.${MONGOOSEIM_CONFIG_FORMAT:-toml}
EJABBERD_CONFIG_PATH=${EJABBERD_CONFIG_PATH:-$RUNNER_ETC_DIR/mongooseim.${MONGOOSEIM_CONFIG_FORMAT:-toml}}
export EJABBERD_SO_PATH
export EJABBERD_CONFIG_PATH

Expand Down
Loading

0 comments on commit 344108f

Please sign in to comment.