Skip to content

Commit fc18ca9

Browse files
committed
Correct a dependency of rabbit_prelaunch on rabbit
apps/rabbit_prelaunch should not depend on rabbit, since rabbit already depends on apps/rabbit_prelaunch. So, rabbit_plugins:maybe_migrate_enabled_plugins_file/1 becomes rabbit_prelaunch_plugins:maybe_migrate_enabled_plugins_file/1.
1 parent f8a8fe0 commit fc18ca9

File tree

4 files changed

+48
-46
lines changed

4 files changed

+48
-46
lines changed

apps/rabbitmq_prelaunch/src/rabbit_prelaunch.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ do_run() ->
9393
Context2 = rabbit_env:get_context_after_reloading_env(Context1),
9494

9595
%% Migrate the enabled_plugins file to the new location if necessary
96-
Context3 = rabbit_plugins:maybe_migrate_enabled_plugins_file(Context2),
96+
Context3 = rabbit_prelaunch_plugins:maybe_migrate_enabled_plugins_file(Context2),
9797

9898
?assertMatch(#{}, Context3),
9999
store_context(Context3),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-module(rabbit_prelaunch_plugins).
2+
3+
-include_lib("kernel/include/file.hrl").
4+
5+
-export([maybe_migrate_enabled_plugins_file/1]).
6+
7+
-define(ENABLED_PLUGINS_FILENAME, "enabled_plugins").
8+
9+
-spec maybe_migrate_enabled_plugins_file(map()) -> map().
10+
maybe_migrate_enabled_plugins_file(#{enabled_plugins_file := EnabledPluginsFile} = Context)
11+
when EnabledPluginsFile =/= undefined ->
12+
Context;
13+
maybe_migrate_enabled_plugins_file(#{os_type := {unix, _},
14+
config_base_dir := ConfigBaseDir,
15+
data_dir := DataDir} = Context) ->
16+
ModernLocation = filename:join(DataDir, ?ENABLED_PLUGINS_FILENAME),
17+
LegacyLocation = filename:join(ConfigBaseDir, ?ENABLED_PLUGINS_FILENAME),
18+
case {filelib:is_regular(ModernLocation),
19+
file:read_file_info(LegacyLocation)} of
20+
{false, {ok, #file_info{access = read_write}}} ->
21+
rabbit_log_prelaunch:info("NOTICE: Using 'enabled_plugins' file"
22+
" from ~p. Please migrate this file"
23+
" to its new location, ~p, as the"
24+
" previous location is deprecated.",
25+
[LegacyLocation, ModernLocation]),
26+
Context#{enabled_plugins_file := LegacyLocation};
27+
{false, {ok, #file_info{access = read}}} ->
28+
{ok, _} = file:copy(LegacyLocation, ModernLocation),
29+
rabbit_log_prelaunch:info("NOTICE: An 'enabled_plugins' file was"
30+
" found at ~p but was not read and"
31+
" writable. It has been copied to its"
32+
" new location at ~p and any changes"
33+
" to plugin status will be reflected"
34+
" there.", [LegacyLocation, ModernLocation]),
35+
Context#{enabled_plugins_file := ModernLocation};
36+
_ ->
37+
Context#{enabled_plugins_file := ModernLocation}
38+
end;
39+
maybe_migrate_enabled_plugins_file(#{data_dir := DataDir} = Context) ->
40+
Context#{enabled_plugins_file := filename:join(DataDir, ?ENABLED_PLUGINS_FILENAME)}.

src/rabbit_plugins.erl

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,13 @@
2323
-export([ensure/1]).
2424
-export([validate_plugins/1, format_invalid_plugins/1]).
2525
-export([is_strictly_plugin/1, strictly_plugins/2, strictly_plugins/1]).
26-
-export([plugins_dir/0, plugin_names/1, plugins_expand_dir/0, enabled_plugins_file/0,
27-
maybe_migrate_enabled_plugins_file/1]).
26+
-export([plugins_dir/0, plugin_names/1, plugins_expand_dir/0, enabled_plugins_file/0]).
2827

2928
% Export for testing purpose.
3029
-export([is_version_supported/2, validate_plugins/2]).
3130

3231
%%----------------------------------------------------------------------------
3332

34-
-define(ENABLED_PLUGINS_FILENAME, "enabled_plugins").
35-
36-
%%----------------------------------------------------------------------------
37-
3833
-type plugin_name() :: atom().
3934

4035
%%----------------------------------------------------------------------------
@@ -113,39 +108,6 @@ enabled_plugins_file() ->
113108
filename:join([rabbit_mnesia:dir(), "enabled_plugins"])
114109
end.
115110

116-
-spec maybe_migrate_enabled_plugins_file(map()) -> map().
117-
maybe_migrate_enabled_plugins_file(#{enabled_plugins_file := EnabledPluginsFile} = Context)
118-
when EnabledPluginsFile =/= undefined ->
119-
Context;
120-
maybe_migrate_enabled_plugins_file(#{os_type := {unix, _},
121-
config_base_dir := ConfigBaseDir,
122-
data_dir := DataDir} = Context) ->
123-
ModernLocation = filename:join(DataDir, ?ENABLED_PLUGINS_FILENAME),
124-
LegacyLocation = filename:join(ConfigBaseDir, ?ENABLED_PLUGINS_FILENAME),
125-
case {filelib:is_regular(ModernLocation),
126-
file:read_file_info(LegacyLocation)} of
127-
{false, {ok, #file_info{access = read_write}}} ->
128-
rabbit_log_prelaunch:info("NOTICE: Using 'enabled_plugins' file"
129-
" from ~p. Please migrate this file"
130-
" to its new location, ~p, as the"
131-
" previous location is deprecated.",
132-
[LegacyLocation, ModernLocation]),
133-
Context#{enabled_plugins_file := LegacyLocation};
134-
{false, {ok, #file_info{access = read}}} ->
135-
{ok, _} = file:copy(LegacyLocation, ModernLocation),
136-
rabbit_log_prelaunch:info("NOTICE: An 'enabled_plugins' file was"
137-
" found at ~p but was not read and"
138-
" writable. It has been copied to its"
139-
" new location at ~p and any changes"
140-
" to plugin status will be reflected"
141-
" there.", [LegacyLocation, ModernLocation]),
142-
Context#{enabled_plugins_file := ModernLocation};
143-
_ ->
144-
Context#{enabled_plugins_file := ModernLocation}
145-
end;
146-
maybe_migrate_enabled_plugins_file(#{data_dir := DataDir} = Context) ->
147-
Context#{enabled_plugins_file := filename:join(DataDir, ?ENABLED_PLUGINS_FILENAME)}.
148-
149111
-spec enabled_plugins() -> [atom()].
150112
enabled_plugins() ->
151113
case application:get_env(rabbit, enabled_plugins_file) of

test/rabbit_plugins_SUITE.erl renamed to test/rabbit_prelaunch_plugins_SUITE.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
%% Copyright (c) 2019-2020 VMware, Inc. or its affiliates. All rights reserved.
1515
%%
1616

17-
-module(rabbit_plugins_SUITE).
17+
-module(rabbit_prelaunch_plugins_SUITE).
1818

1919
-include_lib("common_test/include/ct.hrl").
2020
-include_lib("eunit/include/eunit.hrl").
@@ -100,7 +100,7 @@ end_per_testcase(_, Config) ->
100100
check_enabled_plugins_file_passthrough(_) ->
101101
Context = #{enabled_plugins_file => "/some/dir/enabled_plugins"},
102102
?assertMatch(#{enabled_plugins_file := "/some/dir/enabled_plugins"},
103-
rabbit_plugins:maybe_migrate_enabled_plugins_file(Context)).
103+
rabbit_prelaunch_plugins:maybe_migrate_enabled_plugins_file(Context)).
104104

105105
check_enabled_plugins_file_modern(Config) ->
106106
DataDir = proplists:get_value(rabbit_data_dir, Config),
@@ -113,7 +113,7 @@ check_enabled_plugins_file_modern(Config) ->
113113
data_dir => DataDir,
114114
enabled_plugins_file => undefined},
115115
?assertMatch(#{enabled_plugins_file := ExpectedLocation},
116-
rabbit_plugins:maybe_migrate_enabled_plugins_file(Context)).
116+
rabbit_prelaunch_plugins:maybe_migrate_enabled_plugins_file(Context)).
117117

118118
check_enabled_plugins_file_default(Config) ->
119119
DataDir = proplists:get_value(rabbit_data_dir, Config),
@@ -127,7 +127,7 @@ check_enabled_plugins_file_default(Config) ->
127127
data_dir => DataDir,
128128
enabled_plugins_file => undefined},
129129
?assertMatch(#{enabled_plugins_file := ExpectedLocation},
130-
rabbit_plugins:maybe_migrate_enabled_plugins_file(Context)).
130+
rabbit_prelaunch_plugins:maybe_migrate_enabled_plugins_file(Context)).
131131

132132
check_enabled_plugins_file_legacy(Config) ->
133133
DataDir = proplists:get_value(rabbit_data_dir, Config),
@@ -141,7 +141,7 @@ check_enabled_plugins_file_legacy(Config) ->
141141
data_dir => DataDir,
142142
enabled_plugins_file => undefined},
143143
?assertMatch(#{enabled_plugins_file := ExpectedLocation},
144-
rabbit_plugins:maybe_migrate_enabled_plugins_file(Context)).
144+
rabbit_prelaunch_plugins:maybe_migrate_enabled_plugins_file(Context)).
145145

146146
check_enabled_plugins_file_copy(Config) ->
147147
DataDir = proplists:get_value(rabbit_data_dir, Config),
@@ -157,7 +157,7 @@ check_enabled_plugins_file_copy(Config) ->
157157
data_dir => DataDir,
158158
enabled_plugins_file => undefined},
159159
?assertMatch(#{enabled_plugins_file := ExpectedLocation},
160-
rabbit_plugins:maybe_migrate_enabled_plugins_file(Context)),
160+
rabbit_prelaunch_plugins:maybe_migrate_enabled_plugins_file(Context)),
161161
{ok, File} = file:read_file(ExpectedLocation),
162162
?assertEqual("[rabbitmq_management].", unicode:characters_to_list(File)).
163163

0 commit comments

Comments
 (0)