blob: acd4a9699958b6c3e091bdd7f4bb46106e6d9ae8 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001def test_checking_rabbitmq_cluster(local_salt_client):
2 # disable config for this test
3 # it may be reintroduced in future
4 # config = utils.get_configuration(__file__)
5 # request pillar data from rmq nodes
6 rabbitmq_pillar_data = local_salt_client.cmd(
7 'rabbitmq:server', 'pillar.data',
8 ['rabbitmq:cluster'], expr_form='pillar')
9
10 # creating dictionary {node:cluster_size_for_the_node}
11 # with required cluster size for each node
12 control_dict = {}
13 required_cluster_size_dict = {}
14 for node in rabbitmq_pillar_data:
15 cluster_size_from_the_node = len(
16 rabbitmq_pillar_data[node]['rabbitmq:cluster']['members'])
17 required_cluster_size_dict.update({node: cluster_size_from_the_node})
18
19 # request actual data from rmq nodes
20 rabbit_actual_data = local_salt_client.cmd(
21 'rabbitmq:server', 'cmd.run',
22 ['rabbitmqctl cluster_status'], expr_form='pillar')
23
24 # find actual cluster size for each node
25 for node in rabbit_actual_data:
26 running_nodes_count = 0
27 for line in rabbit_actual_data[node].split('\n'):
28 if 'running_nodes' in line:
29 running_nodes_count = line.count('rabbit@')
30 # update control dictionary with values
31 # {node:actual_cluster_size_for_node}
32 if required_cluster_size_dict[node] != running_nodes_count:
33 control_dict.update({node: running_nodes_count})
34
35 assert not len(control_dict), "Inconsistency found within cloud. " \
36 "RabbitMQ cluster is probably broken, " \
37 "the cluster size for each node " \
38 "should be: {} but the following " \
39 "nodes has other values: {}".format(
40 len(required_cluster_size_dict.keys()), control_dict)