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