blob: 73efb57909d730d8f2fb2305367e8d76df646c33 [file] [log] [blame]
Hanna Arhipova16e93fb2019-01-23 19:03:01 +02001import utils
Oleksii Zhurbae592ed12018-06-21 18:01:09 -05002
3
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00004def test_checking_rabbitmq_cluster(local_salt_client):
5 # disable config for this test
6 # it may be reintroduced in future
Oleksii Zhurbae592ed12018-06-21 18:01:09 -05007 config = utils.get_configuration()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00008 # request pillar data from rmq nodes
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -05009 # TODO: pillar.get
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000010 rabbitmq_pillar_data = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050011 tgt='rabbitmq:server',
12 fun='pillar.get',
13 param='rabbitmq:cluster',
14 expr_form='pillar')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000015 # creating dictionary {node:cluster_size_for_the_node}
16 # with required cluster size for each node
17 control_dict = {}
18 required_cluster_size_dict = {}
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000019 # request actual data from rmq nodes
20 rabbit_actual_data = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050021 tgt='rabbitmq:server',
22 param='rabbitmqctl cluster_status', expr_form='pillar')
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050023 for node in rabbitmq_pillar_data:
24 if node in config.get('skipped_nodes'):
25 del rabbit_actual_data[node]
26 continue
27 cluster_size_from_the_node = len(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050028 rabbitmq_pillar_data[node]['members'])
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050029 required_cluster_size_dict.update({node: cluster_size_from_the_node})
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000030
31 # find actual cluster size for each node
32 for node in rabbit_actual_data:
33 running_nodes_count = 0
Oleksii Zhurba3e06b622018-01-16 18:43:16 +000034 # rabbitmqctl cluster_status output contains
35 # 3 * # of nodes 'rabbit@' entries + 1
36 running_nodes_count = (rabbit_actual_data[node].count('rabbit@') - 1)/3
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000037 # update control dictionary with values
38 # {node:actual_cluster_size_for_node}
39 if required_cluster_size_dict[node] != running_nodes_count:
40 control_dict.update({node: running_nodes_count})
41
42 assert not len(control_dict), "Inconsistency found within cloud. " \
43 "RabbitMQ cluster is probably broken, " \
44 "the cluster size for each node " \
45 "should be: {} but the following " \
46 "nodes has other values: {}".format(
47 len(required_cluster_size_dict.keys()), control_dict)