blob: ee621ccae129ac907d336a16cc342bd756d7cb05 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03003import utils
Hanna Arhipova1eef8312019-05-06 20:14:18 +03004import logging
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00005
Hanna Arhipova0dabf662019-03-27 22:30:25 +02006# Some nodes can have services that are not applicable for other nodes in similar group.
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +02007# 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 Arhipova51027502019-02-05 17:58:44 +020010inconsistency_rule = {"kvm03": ["srv-volumes-backup.mount", "rsync"]}
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020011
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000012
Oleksii Zhurba23c18332019-05-09 18:53:40 -050013@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050014def test_check_services(local_salt_client, nodes_in_group):
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020015 """
16 Skips services if they are not consistent for all node.
17 Inconsistent services will be checked with another test case
18 """
Hanna Arhipova7e5286b2019-03-07 13:46:43 +020019 exclude_services = utils.get_configuration().get("skipped_services", [])
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030020 services_by_nodes = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
21 fun='service.get_all',
22 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000023
Hanna Arhipova0dabf662019-03-27 22:30:25 +020024 if len(services_by_nodes.keys()) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000025 pytest.skip("Nothing to compare - only 1 node")
26
Oleksii Zhurbaa3e79ce2019-06-04 17:26:51 -050027 # 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 os_octavia = local_salt_client.pillar_get(
35 param='_param:openstack_octavia_enabled')
36 octavia_man_cl = local_salt_client.pillar_get(
37 param='_param:octavia_manager_cluster')
38 if os_octavia and not octavia_man_cl and gtw01 in services_by_nodes.keys():
39 services_by_nodes.pop(gtw01)
40 logging.info("gtw01 node is skipped in test_check_services")
41
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000042 nodes = []
43 pkts_data = []
Hanna Arhipova0dabf662019-03-27 22:30:25 +020044 all_services = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000045
Hanna Arhipova0dabf662019-03-27 22:30:25 +020046 for node in services_by_nodes:
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030047 if not services_by_nodes[node]:
48 # TODO: do not skip node
Hanna Arhipova1eef8312019-05-06 20:14:18 +030049 logging.info("Node {} is skipped".format (node))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030050 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000051 nodes.append(node)
Hanna Arhipova0dabf662019-03-27 22:30:25 +020052 all_services.update(services_by_nodes[node])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000053
Hanna Arhipova0dabf662019-03-27 22:30:25 +020054 for srv in all_services:
55 if srv in exclude_services:
56 continue
57 service_existence = dict()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000058 for node in nodes:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020059 short_name_of_node = node.split('.')[0]
60 if inconsistency_rule.get(short_name_of_node) is not None and srv in inconsistency_rule[short_name_of_node]:
Hanna Arhipova0dabf662019-03-27 22:30:25 +020061 # Skip the checking of some service on the specific node
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020062 break
Hanna Arhipova0dabf662019-03-27 22:30:25 +020063 elif srv in services_by_nodes[node]:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020064 # Found service on node
Hanna Arhipova0dabf662019-03-27 22:30:25 +020065 service_existence[node] = "+"
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000066 else:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020067 # Not found expected service on node
Hanna Arhipova0dabf662019-03-27 22:30:25 +020068 service_existence[node] = "No service"
69 if set(service_existence.values()).__len__() > 1:
70 report = ["{node}: {status}".format(node=node, status=status) for node, status in service_existence.items()]
71 report.sort()
72 report.insert(0, srv)
73 pkts_data.append(report)
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020074 assert len(pkts_data) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050075 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050076 json.dumps(pkts_data, indent=4))
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020077
78
79# TODO : remake this test to make workable https://mirantis.jira.com/browse/PROD-25958
80
81# def _check_services_on_special_node(local_salt_client, nodes_in_group):
82# """
83# Check that specific node has service.
84# Nodes and proper services should be defined in inconsistency_rule dictionary
85#
86# :print: Table with nodes which don't have required services and not existed services
87# """
88#
89# output = local_salt_client.cmd("L@" + ','.join(nodes_in_group), 'service.get_all', expr_form='compound')
90# if len(output.keys()) < 2:
91# pytest.skip("Nothing to compare - just 1 node")
92#
93# def is_proper_service_for_node(_service, _node):
94# """
95# Return True if service exists on node and exists in inconsistency_rule
96# Return True if service doesn't exists on node and doesn't exists in inconsistency_rule
97# Return False otherwise
98# :param _service: string
99# :param _node: string full name of node
100# :return: bool, read description for further details
101# """
102# short_name_of_node = _node.split('.')[0]
103# if short_name_of_node not in inconsistency_rule.keys():
104# return False
105#
106# if _service in inconsistency_rule[short_name_of_node] and \
107# _service in output[_node]:
108# # Return True if service exists on node and exists in inconsistency_rule
109# return True
110#
111# if _service not in inconsistency_rule[short_name_of_node] and \
112# _service not in output[_node]:
113# # Return True if service exists on node and exists in inconsistency_rule
114# return True
115# print("return False for {} in {}".format(_service, _node))
116# # error_text = ""
117# return False
118#
119# errors = list()
120# for node, expected_services in inconsistency_rule.items():
121# print("Check {} , {} ".format(node, expected_services))
122# # Skip if there is no proper node. Find nodes that contains node_title (like 'kvm03') in their titles
123# if not any([node in node_name for node_name in output.keys()]):
124# continue
125# for expected_service in expected_services:
126# service_on_nodes = {_node: expected_service if expected_service in _service else None
127# for _node, _service
128# in output.items()}
129# print([is_proper_service_for_node(expected_service, _node)
130# for _node
131# in output.keys()])
132# if not all([is_proper_service_for_node(expected_service, _node)
133# for _node
134# in output.keys()]):
135# errors.append(service_on_nodes)
136#
137# assert errors.__len__() == 0, json.dumps(errors, indent=4)
138# assert False