blob: fac31e59797195db264176cb96d0b27e27b1d529 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Hanna Arhipova16e93fb2019-01-23 19:03:01 +02003import utils
Hanna Arhipova56eab942019-05-06 20:14:18 +03004import logging
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00005
Hanna Arhipovaab919642019-03-27 20:05:38 +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 Arhipova16e93fb2019-01-23 19:03:01 +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 Zhurba5b15b9b2019-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 """
Oleksii Zhurbadd176092019-04-26 15:29:10 -050019 exclude_services = utils.get_configuration().get("skipped_services", [])
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050020 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 Arhipovaab919642019-03-27 20:05:38 +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
27 nodes = []
28 pkts_data = []
Hanna Arhipovaab919642019-03-27 20:05:38 +020029 all_services = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000030
Hanna Arhipovaab919642019-03-27 20:05:38 +020031 for node in services_by_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050032 if not services_by_nodes[node]:
33 # TODO: do not skip node
Hanna Arhipova56eab942019-05-06 20:14:18 +030034 logging.info("Node {} is skipped".format (node))
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050035 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000036 nodes.append(node)
Hanna Arhipovaab919642019-03-27 20:05:38 +020037 all_services.update(services_by_nodes[node])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000038
Hanna Arhipovaab919642019-03-27 20:05:38 +020039 for srv in all_services:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020040 if srv in exclude_services:
41 continue
Hanna Arhipovaab919642019-03-27 20:05:38 +020042 service_existence = dict()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000043 for node in nodes:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020044 short_name_of_node = node.split('.')[0]
45 if inconsistency_rule.get(short_name_of_node) is not None and srv in inconsistency_rule[short_name_of_node]:
Hanna Arhipovaab919642019-03-27 20:05:38 +020046 # Skip the checking of some service on the specific node
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020047 break
Hanna Arhipovaab919642019-03-27 20:05:38 +020048 elif srv in services_by_nodes[node]:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020049 # Found service on node
Hanna Arhipovaab919642019-03-27 20:05:38 +020050 service_existence[node] = "+"
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000051 else:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020052 # Not found expected service on node
Hanna Arhipovaab919642019-03-27 20:05:38 +020053 service_existence[node] = "No service"
54 if set(service_existence.values()).__len__() > 1:
55 report = ["{node}: {status}".format(node=node, status=status) for node, status in service_existence.items()]
56 report.sort()
57 report.insert(0, srv)
58 pkts_data.append(report)
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020059 assert len(pkts_data) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050060 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050061 json.dumps(pkts_data, indent=4))
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020062
63
64# TODO : remake this test to make workable https://mirantis.jira.com/browse/PROD-25958
65
66# def _check_services_on_special_node(local_salt_client, nodes_in_group):
67# """
68# Check that specific node has service.
69# Nodes and proper services should be defined in inconsistency_rule dictionary
70#
71# :print: Table with nodes which don't have required services and not existed services
72# """
73#
74# output = local_salt_client.cmd("L@" + ','.join(nodes_in_group), 'service.get_all', expr_form='compound')
75# if len(output.keys()) < 2:
76# pytest.skip("Nothing to compare - just 1 node")
77#
78# def is_proper_service_for_node(_service, _node):
79# """
80# Return True if service exists on node and exists in inconsistency_rule
81# Return True if service doesn't exists on node and doesn't exists in inconsistency_rule
82# Return False otherwise
83# :param _service: string
84# :param _node: string full name of node
85# :return: bool, read description for further details
86# """
87# short_name_of_node = _node.split('.')[0]
88# if short_name_of_node not in inconsistency_rule.keys():
89# return False
90#
91# if _service in inconsistency_rule[short_name_of_node] and \
92# _service in output[_node]:
93# # Return True if service exists on node and exists in inconsistency_rule
94# return True
95#
96# if _service not in inconsistency_rule[short_name_of_node] and \
97# _service not in output[_node]:
98# # Return True if service exists on node and exists in inconsistency_rule
99# return True
100# print("return False for {} in {}".format(_service, _node))
101# # error_text = ""
102# return False
103#
104# errors = list()
105# for node, expected_services in inconsistency_rule.items():
106# print("Check {} , {} ".format(node, expected_services))
107# # Skip if there is no proper node. Find nodes that contains node_title (like 'kvm03') in their titles
108# if not any([node in node_name for node_name in output.keys()]):
109# continue
110# for expected_service in expected_services:
111# service_on_nodes = {_node: expected_service if expected_service in _service else None
112# for _node, _service
113# in output.items()}
114# print([is_proper_service_for_node(expected_service, _node)
115# for _node
116# in output.keys()])
117# if not all([is_proper_service_for_node(expected_service, _node)
118# for _node
119# in output.keys()]):
120# errors.append(service_on_nodes)
121#
122# assert errors.__len__() == 0, json.dumps(errors, indent=4)
123# assert False