Skip to content

Commit

Permalink
Remove default value for nodelist_file
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed May 25, 2023
1 parent 058c188 commit 40bcaca
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
5 changes: 3 additions & 2 deletions doc/configuration/internal-databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ Namespace for the cluster. Only nodes with the same cluster name would be discov

### `internal_databases.cets.nodelist_file`

File to read a list of nodes from. Relative to the MongooseIM's config directory. This option is for the file backend.
File to read a list of nodes from. Relative to the MongooseIM's release directory. This option is for the file backend.
Required, if `backend = "file"`.

* **Syntax:** path.
* **Default:** `"cets_disco.txt"`
* **Default:** not specified.
* **Example:** `nodelist_file = "/etc/mim_nodes.txt"`
5 changes: 2 additions & 3 deletions src/config/mongoose_config_spec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,11 @@ internal_database_cets() ->
items = #{<<"backend">> => #option{type = atom,
validate = {enum, [file, rdbms]}},
<<"cluster_name">> => #option{type = atom, validate = non_empty},
%% Relative to the config directory (or an absolute name)
%% Relative to the release directory (or an absolute name)
<<"nodelist_file">> => #option{type = string,
validate = filename}
},
defaults = #{<<"backend">> => rdbms, <<"cluster_name">> => mongooseim,
<<"nodelist_file">> => "cets_disco.txt"}
defaults = #{<<"backend">> => rdbms, <<"cluster_name">> => mongooseim}
}.

%% path: internal_databases.*.*
Expand Down
16 changes: 12 additions & 4 deletions src/ejabberd_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,18 @@ cets_specs() ->

cets_specs(disabled) ->
[];
cets_specs(#{backend := DiscoBackend, cluster_name := ClusterName,
nodelist_file := NodeFile}) ->
ConfigDir = filename:dirname(mongoose_config:get_config_path()),
DiscoFile = filename:join(ConfigDir, NodeFile),
cets_specs(#{backend := DiscoBackend, cluster_name := ClusterName} = Opts) ->
DiscoFile =
case {DiscoBackend, Opts} of
{file, #{nodelist_file := NodeFile}} ->
NodeFile;
{file, _} ->
?LOG_CRITICAL(#{what => nodelist_file_option_is_required,
text => <<"Specify internal_databases.cets.nodelist_file option">>}),
error(nodelist_file_option_is_required);
_ ->
undefined
end,
DiscoOpts = #{
backend_module => disco_backend_to_module(DiscoBackend),
cluster_name => atom_to_binary(ClusterName),
Expand Down
6 changes: 2 additions & 4 deletions test/common/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ options("miscellaneous") ->
{hosts, [<<"localhost">>, <<"anonymous.localhost">>]},
{internal_databases,
#{cets =>
#{backend => rdbms, cluster_name => mongooseim,
nodelist_file => "cets_disco.txt"},
#{backend => rdbms, cluster_name => mongooseim},
mnesia => #{}}},
{language, <<"en">>},
{listen,
Expand Down Expand Up @@ -140,8 +139,7 @@ options("mongooseim-pgsql") ->
[<<"localhost">>, <<"anonymous.localhost">>, <<"localhost.bis">>]},
{internal_databases,
#{cets =>
#{backend => rdbms, cluster_name => mongooseim,
nodelist_file => "cets_disco.txt"},
#{backend => rdbms, cluster_name => mongooseim},
mnesia => #{}}},
{language, <<"en">>},
{listen,
Expand Down
4 changes: 3 additions & 1 deletion test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,8 @@ test_fast_tls_server(P, T) ->

internal_database_cets(_Config) ->
CetsEnabled = #{<<"internal_databases">> => #{<<"cets">> => #{}}},
CetsFile = #{<<"internal_databases">> => #{<<"cets">> =>
#{<<"backend">> => <<"file">>, <<"nodelist_file">> => <<"/dev/null">>}}},
%% No internal_databases section means an empty list of databases
?cfg([internal_databases], #{}, #{}), % default
%% Empty internal_databases could be configured explicitly
Expand All @@ -1217,7 +1219,7 @@ internal_database_cets(_Config) ->
#{<<"internal_databases">> => #{<<"cets">> => #{<<"cluster_name">> => <<"test">>}}}),

?cfg([internal_databases, cets, cluster_name], mongooseim, CetsEnabled),
?cfg([internal_databases, cets, nodelist_file], "cets_disco.txt", CetsEnabled),
?cfg([internal_databases, cets, nodelist_file], "/dev/null", CetsFile),
%% If only mnesia section is defined, CETS section is not included
?cfg([internal_databases], #{mnesia => #{}},
#{<<"internal_databases">> => #{<<"mnesia">> => #{}}}),
Expand Down

0 comments on commit 40bcaca

Please sign in to comment.