blob: 6bb6fdb7a04554ef45d9898b0c3245f040457421 [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
Ekaterina Chernovab2804bc2019-07-25 16:13:29 +030010inconsistency_rule = {"kvm03": ["srv-volumes-backup.mount", "rsync", "sysstat"]}
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", [])
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020020 group, nodes = nodes_in_group
21 services_by_nodes = local_salt_client.cmd(tgt="L@"+','.join(nodes),
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050022 fun='service.get_all',
23 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000024
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030025 if len(list(services_by_nodes.keys())) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000026 pytest.skip("Nothing to compare - only 1 node")
27
Oleksii Zhurba599801a2019-06-04 17:26:51 -050028 # PROD-30833
29 gtw01 = local_salt_client.pillar_get(
30 param='_param:openstack_gateway_node01_hostname') or 'gtw01'
31 cluster_domain = local_salt_client.pillar_get(
32 param='_param:cluster_domain') or '.local'
33 gtw01 += '.' + cluster_domain
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020034 if gtw01 in nodes:
35 octavia = local_salt_client.cmd(tgt="L@" + ','.join(nodes),
Oleksii Zhurba599801a2019-06-04 17:26:51 -050036 fun='pillar.get',
37 param='octavia:manager:enabled',
38 expr_form='compound')
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030039 gtws = [gtw for gtw in list(octavia.values()) if gtw]
40 if len(gtws) == 1 and gtw01 in list(services_by_nodes.keys()):
Oleksii Zhurba599801a2019-06-04 17:26:51 -050041 services_by_nodes.pop(gtw01)
42 logging.info("gtw01 node is skipped in test_check_services")
43
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000044 nodes = []
45 pkts_data = []
Hanna Arhipovaab919642019-03-27 20:05:38 +020046 all_services = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000047
Hanna Arhipovaab919642019-03-27 20:05:38 +020048 for node in services_by_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050049 if not services_by_nodes[node]:
50 # TODO: do not skip node
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020051 logging.info("Node {} is skipped".format(node))
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050052 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000053 nodes.append(node)
Hanna Arhipovaab919642019-03-27 20:05:38 +020054 all_services.update(services_by_nodes[node])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000055
Hanna Arhipovaab919642019-03-27 20:05:38 +020056 for srv in all_services:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020057 if srv in exclude_services:
58 continue
Hanna Arhipovaab919642019-03-27 20:05:38 +020059 service_existence = dict()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000060 for node in nodes:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020061 short_name_of_node = node.split('.')[0]
62 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 +020063 # Skip the checking of some service on the specific node
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020064 break
Hanna Arhipovaab919642019-03-27 20:05:38 +020065 elif srv in services_by_nodes[node]:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020066 # Found service on node
Hanna Arhipovaab919642019-03-27 20:05:38 +020067 service_existence[node] = "+"
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000068 else:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020069 # Not found expected service on node
Hanna Arhipovaab919642019-03-27 20:05:38 +020070 service_existence[node] = "No service"
71 if set(service_existence.values()).__len__() > 1:
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030072 report = ["{node}: {status}".format(node=node, status=status) for node, status in list(service_existence.items())]
Hanna Arhipovaab919642019-03-27 20:05:38 +020073 report.sort()
74 report.insert(0, srv)
75 pkts_data.append(report)
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020076 assert len(pkts_data) == 0, (
77 "Non-uniform services are running on '{}' group of nodes:\n{}".format(
78 group, json.dumps(pkts_data, indent=4))
79 )
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020080
81
82# TODO : remake this test to make workable https://mirantis.jira.com/browse/PROD-25958
83
84# def _check_services_on_special_node(local_salt_client, nodes_in_group):
85# """
86# Check that specific node has service.
87# Nodes and proper services should be defined in inconsistency_rule dictionary
88#
89# :print: Table with nodes which don't have required services and not existed services
90# """
91#
92# output = local_salt_client.cmd("L@" + ','.join(nodes_in_group), 'service.get_all', expr_form='compound')
93# if len(output.keys()) < 2:
94# pytest.skip("Nothing to compare - just 1 node")
95#
96# def is_proper_service_for_node(_service, _node):
97# """
98# Return True if service exists on node and exists in inconsistency_rule
99# Return True if service doesn't exists on node and doesn't exists in inconsistency_rule
100# Return False otherwise
101# :param _service: string
102# :param _node: string full name of node
103# :return: bool, read description for further details
104# """
105# short_name_of_node = _node.split('.')[0]
106# if short_name_of_node not in inconsistency_rule.keys():
107# return False
108#
109# if _service in inconsistency_rule[short_name_of_node] and \
110# _service in output[_node]:
111# # Return True if service exists on node and exists in inconsistency_rule
112# return True
113#
114# if _service not in inconsistency_rule[short_name_of_node] and \
115# _service not in output[_node]:
116# # Return True if service exists on node and exists in inconsistency_rule
117# return True
118# print("return False for {} in {}".format(_service, _node))
119# # error_text = ""
120# return False
121#
122# errors = list()
123# for node, expected_services in inconsistency_rule.items():
124# print("Check {} , {} ".format(node, expected_services))
125# # Skip if there is no proper node. Find nodes that contains node_title (like 'kvm03') in their titles
126# if not any([node in node_name for node_name in output.keys()]):
127# continue
128# for expected_service in expected_services:
129# service_on_nodes = {_node: expected_service if expected_service in _service else None
130# for _node, _service
131# in output.items()}
132# print([is_proper_service_for_node(expected_service, _node)
133# for _node
134# in output.keys()])
135# if not all([is_proper_service_for_node(expected_service, _node)
136# for _node
137# in output.keys()]):
138# errors.append(service_on_nodes)
139#
140# assert errors.__len__() == 0, json.dumps(errors, indent=4)
141# assert False