blob: da858518adae54c5720bbd9ae27d8b9483e4e0d5 [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 Arhipovafeebf9e2018-12-24 12:45:54 +02006# Some nodes can have services that are not applicable for other noder in similar group.
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 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", [])
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050019 output = local_salt_client.cmd("L@"+','.join(nodes_in_group), 'service.get_all', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000020
21 if len(output.keys()) < 2:
22 pytest.skip("Nothing to compare - only 1 node")
23
24 nodes = []
25 pkts_data = []
26 my_set = set()
27
28 for node in output:
29 nodes.append(node)
30 my_set.update(output[node])
31
32 for srv in my_set:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020033 if srv in exclude_services:
34 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000035 diff = []
36 row = []
37 for node in nodes:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020038 short_name_of_node = node.split('.')[0]
39 if inconsistency_rule.get(short_name_of_node) is not None and srv in inconsistency_rule[short_name_of_node]:
40 # Found service on node and it SHOULD be there
41 break
42 elif srv in output[node]:
43 # Found service on node
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000044 diff.append(srv)
45 row.append("{}: +".format(node))
46 else:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020047 # Not found expected service on node
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000048 row.append("{}: No service".format(node))
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020049 if diff.__len__() > 0 and diff.count(diff[0]) < len(nodes):
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000050 row.sort()
51 row.insert(0, srv)
52 pkts_data.append(row)
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020053 assert len(pkts_data) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050054 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050055 json.dumps(pkts_data, indent=4))
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020056
57
58# TODO : remake this test to make workable https://mirantis.jira.com/browse/PROD-25958
59
60# def _check_services_on_special_node(local_salt_client, nodes_in_group):
61# """
62# Check that specific node has service.
63# Nodes and proper services should be defined in inconsistency_rule dictionary
64#
65# :print: Table with nodes which don't have required services and not existed services
66# """
67#
68# output = local_salt_client.cmd("L@" + ','.join(nodes_in_group), 'service.get_all', expr_form='compound')
69# if len(output.keys()) < 2:
70# pytest.skip("Nothing to compare - just 1 node")
71#
72# def is_proper_service_for_node(_service, _node):
73# """
74# Return True if service exists on node and exists in inconsistency_rule
75# Return True if service doesn't exists on node and doesn't exists in inconsistency_rule
76# Return False otherwise
77# :param _service: string
78# :param _node: string full name of node
79# :return: bool, read description for further details
80# """
81# short_name_of_node = _node.split('.')[0]
82# if short_name_of_node not in inconsistency_rule.keys():
83# return False
84#
85# if _service in inconsistency_rule[short_name_of_node] and \
86# _service in output[_node]:
87# # Return True if service exists on node and exists in inconsistency_rule
88# return True
89#
90# if _service not in inconsistency_rule[short_name_of_node] and \
91# _service not in output[_node]:
92# # Return True if service exists on node and exists in inconsistency_rule
93# return True
94# print("return False for {} in {}".format(_service, _node))
95# # error_text = ""
96# return False
97#
98# errors = list()
99# for node, expected_services in inconsistency_rule.items():
100# print("Check {} , {} ".format(node, expected_services))
101# # Skip if there is no proper node. Find nodes that contains node_title (like 'kvm03') in their titles
102# if not any([node in node_name for node_name in output.keys()]):
103# continue
104# for expected_service in expected_services:
105# service_on_nodes = {_node: expected_service if expected_service in _service else None
106# for _node, _service
107# in output.items()}
108# print([is_proper_service_for_node(expected_service, _node)
109# for _node
110# in output.keys()])
111# if not all([is_proper_service_for_node(expected_service, _node)
112# for _node
113# in output.keys()]):
114# errors.append(service_on_nodes)
115#
116# assert errors.__len__() == 0, json.dumps(errors, indent=4)
117# assert False