blob: da5ca3fb84597c74d59fe51dc6263ff7ecb6b9c2 [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
Denis V. Meltsaykin2d354f02020-04-29 12:23:21 +02006# RabbitmqServiceDown, RabbitmqErrorLogsTooHigh
7# TODO: a better test
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -05008@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 = {}
Denis V. Meltsaykin2d354f02020-04-29 12:23:21 +020024
25 # check rabbitmq version
26 version_data = local_salt_client.cmd(
27 tgt='I@rabbitmq:server',
28 fun='pkg.version',
29 param='rabbitmq-server',
30 expr_form='compound'
31 )
32
33 rabbitmq_versions = set(version_data.values())
34
35 assert len(rabbitmq_versions) == 1, (
36 "Non-matching RabbitMQ versions installed:{}".format(version_data)
37 )
38
39 rabbitmq_version = rabbitmq_versions.pop()
40
41 # check if the installed RabbitMQ is 3.8
42 newer_rabbit = int(local_salt_client.cmd(
43 tgt='I@salt:master',
44 fun='pkg.version_cmp',
45 param=['{}'.format(rabbitmq_version), '3.8'],
46 expr_form='compound'
47 ).popitem()[1]) >= 0
48
49 suffix = ' --formatter erlang' if newer_rabbit else ''
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000050 # request actual data from rmq nodes
51 rabbit_actual_data = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050052 tgt='rabbitmq:server',
Denis V. Meltsaykin2d354f02020-04-29 12:23:21 +020053 param=r'rabbitmqctl cluster_status{} '
54 r'| grep "nodes,\|running_nodes"'.format(suffix),
55 expr_form='pillar'
56 )
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050057 for node in rabbitmq_pillar_data:
58 if node in config.get('skipped_nodes'):
59 del rabbit_actual_data[node]
60 continue
61 cluster_size_from_the_node = len(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050062 rabbitmq_pillar_data[node]['members'])
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050063 required_cluster_size_dict.update({node: cluster_size_from_the_node})
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000064
65 # find actual cluster size for each node
66 for node in rabbit_actual_data:
67 running_nodes_count = 0
Oleksii Zhurba3e06b622018-01-16 18:43:16 +000068 # rabbitmqctl cluster_status output contains
Denis V. Meltsaykin2d354f02020-04-29 12:23:21 +020069 # 2 * # of nodes 'rabbit@' entries
70 running_nodes_count = rabbit_actual_data[node].count('rabbit@') // 2
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000071 # update control dictionary with values
72 # {node:actual_cluster_size_for_node}
73 if required_cluster_size_dict[node] != running_nodes_count:
74 control_dict.update({node: running_nodes_count})
75
Denis V. Meltsaykin2d354f02020-04-29 12:23:21 +020076 assert len(control_dict) == 0, (
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020077 "RabbitMQ cluster is probably "
78 "broken - the cluster size for each node should be ({}),\nbut the "
79 "following nodes have other values:\n{}".format(
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030080 len(list(required_cluster_size_dict.keys())), control_dict)
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020081 )