Skip to content

Commit cf7ca5d

Browse files
Additional test coverage for #14793
1 parent f412512 commit cf7ca5d

File tree

8 files changed

+503
-6
lines changed

8 files changed

+503
-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: 119 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,119 @@ export_import_round_trip_case2(Config) ->
358363
{skip, "Should not run in mixed version environments"}
359364
end.
360365

366+
export_import_round_trip_operator_policy(Config) ->
367+
case rabbit_ct_helpers:is_mixed_versions() of
368+
false ->
369+
import_file_case(Config, "case23"),
370+
Defs = export(Config),
371+
Parameters = maps:get(parameters, Defs, []),
372+
OperatorPolicy = lists:filter(
373+
fun(P) ->
374+
maps:get(<<"component">>, P, undefined) =:= <<"operator_policy">>
375+
end,
376+
Parameters
377+
),
378+
?assertEqual(1, length(OperatorPolicy)),
379+
[OpPol] = OperatorPolicy,
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+
_ ->
388+
{skip, "Should not run in mixed version environments"}
389+
end.
390+
391+
export_import_round_trip_vhost_limits(Config) ->
392+
case rabbit_ct_helpers:is_mixed_versions() of
393+
false ->
394+
import_file_case(Config, "case6"),
395+
Defs = export(Config),
396+
Parameters = maps:get(parameters, Defs, []),
397+
VHostLimits = lists:filter(
398+
fun(P) ->
399+
maps:get(<<"component">>, P, undefined) =:= <<"vhost-limits">>
400+
end,
401+
Parameters
402+
),
403+
?assertEqual(1, length(VHostLimits)),
404+
[Limits] = VHostLimits,
405+
Value = maps:get(<<"value">>, Limits),
406+
?assert(is_map(Value)),
407+
?assertEqual(456, maps:get(<<"max-queues">>, Value)),
408+
?assertEqual(123, maps:get(<<"max-connections">>, Value)),
409+
import_parsed(Config, Defs);
410+
_ ->
411+
{skip, "Should not run in mixed version environments"}
412+
end.
413+
414+
export_import_round_trip_operator_policy_all_keys(Config) ->
415+
case rabbit_ct_helpers:is_mixed_versions() of
416+
false ->
417+
import_file_case(Config, "case24"),
418+
Defs = export(Config),
419+
Parameters = maps:get(parameters, Defs, []),
420+
[OpPol] = [P || P <- Parameters,
421+
maps:get(<<"component">>, P) =:= <<"operator_policy">>,
422+
maps:get(<<"name">>, P) =:= <<"regulated-queues">>],
423+
Value = maps:get(<<"value">>, OpPol),
424+
Definition = maps:get(<<"definition">>, Value),
425+
?assert(is_map(Definition)),
426+
?assertEqual(4, maps:size(Definition)),
427+
?assertEqual(3600000, maps:get(<<"expires">>, Definition)),
428+
?assertEqual(300000, maps:get(<<"message-ttl">>, Definition)),
429+
?assertEqual(10000, maps:get(<<"max-length">>, Definition)),
430+
?assertEqual(104857600, maps:get(<<"max-length-bytes">>, Definition)),
431+
import_parsed(Config, Defs);
432+
_ ->
433+
{skip, "Should not run in mixed version environments"}
434+
end.
435+
436+
export_import_round_trip_multiple_operator_policies(Config) ->
437+
case rabbit_ct_helpers:is_mixed_versions() of
438+
false ->
439+
import_file_case(Config, "case25"),
440+
Defs = export(Config),
441+
Parameters = maps:get(parameters, Defs, []),
442+
ExpectedPolicies = [<<"transient-queues">>, <<"limited-queues">>, <<"archive-queues">>],
443+
lists:foreach(fun(PolicyName) ->
444+
[OpPol] = [P || P <- Parameters,
445+
maps:get(<<"component">>, P) =:= <<"operator_policy">>,
446+
maps:get(<<"name">>, P) =:= PolicyName],
447+
Value = maps:get(<<"value">>, OpPol),
448+
Definition = maps:get(<<"definition">>, Value),
449+
?assert(is_map(Definition)),
450+
?assert(maps:size(Definition) >= 2)
451+
end, ExpectedPolicies),
452+
import_parsed(Config, Defs);
453+
_ ->
454+
{skip, "Should not run in mixed version environments"}
455+
end.
456+
457+
export_import_round_trip_mixed_parameters(Config) ->
458+
case rabbit_ct_helpers:is_mixed_versions() of
459+
false ->
460+
import_file_case(Config, "case26"),
461+
Defs = export(Config),
462+
Parameters = maps:get(parameters, Defs, []),
463+
[Limits] = [P || P <- Parameters,
464+
maps:get(<<"component">>, P) =:= <<"vhost-limits">>,
465+
maps:get(<<"name">>, P) =:= <<"limits">>],
466+
LimitsValue = maps:get(<<"value">>, Limits),
467+
?assert(is_map(LimitsValue)),
468+
[OpPol] = [P || P <- Parameters,
469+
maps:get(<<"component">>, P) =:= <<"operator_policy">>,
470+
maps:get(<<"name">>, P) =:= <<"temp-queues">>],
471+
OpPolValue = maps:get(<<"value">>, OpPol),
472+
OpPolDefinition = maps:get(<<"definition">>, OpPolValue),
473+
?assert(is_map(OpPolDefinition)),
474+
import_parsed(Config, Defs);
475+
_ ->
476+
{skip, "Should not run in mixed version environments"}
477+
end.
478+
361479
import_on_a_booting_node_using_classic_local_source(Config) ->
362480
%% see case5.json
363481
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)