Skip to content

Commit

Permalink
Delete vhost in a separate process
Browse files Browse the repository at this point in the history
  • Loading branch information
anhanhnguyen committed Feb 26, 2024
1 parent 01e4583 commit 5c17b2e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
10 changes: 8 additions & 2 deletions deps/rabbitmq_management/src/rabbit_mgmt_wm_vhost.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-export([init/2, resource_exists/2, to_json/2,
content_types_provided/2, content_types_accepted/2,
is_authorized/2, allowed_methods/2, accept_content/2,
delete_resource/2, id/1]).
delete_resource/2, delete_completed/2, id/1]).
-export([variances/2]).

-import(rabbit_misc, [pget/2]).
Expand All @@ -20,6 +20,8 @@

-dialyzer({nowarn_function, accept_content/2}).

-define(WAIT_FOR_VHOST_DELETION, 15000).

%%--------------------------------------------------------------------

init(Req, _State) ->
Expand Down Expand Up @@ -89,12 +91,16 @@ accept_content(ReqData0, Context = #context{user = #user{username = Username}})
delete_resource(ReqData, Context = #context{user = #user{username = Username}}) ->
VHost = id(ReqData),
try
rabbit_vhost:delete(VHost, Username)
Key = rpc:async_call(node(), rabbit_vhost, delete, [VHost, Username]),
rpc:nb_yield(Key, ?WAIT_FOR_VHOST_DELETION)
catch _:{error, {no_such_vhost, _}} ->
ok
end,
{true, ReqData, Context}.

delete_completed(ReqData, Context) ->
{rabbit_vhost:exists(id(ReqData)), ReqData, Context}.

is_authorized(ReqData, Context) ->
rabbit_mgmt_util:is_authorized_admin(ReqData, Context).

Expand Down
24 changes: 24 additions & 0 deletions deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ all_tests() -> [
vhosts_test,
vhosts_description_test,
vhosts_trace_test,
large_vhosts_delete_test,
users_test,
users_legacy_administrator_test,
adding_a_user_with_password_test,
Expand Down Expand Up @@ -510,6 +511,29 @@ vhosts_trace_test(Config) ->

passed.

large_vhosts_delete_test(Config) ->
http_put(Config, "/vhosts/myvhost", none, {group, '2xx'}),

{ok, Conn} =
amqp_connection:start(#amqp_params_direct{node =
rabbit_ct_broker_helpers:get_node_config(Config,
0,
nodename),
virtual_host = <<"myvhost">>}),
{ok, Ch} = amqp_connection:open_channel(Conn),
[amqp_channel:cast(Ch, #'queue.declare'{queue = integer_to_binary(Q), durable = true})
|| Q <- lists:seq(0, 10000)],
amqp_channel:close(Ch),
close_connection(Conn),

http_delete(Config, "/vhosts/myvhost", ?ACCEPTED),

timer:sleep(5000),
http_put(Config, "/vhosts/myvhost", none, {group, '2xx'}),
http_get(Config, "/aliveness-test/myvhost", ?OK),

passed.

users_test(Config) ->
assert_item(#{name => <<"guest">>, tags => [<<"administrator">>]},
http_get(Config, "/whoami")),
Expand Down

0 comments on commit 5c17b2e

Please sign in to comment.