blob: 4f7f61350c7d608aa7697610c1da8beee14e0f5d [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +00003import os
Hanna Arhipova16e93fb2019-01-23 19:03:01 +02004import utils
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 Zhurbad0ae87f2018-03-26 13:36:25 -050013def test_check_services(local_salt_client, nodes_in_group):
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020014 """
15 Skips services if they are not consistent for all node.
16 Inconsistent services will be checked with another test case
17 """
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020018 exclude_services = utils.get_configuration().get("exclude_services", [])
Hanna Arhipovaab919642019-03-27 20:05:38 +020019 services_by_nodes = local_salt_client.cmd("L@"+','.join(nodes_in_group), 'service.get_all', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000020
Hanna Arhipovaab919642019-03-27 20:05:38 +020021 if len(services_by_nodes.keys()) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000022 pytest.skip("Nothing to compare - only 1 node")
23
24 nodes = []
25 pkts_data = []
Hanna Arhipovaab919642019-03-27 20:05:38 +020026 all_services = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000027
Hanna Arhipovaab919642019-03-27 20:05:38 +020028 for node in services_by_nodes:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000029 nodes.append(node)
Hanna Arhipovaab919642019-03-27 20:05:38 +020030 all_services.update(services_by_nodes[node])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000031
Hanna Arhipovaab919642019-03-27 20:05:38 +020032 for srv in all_services:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020033 if srv in exclude_services:
34 continue
Hanna Arhipovaab919642019-03-27 20:05:38 +020035 service_existence = dict()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000036 for node in nodes:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020037 short_name_of_node = node.split('.')[0]
38 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 +020039 # Skip the checking of some service on the specific node
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020040 break
Hanna Arhipovaab919642019-03-27 20:05:38 +020041 elif srv in services_by_nodes[node]:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020042 # Found service on node
Hanna Arhipovaab919642019-03-27 20:05:38 +020043 service_existence[node] = "+"
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000044 else:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020045 # Not found expected service on node
Hanna Arhipovaab919642019-03-27 20:05:38 +020046 service_existence[node] = "No service"
47 if set(service_existence.values()).__len__() > 1:
48 report = ["{node}: {status}".format(node=node, status=status) for node, status in service_existence.items()]
49 report.sort()
50 report.insert(0, srv)
51 pkts_data.append(report)
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020052 assert len(pkts_data) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050053 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050054 json.dumps(pkts_data, indent=4))
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020055
56
57# TODO : remake this test to make workable https://mirantis.jira.com/browse/PROD-25958
58
59# def _check_services_on_special_node(local_salt_client, nodes_in_group):
60# """
61# Check that specific node has service.
62# Nodes and proper services should be defined in inconsistency_rule dictionary
63#
64# :print: Table with nodes which don't have required services and not existed services
65# """
66#
67# output = local_salt_client.cmd("L@" + ','.join(nodes_in_group), 'service.get_all', expr_form='compound')
68# if len(output.keys()) < 2:
69# pytest.skip("Nothing to compare - just 1 node")
70#
71# def is_proper_service_for_node(_service, _node):
72# """
73# Return True if service exists on node and exists in inconsistency_rule
74# Return True if service doesn't exists on node and doesn't exists in inconsistency_rule
75# Return False otherwise
76# :param _service: string
77# :param _node: string full name of node
78# :return: bool, read description for further details
79# """
80# short_name_of_node = _node.split('.')[0]
81# if short_name_of_node not in inconsistency_rule.keys():
82# return False
83#
84# if _service in inconsistency_rule[short_name_of_node] and \
85# _service in output[_node]:
86# # Return True if service exists on node and exists in inconsistency_rule
87# return True
88#
89# if _service not in inconsistency_rule[short_name_of_node] and \
90# _service not in output[_node]:
91# # Return True if service exists on node and exists in inconsistency_rule
92# return True
93# print("return False for {} in {}".format(_service, _node))
94# # error_text = ""
95# return False
96#
97# errors = list()
98# for node, expected_services in inconsistency_rule.items():
99# print("Check {} , {} ".format(node, expected_services))
100# # Skip if there is no proper node. Find nodes that contains node_title (like 'kvm03') in their titles
101# if not any([node in node_name for node_name in output.keys()]):
102# continue
103# for expected_service in expected_services:
104# service_on_nodes = {_node: expected_service if expected_service in _service else None
105# for _node, _service
106# in output.items()}
107# print([is_proper_service_for_node(expected_service, _node)
108# for _node
109# in output.keys()])
110# if not all([is_proper_service_for_node(expected_service, _node)
111# for _node
112# in output.keys()]):
113# errors.append(service_on_nodes)
114#
115# assert errors.__len__() == 0, json.dumps(errors, indent=4)
116# assert False