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