From 9291d7241024e24d6dd5ca98530cc37011827e8f Mon Sep 17 00:00:00 2001 From: Philip Kuryloski Date: Mon, 30 Mar 2020 23:06:32 +0200 Subject: [PATCH 1/3] Move the location of the 'enabled_plugins' file From /etc/rabbitmq to /var/lib/rabbitmq on unix, but fallback to the original location if there is no file at the new location, and the file at the old location is both readable and writable. --- src/rabbit_env.erl | 29 ++++- test/rabbit_env_SUITE.erl | 218 +++++++++++++++++++++++--------------- 2 files changed, 162 insertions(+), 85 deletions(-) diff --git a/src/rabbit_env.erl b/src/rabbit_env.erl index 1397ced7..8f71d92e 100644 --- a/src/rabbit_env.erl +++ b/src/rabbit_env.erl @@ -1087,8 +1087,33 @@ enabled_plugins_file_from_env(Context) -> update_context(Context, enabled_plugins_file, File, environment) end. -get_default_enabled_plugins_file(#{config_base_dir := ConfigBaseDir}) -> - filename:join(ConfigBaseDir, "enabled_plugins"). +get_default_enabled_plugins_file(#{os_type := {unix, _}, + config_base_dir := ConfigBaseDir, + data_dir := DataDir}) -> + LegacyLocation = filename:join(ConfigBaseDir, "enabled_plugins"), + ModernLocation = filename:join(DataDir, "enabled_plugins"), + case {filelib:is_regular(ModernLocation), + file:read_file_info(LegacyLocation)} of + {false, {ok, #file_info{access = read_write}}} -> + rabbit_log_prelaunch:info("NOTICE: Using 'enabled_plugins' file" + " from ~p.", [LegacyLocation]), + rabbit_log_prelaunch:info("Please migrate this file to its new" + " location, ~p, as the old location is" + " deprecated.", [ModernLocation]), + LegacyLocation; + {false, _} -> + rabbit_log_prelaunch:info("NOTICE: An 'enabled_plugins' file was" + " found at ~p but was not writable and" + " will be ignored.", [LegacyLocation]), + rabbit_log_prelaunch:info("The file will instead be created at" + " ~p as the previos location is" + " deprecated.", [ModernLocation]), + ModernLocation; + _ -> + ModernLocation + end; +get_default_enabled_plugins_file(#{data_dir := DataDir}) -> + filename:join(DataDir, "enabled_plugins"). enabled_plugins_file_from_node(#{from_remote_node := Remote} = Context) -> Ret = query_remote(Remote, diff --git a/test/rabbit_env_SUITE.erl b/test/rabbit_env_SUITE.erl index 3db0ce89..7228a65a 100644 --- a/test/rabbit_env_SUITE.erl +++ b/test/rabbit_env_SUITE.erl @@ -18,86 +18,14 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). +-include_lib("kernel/include/file.hrl"). --export([all/0, - suite/0, - groups/0, - init_per_group/2, - end_per_group/2, - init_per_testcase/2, - end_per_testcase/2, - check_data_dir/1, - check_default_values/1, - check_values_from_reachable_remote_node/1, - check_values_from_offline_remote_node/1, - check_context_to_app_env_vars/1, - check_context_to_code_path/1, - check_RABBITMQ_ADVANCED_CONFIG_FILE/1, - check_RABBITMQ_CONFIG_FILE/1, - check_RABBITMQ_CONFIG_FILES/1, - check_RABBITMQ_DIST_PORT/1, - check_RABBITMQ_ENABLED_PLUGINS/1, - check_RABBITMQ_ENABLED_PLUGINS_FILE/1, - check_RABBITMQ_FEATURE_FLAGS_FILE/1, - check_RABBITMQ_KEEP_PID_FILE_ON_EXIT/1, - check_RABBITMQ_LOG/1, - check_RABBITMQ_LOG_BASE/1, - check_RABBITMQ_LOGS/1, - check_RABBITMQ_MNESIA_BASE/1, - check_RABBITMQ_MNESIA_DIR/1, - check_RABBITMQ_MOTD_FILE/1, - check_RABBITMQ_NODE_IP_ADDRESS/1, - check_RABBITMQ_NODE_PORT/1, - check_RABBITMQ_NODENAME/1, - check_RABBITMQ_PID_FILE/1, - check_RABBITMQ_PLUGINS_DIR/1, - check_RABBITMQ_PLUGINS_EXPAND_DIR/1, - check_RABBITMQ_PRODUCT_NAME/1, - check_RABBITMQ_PRODUCT_VERSION/1, - check_RABBITMQ_QUORUM_DIR/1, - check_RABBITMQ_UPGRADE_LOG/1, - check_RABBITMQ_USE_LOGNAME/1, - check_value_is_yes/1, - check_log_process_env/1, - check_log_context/1 - ]). +-compile(export_all). all() -> [ - check_data_dir, - check_default_values, - check_values_from_reachable_remote_node, - check_values_from_offline_remote_node, - check_context_to_app_env_vars, - check_context_to_code_path, - check_RABBITMQ_ADVANCED_CONFIG_FILE, - check_RABBITMQ_CONFIG_FILE, - check_RABBITMQ_CONFIG_FILES, - check_RABBITMQ_DIST_PORT, - check_RABBITMQ_ENABLED_PLUGINS, - check_RABBITMQ_ENABLED_PLUGINS_FILE, - check_RABBITMQ_FEATURE_FLAGS_FILE, - check_RABBITMQ_KEEP_PID_FILE_ON_EXIT, - check_RABBITMQ_LOG, - check_RABBITMQ_LOG_BASE, - check_RABBITMQ_LOGS, - check_RABBITMQ_MNESIA_BASE, - check_RABBITMQ_MNESIA_DIR, - check_RABBITMQ_MOTD_FILE, - check_RABBITMQ_NODE_IP_ADDRESS, - check_RABBITMQ_NODE_PORT, - check_RABBITMQ_NODENAME, - check_RABBITMQ_PID_FILE, - check_RABBITMQ_PLUGINS_DIR, - check_RABBITMQ_PLUGINS_EXPAND_DIR, - check_RABBITMQ_PRODUCT_NAME, - check_RABBITMQ_PRODUCT_VERSION, - check_RABBITMQ_QUORUM_DIR, - check_RABBITMQ_UPGRADE_LOG, - check_RABBITMQ_USE_LOGNAME, - check_value_is_yes, - check_log_process_env, - check_log_context + {group, main_tests}, + {group, enabled_plugins_file_tests} ]. suite() -> @@ -105,14 +33,92 @@ suite() -> groups() -> [ - {parallel_tests, [parallel], all()} + {main_tests, [], [ + check_data_dir, + check_default_values, + check_values_from_reachable_remote_node, + check_values_from_offline_remote_node, + check_context_to_app_env_vars, + check_context_to_code_path, + check_RABBITMQ_ADVANCED_CONFIG_FILE, + check_RABBITMQ_CONFIG_FILE, + check_RABBITMQ_CONFIG_FILES, + check_RABBITMQ_DIST_PORT, + check_RABBITMQ_ENABLED_PLUGINS, + check_RABBITMQ_ENABLED_PLUGINS_FILE, + check_RABBITMQ_FEATURE_FLAGS_FILE, + check_RABBITMQ_KEEP_PID_FILE_ON_EXIT, + check_RABBITMQ_LOG, + check_RABBITMQ_LOG_BASE, + check_RABBITMQ_LOGS, + check_RABBITMQ_MNESIA_BASE, + check_RABBITMQ_MNESIA_DIR, + check_RABBITMQ_MOTD_FILE, + check_RABBITMQ_NODE_IP_ADDRESS, + check_RABBITMQ_NODE_PORT, + check_RABBITMQ_NODENAME, + check_RABBITMQ_PID_FILE, + check_RABBITMQ_PLUGINS_DIR, + check_RABBITMQ_PLUGINS_EXPAND_DIR, + check_RABBITMQ_PRODUCT_NAME, + check_RABBITMQ_PRODUCT_VERSION, + check_RABBITMQ_QUORUM_DIR, + check_RABBITMQ_UPGRADE_LOG, + check_RABBITMQ_USE_LOGNAME, + check_value_is_yes, + check_log_process_env, + check_log_context + ]}, + {enabled_plugins_file_tests, [], [ + check_enabled_plugins_file_normal, + check_enabled_plugins_file_fallback, + check_enabled_plugins_file_warning + ]} ]. -init_per_group(_, Config) -> Config. -end_per_group(_, Config) -> Config. - -init_per_testcase(_, Config) -> Config. -end_per_testcase(_, Config) -> Config. +init_per_group(enabled_plugins_file_tests, Config) -> + case os:type() of + {unix, _} -> + DataDir = proplists:get_value(data_dir, Config), + true = os:putenv("SYS_PREFIX", DataDir), + RabbitConfigBaseDir = filename:join(DataDir, "etc/rabbitmq"), + ok = filelib:ensure_dir(RabbitConfigBaseDir), + RabbitDataDir = filename:join(DataDir, "var/lib/rabbitmq"), + [{rabbit_config_base_dir, RabbitConfigBaseDir}, + {rabbit_data_dir, RabbitDataDir} | Config]; + _ -> + {skip, "enabled_plugins_file fallback behavior does not apply to Windows"} + end; +init_per_group(_, Config) -> + Config. + +end_per_group(enabled_plugins_file_tests, Config) -> + true = os:unsetenv("SYS_PREFIX"), + Config; +end_per_group(_, Config) -> + Config. + +init_per_testcase(check_enabled_plugins_file_normal, Config) -> + Config; +init_per_testcase(check_enabled_plugins_file_fallback, Config) -> + create_enabled_plugins_file(Config, 8#600); +init_per_testcase(check_enabled_plugins_file_warning, Config) -> + create_enabled_plugins_file(Config, 8#400); +init_per_testcase(_, Config) -> + Config. + +end_per_testcase(check_enabled_plugins_file_normal, Config) -> + Config; +end_per_testcase(check_enabled_plugins_file_fallback, Config) -> + EnabledPluginsFile = proplists:get_value(enabled_plugins_file, Config), + ok = file:delete(EnabledPluginsFile), + Config; +end_per_testcase(check_enabled_plugins_file_warning, Config) -> + EnabledPluginsFile = proplists:get_value(enabled_plugins_file, Config), + ok = file:delete(EnabledPluginsFile), + Config; +end_per_testcase(_, Config) -> + Config. check_data_dir(_) -> {Variable, ExpValue} = case os:type() of @@ -203,7 +209,7 @@ check_default_values(_) -> dbg_mods => [], dbg_output => stdout, enabled_plugins => undefined, - enabled_plugins_file => "/etc/rabbitmq/enabled_plugins", + enabled_plugins_file => "/var/lib/rabbitmq/enabled_plugins", erlang_dist_tcp_port => 25672, feature_flags_file => "/var/lib/rabbitmq/mnesia/" ++ NodeS ++ "-feature_flags", @@ -986,6 +992,44 @@ check_prefixed_variable("RABBITMQ_" ++ Variable = PrefixedVariable, ?assertMatch(#{Key := DefaultValue}, Context) end. +check_enabled_plugins_file_normal(Config) -> + % If /var/lib/rabbitmq/enabled_plugins is missing AND + % /etc/rabbitmq/enabled_plugins is missing, we use the new + % default location without any message + DataDir = proplists:get_value(rabbit_data_dir, Config), + ConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), + false = filelib:is_regular(filename:join(DataDir, "enabled_plugins")), + false = filelib:is_regular(filename:join(ConfigBaseDir, "enabled_plugins")), + ?assertEqual(filename:join(DataDir, "enabled_plugins"), + maps:get(enabled_plugins_file, rabbit_env:get_context())). + +check_enabled_plugins_file_fallback(Config) -> + % If /var/lib/rabbitmq/enabled_plugins is missing AND + % /etc/rabbitmq/enabled_plugins is present and writable, we use + % it and log a message + DataDir = proplists:get_value(rabbit_data_dir, Config), + ConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), + false = filelib:is_regular(filename:join(DataDir, "enabled_plugins")), + {ok, #file_info{access = read_write}} = file:read_file_info( + filename:join(ConfigBaseDir, + "enabled_plugins")), + #{enabled_plugins_file := EnabledPluginsFile} = rabbit_env:get_context(), + ?assertEqual(filename:join(ConfigBaseDir, "enabled_plugins"), + maps:get(enabled_plugins_file, rabbit_env:get_context())). + +check_enabled_plugins_file_warning(Config) -> + % If /var/lib/rabbitmq/enabled_plugins is missing AND + % /etc/rabbitmq/enabled_plugins is present but not writable, we + % ignore it and log a message. + DataDir = proplists:get_value(rabbit_data_dir, Config), + ConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), + false = filelib:is_regular(filename:join(DataDir, "enabled_plugins")), + {ok, #file_info{access = read}} = file:read_file_info( + filename:join(ConfigBaseDir, + "enabled_plugins")), + ?assertEqual(filename:join(DataDir, "enabled_plugins"), + maps:get(enabled_plugins_file, rabbit_env:get_context())). + random_int() -> rand:uniform(50000). random_string() -> integer_to_list(random_int()). random_atom() -> list_to_atom(random_string()). @@ -998,3 +1042,11 @@ get_default_nodename() -> "rabbit@\\1", [{return, list}]), list_to_atom(NodeS). + +create_enabled_plugins_file(Config, Perm) -> + RabbitConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), + EnabledPluginsFile = filename:join(RabbitConfigBaseDir, "enabled_plugins"), + FileContent = io_lib:format("[rabbitmq_management].", []), + ok = file:write_file(EnabledPluginsFile, FileContent), + ok = file:change_mode(EnabledPluginsFile, Perm), + [{enabled_plugins_file, EnabledPluginsFile} | Config]. From e96b9d1f94c92aa6435bc91e066d60158eb63be3 Mon Sep 17 00:00:00 2001 From: Philip Kuryloski Date: Tue, 31 Mar 2020 11:36:13 +0200 Subject: [PATCH 2/3] Enhance 'enabled_plugins' fallback behavior If the 'enabled_plugins' file is present at the legacy location, but not writable, we now copy it to the modern location first, rather than ignore it The intention is to avoid a change in behavior for users who configured plugins this way for startup, but never changed them. --- .gitignore | 1 + src/rabbit_env.erl | 23 +++++++------- test/rabbit_env_SUITE.erl | 65 ++++++++++++++++++++------------------- 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index f6096314..58477926 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ /sbin/ /sbin.lock /test/ct.cover.spec +/test/*_SUITE_data/ /xrefr /rabbit_common.d diff --git a/src/rabbit_env.erl b/src/rabbit_env.erl index 8f71d92e..b75b3dd9 100644 --- a/src/rabbit_env.erl +++ b/src/rabbit_env.erl @@ -1090,24 +1090,25 @@ enabled_plugins_file_from_env(Context) -> get_default_enabled_plugins_file(#{os_type := {unix, _}, config_base_dir := ConfigBaseDir, data_dir := DataDir}) -> - LegacyLocation = filename:join(ConfigBaseDir, "enabled_plugins"), ModernLocation = filename:join(DataDir, "enabled_plugins"), + LegacyLocation = filename:join(ConfigBaseDir, "enabled_plugins"), case {filelib:is_regular(ModernLocation), file:read_file_info(LegacyLocation)} of {false, {ok, #file_info{access = read_write}}} -> rabbit_log_prelaunch:info("NOTICE: Using 'enabled_plugins' file" - " from ~p.", [LegacyLocation]), - rabbit_log_prelaunch:info("Please migrate this file to its new" - " location, ~p, as the old location is" - " deprecated.", [ModernLocation]), + " from ~p. Please migrate this file" + " to its new location, ~p, as the" + " previous location is deprecated.", + [LegacyLocation, ModernLocation]), LegacyLocation; - {false, _} -> + {false, {ok, #file_info{access = read}}} -> + {ok, _} = file:copy(LegacyLocation, ModernLocation), rabbit_log_prelaunch:info("NOTICE: An 'enabled_plugins' file was" - " found at ~p but was not writable and" - " will be ignored.", [LegacyLocation]), - rabbit_log_prelaunch:info("The file will instead be created at" - " ~p as the previos location is" - " deprecated.", [ModernLocation]), + " found at ~p but was not read and" + " writable. It has been copied to its" + " new location at ~p and any changes" + " to plugin status will be reflected" + " there.", [LegacyLocation, ModernLocation]), ModernLocation; _ -> ModernLocation diff --git a/test/rabbit_env_SUITE.erl b/test/rabbit_env_SUITE.erl index 7228a65a..31b80ff0 100644 --- a/test/rabbit_env_SUITE.erl +++ b/test/rabbit_env_SUITE.erl @@ -71,8 +71,8 @@ groups() -> ]}, {enabled_plugins_file_tests, [], [ check_enabled_plugins_file_normal, - check_enabled_plugins_file_fallback, - check_enabled_plugins_file_warning + check_enabled_plugins_file_legacy, + check_enabled_plugins_file_copy ]} ]. @@ -81,9 +81,14 @@ init_per_group(enabled_plugins_file_tests, Config) -> {unix, _} -> DataDir = proplists:get_value(data_dir, Config), true = os:putenv("SYS_PREFIX", DataDir), - RabbitConfigBaseDir = filename:join(DataDir, "etc/rabbitmq"), - ok = filelib:ensure_dir(RabbitConfigBaseDir), - RabbitDataDir = filename:join(DataDir, "var/lib/rabbitmq"), + RabbitConfigBaseDir = filename:join([DataDir, "etc", "rabbitmq"]), + LegacyFile = filename:join(RabbitConfigBaseDir, "enabled_plugins"), + ok = delete_if_present(LegacyFile), + ok = filelib:ensure_dir(LegacyFile), + RabbitDataDir = filename:join([DataDir, "var", "lib", "rabbitmq"]), + ModernFile = filename:join(RabbitDataDir, "enabled_plugins"), + ok = delete_if_present(ModernFile), + ok = filelib:ensure_dir(ModernFile), [{rabbit_config_base_dir, RabbitConfigBaseDir}, {rabbit_data_dir, RabbitDataDir} | Config]; _ -> @@ -100,23 +105,13 @@ end_per_group(_, Config) -> init_per_testcase(check_enabled_plugins_file_normal, Config) -> Config; -init_per_testcase(check_enabled_plugins_file_fallback, Config) -> +init_per_testcase(check_enabled_plugins_file_legacy, Config) -> create_enabled_plugins_file(Config, 8#600); -init_per_testcase(check_enabled_plugins_file_warning, Config) -> +init_per_testcase(check_enabled_plugins_file_copy, Config) -> create_enabled_plugins_file(Config, 8#400); init_per_testcase(_, Config) -> Config. -end_per_testcase(check_enabled_plugins_file_normal, Config) -> - Config; -end_per_testcase(check_enabled_plugins_file_fallback, Config) -> - EnabledPluginsFile = proplists:get_value(enabled_plugins_file, Config), - ok = file:delete(EnabledPluginsFile), - Config; -end_per_testcase(check_enabled_plugins_file_warning, Config) -> - EnabledPluginsFile = proplists:get_value(enabled_plugins_file, Config), - ok = file:delete(EnabledPluginsFile), - Config; end_per_testcase(_, Config) -> Config. @@ -993,42 +988,38 @@ check_prefixed_variable("RABBITMQ_" ++ Variable = PrefixedVariable, end. check_enabled_plugins_file_normal(Config) -> - % If /var/lib/rabbitmq/enabled_plugins is missing AND - % /etc/rabbitmq/enabled_plugins is missing, we use the new - % default location without any message DataDir = proplists:get_value(rabbit_data_dir, Config), ConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), false = filelib:is_regular(filename:join(DataDir, "enabled_plugins")), false = filelib:is_regular(filename:join(ConfigBaseDir, "enabled_plugins")), + ?assertEqual(filename:join(DataDir, "enabled_plugins"), maps:get(enabled_plugins_file, rabbit_env:get_context())). -check_enabled_plugins_file_fallback(Config) -> - % If /var/lib/rabbitmq/enabled_plugins is missing AND - % /etc/rabbitmq/enabled_plugins is present and writable, we use - % it and log a message +check_enabled_plugins_file_legacy(Config) -> DataDir = proplists:get_value(rabbit_data_dir, Config), ConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), false = filelib:is_regular(filename:join(DataDir, "enabled_plugins")), {ok, #file_info{access = read_write}} = file:read_file_info( filename:join(ConfigBaseDir, "enabled_plugins")), - #{enabled_plugins_file := EnabledPluginsFile} = rabbit_env:get_context(), + ?assertEqual(filename:join(ConfigBaseDir, "enabled_plugins"), maps:get(enabled_plugins_file, rabbit_env:get_context())). -check_enabled_plugins_file_warning(Config) -> - % If /var/lib/rabbitmq/enabled_plugins is missing AND - % /etc/rabbitmq/enabled_plugins is present but not writable, we - % ignore it and log a message. +check_enabled_plugins_file_copy(Config) -> DataDir = proplists:get_value(rabbit_data_dir, Config), ConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), - false = filelib:is_regular(filename:join(DataDir, "enabled_plugins")), + ExpectedLocation = filename:join(DataDir, "enabled_plugins"), + false = filelib:is_regular(ExpectedLocation), {ok, #file_info{access = read}} = file:read_file_info( filename:join(ConfigBaseDir, "enabled_plugins")), - ?assertEqual(filename:join(DataDir, "enabled_plugins"), - maps:get(enabled_plugins_file, rabbit_env:get_context())). + + ?assertEqual(ExpectedLocation, + maps:get(enabled_plugins_file, rabbit_env:get_context())), + {ok, File} = file:read_file(ExpectedLocation), + ?assertEqual("[rabbitmq_management].", unicode:characters_to_list(File)). random_int() -> rand:uniform(50000). random_string() -> integer_to_list(random_int()). @@ -1050,3 +1041,13 @@ create_enabled_plugins_file(Config, Perm) -> ok = file:write_file(EnabledPluginsFile, FileContent), ok = file:change_mode(EnabledPluginsFile, Perm), [{enabled_plugins_file, EnabledPluginsFile} | Config]. + +delete_if_present(Filename) -> + case file:read_file_info(Filename) of + {ok, #file_info{type = regular}} -> + file:delete(Filename); + {ok, _} -> + {error, not_regular_file}; + _ -> + ok + end. From 7b558351b2469936d1af5078c9130144cdfa8084 Mon Sep 17 00:00:00 2001 From: Philip Kuryloski Date: Thu, 2 Apr 2020 15:02:09 +0200 Subject: [PATCH 3/3] Make the default enabled_plugins location undefined It is now undefined with respect to the context, as it will later determined later on by the rabbit_plugins module, potentially with side effects. Additionally, we rename the default group in the tests for clarity, since they were not actually run in parallel. --- .gitignore | 1 - src/rabbit_env.erl | 34 +-------- test/rabbit_env_SUITE.erl | 153 +++++++++++++------------------------- 3 files changed, 53 insertions(+), 135 deletions(-) diff --git a/.gitignore b/.gitignore index 58477926..f6096314 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,6 @@ /sbin/ /sbin.lock /test/ct.cover.spec -/test/*_SUITE_data/ /xrefr /rabbit_common.d diff --git a/src/rabbit_env.erl b/src/rabbit_env.erl index b75b3dd9..6010c5db 100644 --- a/src/rabbit_env.erl +++ b/src/rabbit_env.erl @@ -1080,42 +1080,12 @@ enabled_plugins_file(Context) -> enabled_plugins_file_from_env(Context) -> case get_prefixed_env_var("RABBITMQ_ENABLED_PLUGINS_FILE") of false -> - File = get_default_enabled_plugins_file(Context), - update_context(Context, enabled_plugins_file, File, default); + update_context(Context, enabled_plugins_file, undefined, default); Value -> File = normalize_path(Value), update_context(Context, enabled_plugins_file, File, environment) end. -get_default_enabled_plugins_file(#{os_type := {unix, _}, - config_base_dir := ConfigBaseDir, - data_dir := DataDir}) -> - ModernLocation = filename:join(DataDir, "enabled_plugins"), - LegacyLocation = filename:join(ConfigBaseDir, "enabled_plugins"), - case {filelib:is_regular(ModernLocation), - file:read_file_info(LegacyLocation)} of - {false, {ok, #file_info{access = read_write}}} -> - rabbit_log_prelaunch:info("NOTICE: Using 'enabled_plugins' file" - " from ~p. Please migrate this file" - " to its new location, ~p, as the" - " previous location is deprecated.", - [LegacyLocation, ModernLocation]), - LegacyLocation; - {false, {ok, #file_info{access = read}}} -> - {ok, _} = file:copy(LegacyLocation, ModernLocation), - rabbit_log_prelaunch:info("NOTICE: An 'enabled_plugins' file was" - " found at ~p but was not read and" - " writable. It has been copied to its" - " new location at ~p and any changes" - " to plugin status will be reflected" - " there.", [LegacyLocation, ModernLocation]), - ModernLocation; - _ -> - ModernLocation - end; -get_default_enabled_plugins_file(#{data_dir := DataDir}) -> - filename:join(DataDir, "enabled_plugins"). - enabled_plugins_file_from_node(#{from_remote_node := Remote} = Context) -> Ret = query_remote(Remote, application, get_env, [rabbit, enabled_plugins_file]), @@ -1497,7 +1467,7 @@ do_load_conf_env_file(Context, Sh, ConfEnvFile) -> {"CONFIG_FILE", MainConfigFile}, {"ADVANCED_CONFIG_FILE", get_default_advanced_config_file(Context)}, {"MNESIA_BASE", get_default_mnesia_base_dir(Context)}, - {"ENABLED_PLUGINS_FILE", get_default_enabled_plugins_file(Context)}, + {"ENABLED_PLUGINS_FILE", false}, {"PLUGINS_DIR", get_default_plugins_path_from_env(Context)}, {"CONF_ENV_FILE_PHASE", "rabbtimq-prelaunch"} ], diff --git a/test/rabbit_env_SUITE.erl b/test/rabbit_env_SUITE.erl index 31b80ff0..b315e120 100644 --- a/test/rabbit_env_SUITE.erl +++ b/test/rabbit_env_SUITE.erl @@ -18,14 +18,53 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). --include_lib("kernel/include/file.hrl"). --compile(export_all). +-export([all/0, + suite/0, + groups/0, + init_per_group/2, + end_per_group/2, + init_per_testcase/2, + end_per_testcase/2, + check_data_dir/1, + check_default_values/1, + check_values_from_reachable_remote_node/1, + check_values_from_offline_remote_node/1, + check_context_to_app_env_vars/1, + check_context_to_code_path/1, + check_RABBITMQ_ADVANCED_CONFIG_FILE/1, + check_RABBITMQ_CONFIG_FILE/1, + check_RABBITMQ_CONFIG_FILES/1, + check_RABBITMQ_DIST_PORT/1, + check_RABBITMQ_ENABLED_PLUGINS/1, + check_RABBITMQ_ENABLED_PLUGINS_FILE/1, + check_RABBITMQ_FEATURE_FLAGS_FILE/1, + check_RABBITMQ_KEEP_PID_FILE_ON_EXIT/1, + check_RABBITMQ_LOG/1, + check_RABBITMQ_LOG_BASE/1, + check_RABBITMQ_LOGS/1, + check_RABBITMQ_MNESIA_BASE/1, + check_RABBITMQ_MNESIA_DIR/1, + check_RABBITMQ_MOTD_FILE/1, + check_RABBITMQ_NODE_IP_ADDRESS/1, + check_RABBITMQ_NODE_PORT/1, + check_RABBITMQ_NODENAME/1, + check_RABBITMQ_PID_FILE/1, + check_RABBITMQ_PLUGINS_DIR/1, + check_RABBITMQ_PLUGINS_EXPAND_DIR/1, + check_RABBITMQ_PRODUCT_NAME/1, + check_RABBITMQ_PRODUCT_VERSION/1, + check_RABBITMQ_QUORUM_DIR/1, + check_RABBITMQ_UPGRADE_LOG/1, + check_RABBITMQ_USE_LOGNAME/1, + check_value_is_yes/1, + check_log_process_env/1, + check_log_context/1 + ]). all() -> [ - {group, main_tests}, - {group, enabled_plugins_file_tests} + {group, main_tests} ]. suite() -> @@ -68,52 +107,14 @@ groups() -> check_value_is_yes, check_log_process_env, check_log_context - ]}, - {enabled_plugins_file_tests, [], [ - check_enabled_plugins_file_normal, - check_enabled_plugins_file_legacy, - check_enabled_plugins_file_copy - ]} + ]} ]. -init_per_group(enabled_plugins_file_tests, Config) -> - case os:type() of - {unix, _} -> - DataDir = proplists:get_value(data_dir, Config), - true = os:putenv("SYS_PREFIX", DataDir), - RabbitConfigBaseDir = filename:join([DataDir, "etc", "rabbitmq"]), - LegacyFile = filename:join(RabbitConfigBaseDir, "enabled_plugins"), - ok = delete_if_present(LegacyFile), - ok = filelib:ensure_dir(LegacyFile), - RabbitDataDir = filename:join([DataDir, "var", "lib", "rabbitmq"]), - ModernFile = filename:join(RabbitDataDir, "enabled_plugins"), - ok = delete_if_present(ModernFile), - ok = filelib:ensure_dir(ModernFile), - [{rabbit_config_base_dir, RabbitConfigBaseDir}, - {rabbit_data_dir, RabbitDataDir} | Config]; - _ -> - {skip, "enabled_plugins_file fallback behavior does not apply to Windows"} - end; -init_per_group(_, Config) -> - Config. - -end_per_group(enabled_plugins_file_tests, Config) -> - true = os:unsetenv("SYS_PREFIX"), - Config; -end_per_group(_, Config) -> - Config. - -init_per_testcase(check_enabled_plugins_file_normal, Config) -> - Config; -init_per_testcase(check_enabled_plugins_file_legacy, Config) -> - create_enabled_plugins_file(Config, 8#600); -init_per_testcase(check_enabled_plugins_file_copy, Config) -> - create_enabled_plugins_file(Config, 8#400); -init_per_testcase(_, Config) -> - Config. - -end_per_testcase(_, Config) -> - Config. +init_per_group(_, Config) -> Config. +end_per_group(_, Config) -> Config. + +init_per_testcase(_, Config) -> Config. +end_per_testcase(_, Config) -> Config. check_data_dir(_) -> {Variable, ExpValue} = case os:type() of @@ -204,7 +205,7 @@ check_default_values(_) -> dbg_mods => [], dbg_output => stdout, enabled_plugins => undefined, - enabled_plugins_file => "/var/lib/rabbitmq/enabled_plugins", + enabled_plugins_file => undefined, erlang_dist_tcp_port => 25672, feature_flags_file => "/var/lib/rabbitmq/mnesia/" ++ NodeS ++ "-feature_flags", @@ -251,7 +252,7 @@ check_default_values(_) -> dbg_mods => [], dbg_output => stdout, enabled_plugins => undefined, - enabled_plugins_file => "%APPDATA%/RabbitMQ/enabled_plugins", + enabled_plugins_file => undefined, erlang_dist_tcp_port => 25672, feature_flags_file => "%APPDATA%/RabbitMQ/db/" ++ NodeS ++ "-feature_flags", @@ -987,40 +988,6 @@ check_prefixed_variable("RABBITMQ_" ++ Variable = PrefixedVariable, ?assertMatch(#{Key := DefaultValue}, Context) end. -check_enabled_plugins_file_normal(Config) -> - DataDir = proplists:get_value(rabbit_data_dir, Config), - ConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), - false = filelib:is_regular(filename:join(DataDir, "enabled_plugins")), - false = filelib:is_regular(filename:join(ConfigBaseDir, "enabled_plugins")), - - ?assertEqual(filename:join(DataDir, "enabled_plugins"), - maps:get(enabled_plugins_file, rabbit_env:get_context())). - -check_enabled_plugins_file_legacy(Config) -> - DataDir = proplists:get_value(rabbit_data_dir, Config), - ConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), - false = filelib:is_regular(filename:join(DataDir, "enabled_plugins")), - {ok, #file_info{access = read_write}} = file:read_file_info( - filename:join(ConfigBaseDir, - "enabled_plugins")), - - ?assertEqual(filename:join(ConfigBaseDir, "enabled_plugins"), - maps:get(enabled_plugins_file, rabbit_env:get_context())). - -check_enabled_plugins_file_copy(Config) -> - DataDir = proplists:get_value(rabbit_data_dir, Config), - ConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), - ExpectedLocation = filename:join(DataDir, "enabled_plugins"), - false = filelib:is_regular(ExpectedLocation), - {ok, #file_info{access = read}} = file:read_file_info( - filename:join(ConfigBaseDir, - "enabled_plugins")), - - ?assertEqual(ExpectedLocation, - maps:get(enabled_plugins_file, rabbit_env:get_context())), - {ok, File} = file:read_file(ExpectedLocation), - ?assertEqual("[rabbitmq_management].", unicode:characters_to_list(File)). - random_int() -> rand:uniform(50000). random_string() -> integer_to_list(random_int()). random_atom() -> list_to_atom(random_string()). @@ -1033,21 +1000,3 @@ get_default_nodename() -> "rabbit@\\1", [{return, list}]), list_to_atom(NodeS). - -create_enabled_plugins_file(Config, Perm) -> - RabbitConfigBaseDir = proplists:get_value(rabbit_config_base_dir, Config), - EnabledPluginsFile = filename:join(RabbitConfigBaseDir, "enabled_plugins"), - FileContent = io_lib:format("[rabbitmq_management].", []), - ok = file:write_file(EnabledPluginsFile, FileContent), - ok = file:change_mode(EnabledPluginsFile, Perm), - [{enabled_plugins_file, EnabledPluginsFile} | Config]. - -delete_if_present(Filename) -> - case file:read_file_info(Filename) of - {ok, #file_info{type = regular}} -> - file:delete(Filename); - {ok, _} -> - {error, not_regular_file}; - _ -> - ok - end.