Skip to content

Commit b9390af

Browse files
Merge pull request #14800 from rabbitmq/rabbitmq-server-14793
Definition export: convert proplists recursively before serializing #14793
2 parents 05d1eca + 9e999e7 commit b9390af

File tree

8 files changed

+489
-6
lines changed

8 files changed

+489
-6
lines changed

deps/rabbit/src/rabbit_definitions.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,10 +1110,10 @@ runtime_parameter_definition(Param) ->
11101110

11111111
maybe_map(Value) ->
11121112
%% Not all definitions are maps. `federation-upstream-set` is
1113-
%% a list of maps, and it should be exported as it has been
1114-
%% imported
1113+
%% a list of maps. We also need to recursively convert nested
1114+
%% proplists to maps (e.g. policy and operator policy definitions).
11151115
try
1116-
rabbit_data_coercion:to_map(Value)
1116+
rabbit_data_coercion:to_map_recursive(Value)
11171117
catch
11181118
error:badarg ->
11191119
Value

deps/rabbit/test/definition_import_SUITE.erl

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ groups() ->
7171

7272
{roundtrip, [], [
7373
export_import_round_trip_case1,
74-
export_import_round_trip_case2
74+
export_import_round_trip_case2,
75+
export_import_round_trip_operator_policy,
76+
export_import_round_trip_vhost_limits,
77+
export_import_round_trip_operator_policy_all_keys,
78+
export_import_round_trip_multiple_operator_policies,
79+
export_import_round_trip_mixed_parameters
7580
]},
7681

7782
{skip_if_unchanged, [], [
@@ -358,6 +363,105 @@ export_import_round_trip_case2(Config) ->
358363
{skip, "Should not run in mixed version environments"}
359364
end.
360365

366+
run_if_not_mixed_versions(Fun) ->
367+
case rabbit_ct_helpers:is_mixed_versions() of
368+
false -> Fun();
369+
_ -> {skip, "Should not run in mixed version environments"}
370+
end.
371+
372+
export_import_round_trip_operator_policy(Config) ->
373+
run_if_not_mixed_versions(fun() ->
374+
import_file_case(Config, "case23"),
375+
Defs = export(Config),
376+
Parameters = maps:get(parameters, Defs, []),
377+
[OpPol] = [P || P <- Parameters,
378+
maps:get(<<"component">>, P) =:= <<"operator_policy">>,
379+
maps:get(<<"name">>, P) =:= <<"transient-queue-ttl">>],
380+
Value = maps:get(<<"value">>, OpPol),
381+
Definition = maps:get(<<"definition">>, Value),
382+
?assert(is_map(Definition)),
383+
?assertEqual(1800000, maps:get(<<"expires">>, Definition)),
384+
?assertEqual(60000, maps:get(<<"message-ttl">>, Definition)),
385+
?assertEqual(1000, maps:get(<<"max-length">>, Definition)),
386+
import_parsed(Config, Defs)
387+
end).
388+
389+
export_import_round_trip_vhost_limits(Config) ->
390+
run_if_not_mixed_versions(fun() ->
391+
import_file_case(Config, "case6"),
392+
Defs = export(Config),
393+
Parameters = maps:get(parameters, Defs, []),
394+
VHostLimits = lists:filter(
395+
fun(P) ->
396+
maps:get(<<"component">>, P, undefined) =:= <<"vhost-limits">>
397+
end,
398+
Parameters
399+
),
400+
?assertEqual(1, length(VHostLimits)),
401+
[Limits] = VHostLimits,
402+
Value = maps:get(<<"value">>, Limits),
403+
?assert(is_map(Value)),
404+
?assertEqual(456, maps:get(<<"max-queues">>, Value)),
405+
?assertEqual(123, maps:get(<<"max-connections">>, Value)),
406+
import_parsed(Config, Defs)
407+
end).
408+
409+
export_import_round_trip_operator_policy_all_keys(Config) ->
410+
run_if_not_mixed_versions(fun() ->
411+
import_file_case(Config, "case24"),
412+
Defs = export(Config),
413+
Parameters = maps:get(parameters, Defs, []),
414+
[OpPol] = [P || P <- Parameters,
415+
maps:get(<<"component">>, P) =:= <<"operator_policy">>,
416+
maps:get(<<"name">>, P) =:= <<"regulated-queues">>],
417+
Value = maps:get(<<"value">>, OpPol),
418+
Definition = maps:get(<<"definition">>, Value),
419+
?assert(is_map(Definition)),
420+
?assertEqual(4, maps:size(Definition)),
421+
?assertEqual(3600000, maps:get(<<"expires">>, Definition)),
422+
?assertEqual(300000, maps:get(<<"message-ttl">>, Definition)),
423+
?assertEqual(10000, maps:get(<<"max-length">>, Definition)),
424+
?assertEqual(104857600, maps:get(<<"max-length-bytes">>, Definition)),
425+
import_parsed(Config, Defs)
426+
end).
427+
428+
export_import_round_trip_multiple_operator_policies(Config) ->
429+
run_if_not_mixed_versions(fun() ->
430+
import_file_case(Config, "case25"),
431+
Defs = export(Config),
432+
Parameters = maps:get(parameters, Defs, []),
433+
ExpectedPolicies = [<<"transient-queues">>, <<"limited-queues">>, <<"archive-queues">>],
434+
lists:foreach(fun(PolicyName) ->
435+
[OpPol] = [P || P <- Parameters,
436+
maps:get(<<"component">>, P) =:= <<"operator_policy">>,
437+
maps:get(<<"name">>, P) =:= PolicyName],
438+
Value = maps:get(<<"value">>, OpPol),
439+
Definition = maps:get(<<"definition">>, Value),
440+
?assert(is_map(Definition)),
441+
?assert(maps:size(Definition) >= 2)
442+
end, ExpectedPolicies),
443+
import_parsed(Config, Defs)
444+
end).
445+
446+
export_import_round_trip_mixed_parameters(Config) ->
447+
run_if_not_mixed_versions(fun() ->
448+
import_file_case(Config, "case26"),
449+
Defs = export(Config),
450+
Parameters = maps:get(parameters, Defs, []),
451+
[Limits] = [P || P <- Parameters,
452+
maps:get(<<"component">>, P) =:= <<"vhost-limits">>,
453+
maps:get(<<"name">>, P) =:= <<"limits">>],
454+
LimitsValue = maps:get(<<"value">>, Limits),
455+
?assert(is_map(LimitsValue)),
456+
[OpPol] = [P || P <- Parameters,
457+
maps:get(<<"component">>, P) =:= <<"operator_policy">>,
458+
maps:get(<<"name">>, P) =:= <<"temp-queues">>],
459+
OpPolValue = maps:get(<<"value">>, OpPol),
460+
OpPolDefinition = maps:get(<<"definition">>, OpPolValue),
461+
?assert(is_map(OpPolDefinition)),
462+
import_parsed(Config, Defs)
463+
end).
464+
361465
import_on_a_booting_node_using_classic_local_source(Config) ->
362466
%% see case5.json
363467
VHost = <<"vhost2">>,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"rabbit_version": "4.2.0",
3+
"users": [
4+
{
5+
"name": "guest",
6+
"password_hash": "J+UiUxNQ3I8uPn6Lo2obWcl93VgXgbw4R+xhl3L5zHwkRFZG",
7+
"hashing_algorithm": "rabbit_password_hashing_sha256",
8+
"tags": "administrator"
9+
}
10+
],
11+
"vhosts": [
12+
{
13+
"name": "/"
14+
}
15+
],
16+
"permissions": [
17+
{
18+
"user": "guest",
19+
"vhost": "/",
20+
"configure": ".*",
21+
"write": ".*",
22+
"read": ".*"
23+
}
24+
],
25+
"topic_permissions": [],
26+
"parameters": [
27+
{
28+
"value": {
29+
"pattern": "^amq\\.",
30+
"definition": {
31+
"expires": 1800000,
32+
"message-ttl": 60000,
33+
"max-length": 1000
34+
},
35+
"priority": 1,
36+
"apply-to": "queues"
37+
},
38+
"vhost": "/",
39+
"component": "operator_policy",
40+
"name": "transient-queue-ttl"
41+
}
42+
],
43+
"global_parameters": [],
44+
"policies": [],
45+
"queues": [],
46+
"exchanges": [],
47+
"bindings": []
48+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"rabbit_version": "4.2.0",
3+
"users": [
4+
{
5+
"name": "guest",
6+
"password_hash": "J+UiUxNQ3I8uPn6Lo2obWcl93VgXgbw4R+xhl3L5zHwkRFZG",
7+
"hashing_algorithm": "rabbit_password_hashing_sha256",
8+
"tags": "administrator"
9+
}
10+
],
11+
"vhosts": [
12+
{
13+
"name": "/"
14+
}
15+
],
16+
"permissions": [
17+
{
18+
"user": "guest",
19+
"vhost": "/",
20+
"configure": ".*",
21+
"read": ".*",
22+
"write": ".*"
23+
}
24+
],
25+
"topic_permissions": [],
26+
"parameters": [
27+
{
28+
"value": {
29+
"pattern": "^regulated\\.",
30+
"definition": {
31+
"expires": 3600000,
32+
"message-ttl": 300000,
33+
"max-length": 10000,
34+
"max-length-bytes": 104857600
35+
},
36+
"priority": 1,
37+
"apply-to": "queues"
38+
},
39+
"vhost": "/",
40+
"component": "operator_policy",
41+
"name": "regulated-queues"
42+
}
43+
],
44+
"global_parameters": [],
45+
"policies": [],
46+
"queues": [],
47+
"exchanges": [],
48+
"bindings": []
49+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"rabbit_version": "4.2.0",
3+
"users": [
4+
{
5+
"name": "guest",
6+
"password_hash": "J+UiUxNQ3I8uPn6Lo2obWcl93VgXgbw4R+xhl3L5zHwkRFZG",
7+
"hashing_algorithm": "rabbit_password_hashing_sha256",
8+
"tags": "administrator"
9+
}
10+
],
11+
"vhosts": [
12+
{
13+
"name": "/"
14+
}
15+
],
16+
"permissions": [
17+
{
18+
"user": "guest",
19+
"vhost": "/",
20+
"configure": ".*",
21+
"read": ".*",
22+
"write": ".*"
23+
}
24+
],
25+
"topic_permissions": [],
26+
"parameters": [
27+
{
28+
"value": {
29+
"pattern": "^transient\\.",
30+
"definition": {
31+
"expires": 300000,
32+
"message-ttl": 60000
33+
},
34+
"priority": 10,
35+
"apply-to": "queues"
36+
},
37+
"vhost": "/",
38+
"component": "operator_policy",
39+
"name": "transient-queues"
40+
},
41+
{
42+
"value": {
43+
"pattern": "^limited\\.",
44+
"definition": {
45+
"max-length": 5000,
46+
"max-length-bytes": 10485760
47+
},
48+
"priority": 5,
49+
"apply-to": "queues"
50+
},
51+
"vhost": "/",
52+
"component": "operator_policy",
53+
"name": "limited-queues"
54+
},
55+
{
56+
"value": {
57+
"pattern": "^archive\\.",
58+
"definition": {
59+
"expires": 2592000000,
60+
"max-length": 100000,
61+
"message-ttl": 86400000,
62+
"max-length-bytes": 1073741824
63+
},
64+
"priority": 1,
65+
"apply-to": "queues"
66+
},
67+
"vhost": "/",
68+
"component": "operator_policy",
69+
"name": "archive-queues"
70+
}
71+
],
72+
"global_parameters": [],
73+
"policies": [],
74+
"queues": [],
75+
"exchanges": [],
76+
"bindings": []
77+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"rabbit_version": "4.2.0",
3+
"users": [
4+
{
5+
"name": "guest",
6+
"password_hash": "J+UiUxNQ3I8uPn6Lo2obWcl93VgXgbw4R+xhl3L5zHwkRFZG",
7+
"hashing_algorithm": "rabbit_password_hashing_sha256",
8+
"tags": "administrator"
9+
}
10+
],
11+
"vhosts": [
12+
{
13+
"name": "/"
14+
}
15+
],
16+
"permissions": [
17+
{
18+
"user": "guest",
19+
"vhost": "/",
20+
"configure": ".*",
21+
"read": ".*",
22+
"write": ".*"
23+
}
24+
],
25+
"topic_permissions": [],
26+
"parameters": [
27+
{
28+
"value": {
29+
"max-connections": 500,
30+
"max-queues": 1000
31+
},
32+
"vhost": "/",
33+
"component": "vhost-limits",
34+
"name": "limits"
35+
},
36+
{
37+
"value": {
38+
"pattern": "^temp\\.",
39+
"definition": {
40+
"expires": 1800000,
41+
"max-length": 2000
42+
},
43+
"priority": 1,
44+
"apply-to": "queues"
45+
},
46+
"vhost": "/",
47+
"component": "operator_policy",
48+
"name": "temp-queues"
49+
}
50+
],
51+
"global_parameters": [],
52+
"policies": [],
53+
"queues": [],
54+
"exchanges": [],
55+
"bindings": []
56+
}

0 commit comments

Comments
 (0)