Skip to content

Commit a809e55

Browse files
Merge pull request #3333 from rabbitmq/mk-definition-import-of-vhost-with-metadata
Correctly import virtual host metadata
2 parents 28c5f67 + 2e61f51 commit a809e55

File tree

3 files changed

+92
-6
lines changed

3 files changed

+92
-6
lines changed

deps/rabbit/src/rabbit_definitions.erl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,13 @@ add_policy(VHost, Param, Username) ->
481481
-spec add_vhost(map(), rabbit_types:username()) -> ok.
482482

483483
add_vhost(VHost, ActingUser) ->
484-
VHostName = maps:get(name, VHost, undefined),
485-
VHostTrace = maps:get(tracing, VHost, undefined),
486-
VHostDefinition = maps:get(definition, VHost, undefined),
487-
VHostTags = maps:get(tags, VHost, undefined),
488-
rabbit_vhost:put_vhost(VHostName, VHostDefinition, VHostTags, VHostTrace, ActingUser).
484+
Name = maps:get(name, VHost, undefined),
485+
IsTracingEnabled = maps:get(tracing, VHost, undefined),
486+
Metadata = rabbit_data_coercion:atomize_keys(maps:get(metadata, VHost, #{})),
487+
Description = maps:get(description, VHost, maps:get(description, Metadata, <<"">>)),
488+
Tags = maps:get(tags, VHost, maps:get(tags, Metadata, [])),
489+
490+
rabbit_vhost:put_vhost(Name, Description, Tags, IsTracingEnabled, ActingUser).
489491

490492
add_permission(Permission, ActingUser) ->
491493
rabbit_auth_backend_internal:set_permissions(maps:get(user, Permission, undefined),

deps/rabbit/test/definition_import_SUITE.erl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ groups() ->
4545
import_case12,
4646
import_case13,
4747
import_case14,
48-
import_case15
48+
import_case15,
49+
import_case16
4950
]},
5051

5152
{boot_time_import_using_classic_source, [], [
@@ -206,6 +207,28 @@ import_case13(Config) ->
206207
import_case14(Config) -> import_file_case(Config, "case14").
207208
%% contains a user with tags as a list
208209
import_case15(Config) -> import_file_case(Config, "case15").
210+
%% contains a virtual host with tags
211+
import_case16(Config) ->
212+
case rabbit_ct_broker_helpers:enable_feature_flag(Config, virtual_host_metadata) of
213+
ok ->
214+
import_file_case(Config, "case16"),
215+
VHost = <<"tagged">>,
216+
VHostIsImported =
217+
fun () ->
218+
case vhost_lookup(Config, VHost) of
219+
{error, {no_such_vhosts, _}} -> false;
220+
_ -> true
221+
end
222+
end,
223+
rabbit_ct_helpers:await_condition(VHostIsImported, 20000),
224+
VHostRec = vhost_lookup(Config, VHost),
225+
?assertEqual(<<"A case16 description">>, vhost:get_description(VHostRec)),
226+
?assertEqual([multi_dc_replication,ab,cde], vhost:get_tags(VHostRec)),
227+
228+
ok;
229+
Skip ->
230+
Skip
231+
end.
209232

210233
export_import_round_trip_case1(Config) ->
211234
%% case 6 has runtime parameters that do not depend on any plugins
@@ -338,3 +361,6 @@ run_invalid_import_case(Path) ->
338361

339362
queue_lookup(Config, VHost, Name) ->
340363
rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_amqqueue, lookup, [rabbit_misc:r(VHost, queue, Name)]).
364+
365+
vhost_lookup(Config, VHost) ->
366+
rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_vhost, lookup, [VHost]).
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"bindings": [],
3+
"exchanges": [],
4+
"global_parameters": [
5+
{
6+
"name": "cluster_name",
7+
"value": "rabbitmq@localhost"
8+
}
9+
],
10+
"parameters": [],
11+
"permissions": [
12+
{
13+
"configure": ".*",
14+
"read": ".*",
15+
"user": "guest",
16+
"vhost": "/",
17+
"write": ".*"
18+
}
19+
],
20+
"policies": [],
21+
"queues": [],
22+
"rabbit_version": "3.9.1",
23+
"rabbitmq_version": "3.9.1",
24+
"topic_permissions": [],
25+
"users": [
26+
{
27+
"hashing_algorithm": "rabbit_password_hashing_sha256",
28+
"limits": {},
29+
"name": "guest",
30+
"password_hash": "wS4AT3B4Z5RpWlFn1FA30osf2C75D7WA3gem591ACDZ6saO6",
31+
"tags": [
32+
"administrator"
33+
]
34+
}
35+
],
36+
"vhosts": [
37+
{
38+
"limits": [],
39+
"metadata": {
40+
"description": "Default virtual host",
41+
"tags": []
42+
},
43+
"name": "/"
44+
},
45+
{
46+
"limits": [],
47+
"metadata": {
48+
"description": "A case16 description",
49+
"tags": [
50+
"multi_dc_replication",
51+
"ab",
52+
"cde"
53+
]
54+
},
55+
"name": "tagged"
56+
}
57+
]
58+
}

0 commit comments

Comments
 (0)