Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame] | 1 | import utils |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 2 | import pytest |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 3 | |
| 4 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 5 | @pytest.mark.sl_dup |
| 6 | #RabbitmqServiceDown, RabbitmqErrorLogsTooHigh |
| 7 | #TODO: a better test |
| 8 | @pytest.mark.full |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 9 | def test_checking_rabbitmq_cluster(local_salt_client): |
| 10 | # disable config for this test |
| 11 | # it may be reintroduced in future |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 12 | config = utils.get_configuration() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 13 | # request pillar data from rmq nodes |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 14 | # TODO: pillar.get |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 15 | rabbitmq_pillar_data = local_salt_client.cmd( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 16 | tgt='rabbitmq:server', |
| 17 | fun='pillar.get', |
| 18 | param='rabbitmq:cluster', |
| 19 | expr_form='pillar') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 20 | # 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 Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 24 | # request actual data from rmq nodes |
| 25 | rabbit_actual_data = local_salt_client.cmd( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 26 | tgt='rabbitmq:server', |
| 27 | param='rabbitmqctl cluster_status', expr_form='pillar') |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 28 | 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 Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 33 | rabbitmq_pillar_data[node]['members']) |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 34 | required_cluster_size_dict.update({node: cluster_size_from_the_node}) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 35 | |
| 36 | # find actual cluster size for each node |
| 37 | for node in rabbit_actual_data: |
| 38 | running_nodes_count = 0 |
Oleksii Zhurba | 3e06b62 | 2018-01-16 18:43:16 +0000 | [diff] [blame] | 39 | # 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 Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 42 | # 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 | |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame^] | 47 | assert not len(control_dict), ( |
| 48 | "RabbitMQ cluster is probably " |
| 49 | "broken - the cluster size for each node should be ({}),\nbut the " |
| 50 | "following nodes have other values:\n{}".format( |
| 51 | len(required_cluster_size_dict.keys()), control_dict) |
| 52 | ) |