Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import pytest |
| 2 | import json |
Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame] | 3 | import utils |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 4 | import logging |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 5 | |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 6 | # Some nodes can have services that are not applicable for other nodes in similar group. |
Hanna Arhipova | feebf9e | 2018-12-24 12:45:54 +0200 | [diff] [blame] | 7 | # For example , there are 3 node in kvm group, but just kvm03 node has srv-volumes-backup.mount service |
| 8 | # in service.get_all |
| 9 | # NODE NAME SERVICE_NAME |
Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame] | 10 | inconsistency_rule = {"kvm03": ["srv-volumes-backup.mount", "rsync"]} |
Hanna Arhipova | feebf9e | 2018-12-24 12:45:54 +0200 | [diff] [blame] | 11 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 12 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 13 | @pytest.mark.full |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 14 | def test_check_services(local_salt_client, nodes_in_group): |
Hanna Arhipova | feebf9e | 2018-12-24 12:45:54 +0200 | [diff] [blame] | 15 | """ |
| 16 | Skips services if they are not consistent for all node. |
| 17 | Inconsistent services will be checked with another test case |
| 18 | """ |
Oleksii Zhurba | dd17609 | 2019-04-26 15:29:10 -0500 | [diff] [blame] | 19 | exclude_services = utils.get_configuration().get("skipped_services", []) |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 20 | services_by_nodes = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group), |
| 21 | fun='service.get_all', |
| 22 | expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 23 | |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 24 | if len(services_by_nodes.keys()) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 25 | pytest.skip("Nothing to compare - only 1 node") |
| 26 | |
Oleksii Zhurba | 599801a | 2019-06-04 17:26:51 -0500 | [diff] [blame^] | 27 | # PROD-30833 |
| 28 | gtw01 = local_salt_client.pillar_get( |
| 29 | param='_param:openstack_gateway_node01_hostname') or 'gtw01' |
| 30 | cluster_domain = local_salt_client.pillar_get( |
| 31 | param='_param:cluster_domain') or '.local' |
| 32 | gtw01 += '.' + cluster_domain |
| 33 | if gtw01 in nodes_in_group: |
| 34 | octavia = local_salt_client.cmd(tgt="L@" + ','.join(nodes_in_group), |
| 35 | fun='pillar.get', |
| 36 | param='octavia:manager:enabled', |
| 37 | expr_form='compound') |
| 38 | gtws = [gtw for gtw in octavia.values() if gtw] |
| 39 | if len(gtws) == 1 and gtw01 in services_by_nodes.keys(): |
| 40 | services_by_nodes.pop(gtw01) |
| 41 | logging.info("gtw01 node is skipped in test_check_services") |
| 42 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 43 | nodes = [] |
| 44 | pkts_data = [] |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 45 | all_services = set() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 46 | |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 47 | for node in services_by_nodes: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 48 | if not services_by_nodes[node]: |
| 49 | # TODO: do not skip node |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 50 | logging.info("Node {} is skipped".format (node)) |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 51 | continue |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 52 | nodes.append(node) |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 53 | all_services.update(services_by_nodes[node]) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 54 | |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 55 | for srv in all_services: |
Hanna Arhipova | 8fd295c | 2019-03-07 13:46:43 +0200 | [diff] [blame] | 56 | if srv in exclude_services: |
| 57 | continue |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 58 | service_existence = dict() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 59 | for node in nodes: |
Hanna Arhipova | feebf9e | 2018-12-24 12:45:54 +0200 | [diff] [blame] | 60 | short_name_of_node = node.split('.')[0] |
| 61 | if inconsistency_rule.get(short_name_of_node) is not None and srv in inconsistency_rule[short_name_of_node]: |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 62 | # Skip the checking of some service on the specific node |
Hanna Arhipova | feebf9e | 2018-12-24 12:45:54 +0200 | [diff] [blame] | 63 | break |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 64 | elif srv in services_by_nodes[node]: |
Hanna Arhipova | feebf9e | 2018-12-24 12:45:54 +0200 | [diff] [blame] | 65 | # Found service on node |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 66 | service_existence[node] = "+" |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 67 | else: |
Hanna Arhipova | feebf9e | 2018-12-24 12:45:54 +0200 | [diff] [blame] | 68 | # Not found expected service on node |
Hanna Arhipova | ab91964 | 2019-03-27 20:05:38 +0200 | [diff] [blame] | 69 | service_existence[node] = "No service" |
| 70 | if set(service_existence.values()).__len__() > 1: |
| 71 | report = ["{node}: {status}".format(node=node, status=status) for node, status in service_existence.items()] |
| 72 | report.sort() |
| 73 | report.insert(0, srv) |
| 74 | pkts_data.append(report) |
Hanna Arhipova | feebf9e | 2018-12-24 12:45:54 +0200 | [diff] [blame] | 75 | assert len(pkts_data) == 0, \ |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 76 | "Several problems found: {0}".format( |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 77 | json.dumps(pkts_data, indent=4)) |
Hanna Arhipova | feebf9e | 2018-12-24 12:45:54 +0200 | [diff] [blame] | 78 | |
| 79 | |
| 80 | # TODO : remake this test to make workable https://mirantis.jira.com/browse/PROD-25958 |
| 81 | |
| 82 | # def _check_services_on_special_node(local_salt_client, nodes_in_group): |
| 83 | # """ |
| 84 | # Check that specific node has service. |
| 85 | # Nodes and proper services should be defined in inconsistency_rule dictionary |
| 86 | # |
| 87 | # :print: Table with nodes which don't have required services and not existed services |
| 88 | # """ |
| 89 | # |
| 90 | # output = local_salt_client.cmd("L@" + ','.join(nodes_in_group), 'service.get_all', expr_form='compound') |
| 91 | # if len(output.keys()) < 2: |
| 92 | # pytest.skip("Nothing to compare - just 1 node") |
| 93 | # |
| 94 | # def is_proper_service_for_node(_service, _node): |
| 95 | # """ |
| 96 | # Return True if service exists on node and exists in inconsistency_rule |
| 97 | # Return True if service doesn't exists on node and doesn't exists in inconsistency_rule |
| 98 | # Return False otherwise |
| 99 | # :param _service: string |
| 100 | # :param _node: string full name of node |
| 101 | # :return: bool, read description for further details |
| 102 | # """ |
| 103 | # short_name_of_node = _node.split('.')[0] |
| 104 | # if short_name_of_node not in inconsistency_rule.keys(): |
| 105 | # return False |
| 106 | # |
| 107 | # if _service in inconsistency_rule[short_name_of_node] and \ |
| 108 | # _service in output[_node]: |
| 109 | # # Return True if service exists on node and exists in inconsistency_rule |
| 110 | # return True |
| 111 | # |
| 112 | # if _service not in inconsistency_rule[short_name_of_node] and \ |
| 113 | # _service not in output[_node]: |
| 114 | # # Return True if service exists on node and exists in inconsistency_rule |
| 115 | # return True |
| 116 | # print("return False for {} in {}".format(_service, _node)) |
| 117 | # # error_text = "" |
| 118 | # return False |
| 119 | # |
| 120 | # errors = list() |
| 121 | # for node, expected_services in inconsistency_rule.items(): |
| 122 | # print("Check {} , {} ".format(node, expected_services)) |
| 123 | # # Skip if there is no proper node. Find nodes that contains node_title (like 'kvm03') in their titles |
| 124 | # if not any([node in node_name for node_name in output.keys()]): |
| 125 | # continue |
| 126 | # for expected_service in expected_services: |
| 127 | # service_on_nodes = {_node: expected_service if expected_service in _service else None |
| 128 | # for _node, _service |
| 129 | # in output.items()} |
| 130 | # print([is_proper_service_for_node(expected_service, _node) |
| 131 | # for _node |
| 132 | # in output.keys()]) |
| 133 | # if not all([is_proper_service_for_node(expected_service, _node) |
| 134 | # for _node |
| 135 | # in output.keys()]): |
| 136 | # errors.append(service_on_nodes) |
| 137 | # |
| 138 | # assert errors.__len__() == 0, json.dumps(errors, indent=4) |
| 139 | # assert False |