blob: 95dfb514dc90372a804b4b2ba101460a37fe1f4d [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +00003import os
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00004from cvp_checks import utils
5
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
10inconsistency_rule = {"kvm03": ["srv-volumes-backup.mount", "rsync"]}
11
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 """
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050018 output = local_salt_client.cmd("L@"+','.join(nodes_in_group), 'service.get_all', expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000019
20 if len(output.keys()) < 2:
21 pytest.skip("Nothing to compare - only 1 node")
22
23 nodes = []
24 pkts_data = []
25 my_set = set()
26
27 for node in output:
28 nodes.append(node)
29 my_set.update(output[node])
30
31 for srv in my_set:
32 diff = []
33 row = []
34 for node in nodes:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020035 short_name_of_node = node.split('.')[0]
36 if inconsistency_rule.get(short_name_of_node) is not None and srv in inconsistency_rule[short_name_of_node]:
37 # Found service on node and it SHOULD be there
38 break
39 elif srv in output[node]:
40 # Found service on node
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000041 diff.append(srv)
42 row.append("{}: +".format(node))
43 else:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020044 # Not found expected service on node
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000045 row.append("{}: No service".format(node))
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020046 if diff.__len__() > 0 and diff.count(diff[0]) < len(nodes):
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000047 row.sort()
48 row.insert(0, srv)
49 pkts_data.append(row)
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020050 assert len(pkts_data) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050051 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050052 json.dumps(pkts_data, indent=4))
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020053
54
55# TODO : remake this test to make workable https://mirantis.jira.com/browse/PROD-25958
56
57# def _check_services_on_special_node(local_salt_client, nodes_in_group):
58# """
59# Check that specific node has service.
60# Nodes and proper services should be defined in inconsistency_rule dictionary
61#
62# :print: Table with nodes which don't have required services and not existed services
63# """
64#
65# output = local_salt_client.cmd("L@" + ','.join(nodes_in_group), 'service.get_all', expr_form='compound')
66# if len(output.keys()) < 2:
67# pytest.skip("Nothing to compare - just 1 node")
68#
69# def is_proper_service_for_node(_service, _node):
70# """
71# Return True if service exists on node and exists in inconsistency_rule
72# Return True if service doesn't exists on node and doesn't exists in inconsistency_rule
73# Return False otherwise
74# :param _service: string
75# :param _node: string full name of node
76# :return: bool, read description for further details
77# """
78# short_name_of_node = _node.split('.')[0]
79# if short_name_of_node not in inconsistency_rule.keys():
80# return False
81#
82# if _service in inconsistency_rule[short_name_of_node] and \
83# _service in output[_node]:
84# # Return True if service exists on node and exists in inconsistency_rule
85# return True
86#
87# if _service not in inconsistency_rule[short_name_of_node] and \
88# _service not in output[_node]:
89# # Return True if service exists on node and exists in inconsistency_rule
90# return True
91# print("return False for {} in {}".format(_service, _node))
92# # error_text = ""
93# return False
94#
95# errors = list()
96# for node, expected_services in inconsistency_rule.items():
97# print("Check {} , {} ".format(node, expected_services))
98# # Skip if there is no proper node. Find nodes that contains node_title (like 'kvm03') in their titles
99# if not any([node in node_name for node_name in output.keys()]):
100# continue
101# for expected_service in expected_services:
102# service_on_nodes = {_node: expected_service if expected_service in _service else None
103# for _node, _service
104# in output.items()}
105# print([is_proper_service_for_node(expected_service, _node)
106# for _node
107# in output.keys()])
108# if not all([is_proper_service_for_node(expected_service, _node)
109# for _node
110# in output.keys()]):
111# errors.append(service_on_nodes)
112#
113# assert errors.__len__() == 0, json.dumps(errors, indent=4)
114# assert False