blob: e25015d2c109616d16cab5b32948df22567eda94 [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", [])
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050019 services_by_nodes = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
20 fun='service.get_all',
21 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000022
Hanna Arhipovaab919642019-03-27 20:05:38 +020023 if len(services_by_nodes.keys()) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000024 pytest.skip("Nothing to compare - only 1 node")
25
26 nodes = []
27 pkts_data = []
Hanna Arhipovaab919642019-03-27 20:05:38 +020028 all_services = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000029
Hanna Arhipovaab919642019-03-27 20:05:38 +020030 for node in services_by_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050031 if not services_by_nodes[node]:
32 # TODO: do not skip node
33 print "Node {} is skipped".format (node)
34 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000035 nodes.append(node)
Hanna Arhipovaab919642019-03-27 20:05:38 +020036 all_services.update(services_by_nodes[node])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000037
Hanna Arhipovaab919642019-03-27 20:05:38 +020038 for srv in all_services:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020039 if srv in exclude_services:
40 continue
Hanna Arhipovaab919642019-03-27 20:05:38 +020041 service_existence = dict()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000042 for node in nodes:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020043 short_name_of_node = node.split('.')[0]
44 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 +020045 # Skip the checking of some service on the specific node
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020046 break
Hanna Arhipovaab919642019-03-27 20:05:38 +020047 elif srv in services_by_nodes[node]:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020048 # Found service on node
Hanna Arhipovaab919642019-03-27 20:05:38 +020049 service_existence[node] = "+"
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000050 else:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020051 # Not found expected service on node
Hanna Arhipovaab919642019-03-27 20:05:38 +020052 service_existence[node] = "No service"
53 if set(service_existence.values()).__len__() > 1:
54 report = ["{node}: {status}".format(node=node, status=status) for node, status in service_existence.items()]
55 report.sort()
56 report.insert(0, srv)
57 pkts_data.append(report)
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020058 assert len(pkts_data) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050059 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050060 json.dumps(pkts_data, indent=4))
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020061
62
63# TODO : remake this test to make workable https://mirantis.jira.com/browse/PROD-25958
64
65# def _check_services_on_special_node(local_salt_client, nodes_in_group):
66# """
67# Check that specific node has service.
68# Nodes and proper services should be defined in inconsistency_rule dictionary
69#
70# :print: Table with nodes which don't have required services and not existed services
71# """
72#
73# output = local_salt_client.cmd("L@" + ','.join(nodes_in_group), 'service.get_all', expr_form='compound')
74# if len(output.keys()) < 2:
75# pytest.skip("Nothing to compare - just 1 node")
76#
77# def is_proper_service_for_node(_service, _node):
78# """
79# Return True if service exists on node and exists in inconsistency_rule
80# Return True if service doesn't exists on node and doesn't exists in inconsistency_rule
81# Return False otherwise
82# :param _service: string
83# :param _node: string full name of node
84# :return: bool, read description for further details
85# """
86# short_name_of_node = _node.split('.')[0]
87# if short_name_of_node not in inconsistency_rule.keys():
88# return False
89#
90# if _service in inconsistency_rule[short_name_of_node] and \
91# _service in output[_node]:
92# # Return True if service exists on node and exists in inconsistency_rule
93# return True
94#
95# if _service not in inconsistency_rule[short_name_of_node] and \
96# _service not in output[_node]:
97# # Return True if service exists on node and exists in inconsistency_rule
98# return True
99# print("return False for {} in {}".format(_service, _node))
100# # error_text = ""
101# return False
102#
103# errors = list()
104# for node, expected_services in inconsistency_rule.items():
105# print("Check {} , {} ".format(node, expected_services))
106# # Skip if there is no proper node. Find nodes that contains node_title (like 'kvm03') in their titles
107# if not any([node in node_name for node_name in output.keys()]):
108# continue
109# for expected_service in expected_services:
110# service_on_nodes = {_node: expected_service if expected_service in _service else None
111# for _node, _service
112# in output.items()}
113# print([is_proper_service_for_node(expected_service, _node)
114# for _node
115# in output.keys()])
116# if not all([is_proper_service_for_node(expected_service, _node)
117# for _node
118# in output.keys()]):
119# errors.append(service_on_nodes)
120#
121# assert errors.__len__() == 0, json.dumps(errors, indent=4)
122# assert False