blob: cd18bafc197659f97794f4bfa27e45651fd8d19f [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')
Denis V. Meltsaykin1d68b2e2021-01-28 11:11:22 +010020 # skip the test if there is no cluster data in pillars
21 if sum([len(v) for v in rabbitmq_pillar_data.values()]) == 0:
22 pytest.skip("No RabbitMQ cluster pillar available")
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000023 # creating dictionary {node:cluster_size_for_the_node}
24 # with required cluster size for each node
25 control_dict = {}
26 required_cluster_size_dict = {}
Denis V. Meltsaykin2d354f02020-04-29 12:23:21 +020027
28 # check rabbitmq version
29 version_data = local_salt_client.cmd(
30 tgt='I@rabbitmq:server',
31 fun='pkg.version',
32 param='rabbitmq-server',
33 expr_form='compound'
34 )
35
36 rabbitmq_versions = set(version_data.values())
37
38 assert len(rabbitmq_versions) == 1, (
39 "Non-matching RabbitMQ versions installed:{}".format(version_data)
40 )
41
42 rabbitmq_version = rabbitmq_versions.pop()
43
44 # check if the installed RabbitMQ is 3.8
45 newer_rabbit = int(local_salt_client.cmd(
46 tgt='I@salt:master',
47 fun='pkg.version_cmp',
48 param=['{}'.format(rabbitmq_version), '3.8'],
49 expr_form='compound'
50 ).popitem()[1]) >= 0
51
52 suffix = ' --formatter erlang' if newer_rabbit else ''
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000053 # request actual data from rmq nodes
54 rabbit_actual_data = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050055 tgt='rabbitmq:server',
Denis V. Meltsaykin2d354f02020-04-29 12:23:21 +020056 param=r'rabbitmqctl cluster_status{} '
57 r'| grep "nodes,\|running_nodes"'.format(suffix),
58 expr_form='pillar'
59 )
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050060 for node in rabbitmq_pillar_data:
61 if node in config.get('skipped_nodes'):
62 del rabbit_actual_data[node]
63 continue
64 cluster_size_from_the_node = len(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050065 rabbitmq_pillar_data[node]['members'])
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050066 required_cluster_size_dict.update({node: cluster_size_from_the_node})
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000067
68 # find actual cluster size for each node
69 for node in rabbit_actual_data:
70 running_nodes_count = 0
Oleksii Zhurba3e06b622018-01-16 18:43:16 +000071 # rabbitmqctl cluster_status output contains
Denis V. Meltsaykin2d354f02020-04-29 12:23:21 +020072 # 2 * # of nodes 'rabbit@' entries
73 running_nodes_count = rabbit_actual_data[node].count('rabbit@') // 2
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000074 # update control dictionary with values
75 # {node:actual_cluster_size_for_node}
76 if required_cluster_size_dict[node] != running_nodes_count:
77 control_dict.update({node: running_nodes_count})
78
Denis V. Meltsaykin2d354f02020-04-29 12:23:21 +020079 assert len(control_dict) == 0, (
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020080 "RabbitMQ cluster is probably "
81 "broken - the cluster size for each node should be ({}),\nbut the "
82 "following nodes have other values:\n{}".format(
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030083 len(list(required_cluster_size_dict.keys())), control_dict)
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020084 )