blob: daae7ce70b37741a43fad231bfdc294e0dea1488 [file] [log] [blame]
Oleksii Zhurbae592ed12018-06-21 18:01:09 -05001from cvp_checks import utils
2
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
9 rabbitmq_pillar_data = local_salt_client.cmd(
10 'rabbitmq:server', 'pillar.data',
11 ['rabbitmq:cluster'], expr_form='pillar')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000012 # creating dictionary {node:cluster_size_for_the_node}
13 # with required cluster size for each node
14 control_dict = {}
15 required_cluster_size_dict = {}
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000016 # request actual data from rmq nodes
17 rabbit_actual_data = local_salt_client.cmd(
18 'rabbitmq:server', 'cmd.run',
19 ['rabbitmqctl cluster_status'], expr_form='pillar')
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050020 for node in rabbitmq_pillar_data:
21 if node in config.get('skipped_nodes'):
22 del rabbit_actual_data[node]
23 continue
24 cluster_size_from_the_node = len(
25 rabbitmq_pillar_data[node]['rabbitmq:cluster']['members'])
26 required_cluster_size_dict.update({node: cluster_size_from_the_node})
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000027
28 # find actual cluster size for each node
29 for node in rabbit_actual_data:
30 running_nodes_count = 0
Oleksii Zhurba3e06b622018-01-16 18:43:16 +000031 # rabbitmqctl cluster_status output contains
32 # 3 * # of nodes 'rabbit@' entries + 1
33 running_nodes_count = (rabbit_actual_data[node].count('rabbit@') - 1)/3
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000034 # update control dictionary with values
35 # {node:actual_cluster_size_for_node}
36 if required_cluster_size_dict[node] != running_nodes_count:
37 control_dict.update({node: running_nodes_count})
38
39 assert not len(control_dict), "Inconsistency found within cloud. " \
40 "RabbitMQ cluster is probably broken, " \
41 "the cluster size for each node " \
42 "should be: {} but the following " \
43 "nodes has other values: {}".format(
44 len(required_cluster_size_dict.keys()), control_dict)