blob: d0bb44b72b3d86dddc3ade736365e8acd46da152 [file] [log] [blame]
Hanna Arhipova16e93fb2019-01-23 19:03:01 +02001import utils
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -05002import pytest
Oleksii Zhurbae592ed12018-06-21 18:01:09 -05003
4
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -05005@pytest.mark.sl_dup
6#RabbitmqServiceDown, RabbitmqErrorLogsTooHigh
7#TODO: a better test
8@pytest.mark.full
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00009def test_checking_rabbitmq_cluster(local_salt_client):
10 # disable config for this test
11 # it may be reintroduced in future
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050012 config = utils.get_configuration()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000013 # request pillar data from rmq nodes
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050014 # TODO: pillar.get
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000015 rabbitmq_pillar_data = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050016 tgt='rabbitmq:server',
17 fun='pillar.get',
18 param='rabbitmq:cluster',
19 expr_form='pillar')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000020 # creating dictionary {node:cluster_size_for_the_node}
21 # with required cluster size for each node
22 control_dict = {}
23 required_cluster_size_dict = {}
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000024 # request actual data from rmq nodes
25 rabbit_actual_data = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050026 tgt='rabbitmq:server',
27 param='rabbitmqctl cluster_status', expr_form='pillar')
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050028 for node in rabbitmq_pillar_data:
29 if node in config.get('skipped_nodes'):
30 del rabbit_actual_data[node]
31 continue
32 cluster_size_from_the_node = len(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050033 rabbitmq_pillar_data[node]['members'])
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050034 required_cluster_size_dict.update({node: cluster_size_from_the_node})
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000035
36 # find actual cluster size for each node
37 for node in rabbit_actual_data:
38 running_nodes_count = 0
Oleksii Zhurba3e06b622018-01-16 18:43:16 +000039 # rabbitmqctl cluster_status output contains
40 # 3 * # of nodes 'rabbit@' entries + 1
41 running_nodes_count = (rabbit_actual_data[node].count('rabbit@') - 1)/3
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000042 # update control dictionary with values
43 # {node:actual_cluster_size_for_node}
44 if required_cluster_size_dict[node] != running_nodes_count:
45 control_dict.update({node: running_nodes_count})
46
47 assert not len(control_dict), "Inconsistency found within cloud. " \
48 "RabbitMQ cluster is probably broken, " \
49 "the cluster size for each node " \
50 "should be: {} but the following " \
51 "nodes has other values: {}".format(
52 len(required_cluster_size_dict.keys()), control_dict)