@@ -26,6 +26,7 @@ groups() ->
2626 single_node_vhost_deletion_forces_connection_closure ,
2727 vhost_failure_forces_connection_closure ,
2828 vhost_creation_idempotency ,
29+ vhost_update_idempotency ,
2930 parse_tags
3031 ],
3132 ClusterSize2Tests = [
@@ -92,6 +93,13 @@ end_per_group(_Group, Config) ->
9293 rabbit_ct_client_helpers :teardown_steps () ++
9394 rabbit_ct_broker_helpers :teardown_steps ()).
9495
96+ init_per_testcase (vhost_update_idempotency = Testcase , Config ) ->
97+ rabbit_ct_helpers :testcase_started (Config , Testcase ),
98+ clear_all_connection_tracking_tables (Config ),
99+ case rabbit_ct_broker_helpers :enable_feature_flag (Config , virtual_host_metadata ) of
100+ ok -> Config ;
101+ Skip -> Skip
102+ end ;
95103init_per_testcase (Testcase , Config ) ->
96104 rabbit_ct_helpers :testcase_started (Config , Testcase ),
97105 clear_all_connection_tracking_tables (Config ),
@@ -319,6 +327,68 @@ vhost_creation_idempotency(Config) ->
319327 rabbit_ct_broker_helpers :delete_vhost (Config , VHost )
320328 end .
321329
330+ vhost_update_idempotency (Config ) ->
331+ VHost = <<" update-idempotency-test" >>,
332+ ActingUser = <<" acting-user" >>,
333+ try
334+ % load the dummy event handler on the node
335+ ok = rabbit_ct_broker_helpers :rpc (Config , 0 , test_rabbit_event_handler , okay , []),
336+
337+ ok = rabbit_ct_broker_helpers :rpc (Config , 0 , gen_event , add_handler ,
338+ [rabbit_event , test_rabbit_event_handler , []]),
339+
340+ ? assertEqual (ok , rabbit_ct_broker_helpers :add_vhost (Config , VHost )),
341+
342+ ? assertMatch ({vhost ,VHost , _ , #{tags := [private ,replicate ]}},
343+ rabbit_ct_broker_helpers :rpc (Config , 0 ,
344+ rabbit_vhost , update_tags ,
345+ [VHost , [private , replicate ], ActingUser ])),
346+ ? assertMatch ({vhost ,VHost , _ , #{tags := [private ,replicate ]}},
347+ rabbit_ct_broker_helpers :rpc (Config , 0 ,
348+ rabbit_vhost , update_tags ,
349+ [VHost , [replicate , private ], ActingUser ])),
350+
351+ Events = rabbit_ct_broker_helpers :rpc (Config , 0 ,
352+ gen_event , call ,
353+ [rabbit_event , test_rabbit_event_handler , events , 100 ]),
354+ ct :pal (? LOW_IMPORTANCE , " Events: ~p " , [lists :reverse (Events )]),
355+ TagsSetEvents = lists :filter (fun
356+ (# event {type = vhost_tags_set }) -> true ;
357+ (_ ) -> false
358+ end , Events ),
359+ ? assertMatch ([# event {type = vhost_tags_set ,
360+ props = [{name , VHost },
361+ {tags , [private , replicate ]},
362+ {user_who_performed_action , ActingUser }]}],
363+ TagsSetEvents )
364+ after
365+ rabbit_ct_broker_helpers :rpc (Config , 0 ,
366+ gen_event , delete_handler , [rabbit_event , test_rabbit_event_handler , []]),
367+ rabbit_ct_broker_helpers :delete_vhost (Config , VHost )
368+ end .
369+
370+ vhost_is_created_with_default_limits (Config ) ->
371+ VHost = <<" vhost1" >>,
372+ Limits = [{<<" max-connections" >>, 10 }, {<<" max-queues" >>, 1 }],
373+ Pattern = [{<<" pattern" >>, " .*" }],
374+ Env = [{vhosts , [{<<" id" >>, Limits ++ Pattern }]}],
375+ ? assertEqual (ok , rabbit_ct_broker_helpers :rpc (Config , 0 ,
376+ application , set_env , [rabbit , default_limits , Env ])),
377+ ? assertEqual (ok , rabbit_ct_broker_helpers :add_vhost (Config , VHost )),
378+ ? assertEqual (Limits , rabbit_ct_broker_helpers :rpc (Config , 0 ,
379+ rabbit_vhost_limit , list , [VHost ])).
380+
381+ vhost_is_created_with_operator_policies (Config ) ->
382+ VHost = <<" vhost1" >>,
383+ PolicyName = <<" default-operator-policy" >>,
384+ Definition = [{<<" expires" >>, 10 }],
385+ Env = [{operator , [{PolicyName , Definition }]}],
386+ ? assertEqual (ok , rabbit_ct_broker_helpers :rpc (Config , 0 ,
387+ application , set_env , [rabbit , default_policies , Env ])),
388+ ? assertEqual (ok , rabbit_ct_broker_helpers :add_vhost (Config , VHost )),
389+ ? assertNotEqual (not_found , rabbit_ct_broker_helpers :rpc (Config , 0 ,
390+ rabbit_policy , lookup_op , [VHost , PolicyName ])).
391+
322392parse_tags (Config ) ->
323393 rabbit_ct_broker_helpers :rpc (Config , 0 , ? MODULE , parse_tags1 , [Config ]).
324394
0 commit comments