Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame] | 1 | import utils |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 2 | |
| 3 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 4 | def test_checking_rabbitmq_cluster(local_salt_client): |
| 5 | # disable config for this test |
| 6 | # it may be reintroduced in future |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 7 | config = utils.get_configuration() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 8 | # request pillar data from rmq nodes |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame^] | 9 | # TODO: pillar.get |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 10 | rabbitmq_pillar_data = local_salt_client.cmd( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame^] | 11 | tgt='rabbitmq:server', |
| 12 | fun='pillar.get', |
| 13 | param='rabbitmq:cluster', |
| 14 | expr_form='pillar') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 15 | # creating dictionary {node:cluster_size_for_the_node} |
| 16 | # with required cluster size for each node |
| 17 | control_dict = {} |
| 18 | required_cluster_size_dict = {} |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 19 | # request actual data from rmq nodes |
| 20 | rabbit_actual_data = local_salt_client.cmd( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame^] | 21 | tgt='rabbitmq:server', |
| 22 | param='rabbitmqctl cluster_status', expr_form='pillar') |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 23 | for node in rabbitmq_pillar_data: |
| 24 | if node in config.get('skipped_nodes'): |
| 25 | del rabbit_actual_data[node] |
| 26 | continue |
| 27 | cluster_size_from_the_node = len( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame^] | 28 | rabbitmq_pillar_data[node]['members']) |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 29 | required_cluster_size_dict.update({node: cluster_size_from_the_node}) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 30 | |
| 31 | # find actual cluster size for each node |
| 32 | for node in rabbit_actual_data: |
| 33 | running_nodes_count = 0 |
Oleksii Zhurba | 3e06b62 | 2018-01-16 18:43:16 +0000 | [diff] [blame] | 34 | # rabbitmqctl cluster_status output contains |
| 35 | # 3 * # of nodes 'rabbit@' entries + 1 |
| 36 | running_nodes_count = (rabbit_actual_data[node].count('rabbit@') - 1)/3 |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 37 | # update control dictionary with values |
| 38 | # {node:actual_cluster_size_for_node} |
| 39 | if required_cluster_size_dict[node] != running_nodes_count: |
| 40 | control_dict.update({node: running_nodes_count}) |
| 41 | |
| 42 | assert not len(control_dict), "Inconsistency found within cloud. " \ |
| 43 | "RabbitMQ cluster is probably broken, " \ |
| 44 | "the cluster size for each node " \ |
| 45 | "should be: {} but the following " \ |
| 46 | "nodes has other values: {}".format( |
| 47 | len(required_cluster_size_dict.keys()), control_dict) |