blob: e872b4be34844ce31cd65351cb866c22e7940baf [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
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 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", [])
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050020 services_by_nodes = local_salt_client.cmd(tgt="L@"+','.join(nodes_in_group),
21 fun='service.get_all',
22 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000023
Hanna Arhipovaab919642019-03-27 20:05:38 +020024 if len(services_by_nodes.keys()) < 2:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000025 pytest.skip("Nothing to compare - only 1 node")
26
Oleksii Zhurba599801a2019-06-04 17:26:51 -050027 # PROD-30833
28 gtw01 = local_salt_client.pillar_get(
29 param='_param:openstack_gateway_node01_hostname') or 'gtw01'
30 cluster_domain = local_salt_client.pillar_get(
31 param='_param:cluster_domain') or '.local'
32 gtw01 += '.' + cluster_domain
33 if gtw01 in nodes_in_group:
34 octavia = local_salt_client.cmd(tgt="L@" + ','.join(nodes_in_group),
35 fun='pillar.get',
36 param='octavia:manager:enabled',
37 expr_form='compound')
38 gtws = [gtw for gtw in octavia.values() if gtw]
39 if len(gtws) == 1 and gtw01 in services_by_nodes.keys():
40 services_by_nodes.pop(gtw01)
41 logging.info("gtw01 node is skipped in test_check_services")
42
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000043 nodes = []
44 pkts_data = []
Hanna Arhipovaab919642019-03-27 20:05:38 +020045 all_services = set()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000046
Hanna Arhipovaab919642019-03-27 20:05:38 +020047 for node in services_by_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050048 if not services_by_nodes[node]:
49 # TODO: do not skip node
Hanna Arhipova56eab942019-05-06 20:14:18 +030050 logging.info("Node {} is skipped".format (node))
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050051 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000052 nodes.append(node)
Hanna Arhipovaab919642019-03-27 20:05:38 +020053 all_services.update(services_by_nodes[node])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000054
Hanna Arhipovaab919642019-03-27 20:05:38 +020055 for srv in all_services:
Hanna Arhipova8fd295c2019-03-07 13:46:43 +020056 if srv in exclude_services:
57 continue
Hanna Arhipovaab919642019-03-27 20:05:38 +020058 service_existence = dict()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000059 for node in nodes:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020060 short_name_of_node = node.split('.')[0]
61 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 +020062 # Skip the checking of some service on the specific node
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020063 break
Hanna Arhipovaab919642019-03-27 20:05:38 +020064 elif srv in services_by_nodes[node]:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020065 # Found service on node
Hanna Arhipovaab919642019-03-27 20:05:38 +020066 service_existence[node] = "+"
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000067 else:
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020068 # Not found expected service on node
Hanna Arhipovaab919642019-03-27 20:05:38 +020069 service_existence[node] = "No service"
70 if set(service_existence.values()).__len__() > 1:
71 report = ["{node}: {status}".format(node=node, status=status) for node, status in service_existence.items()]
72 report.sort()
73 report.insert(0, srv)
74 pkts_data.append(report)
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020075 assert len(pkts_data) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050076 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050077 json.dumps(pkts_data, indent=4))
Hanna Arhipovafeebf9e2018-12-24 12:45:54 +020078
79
80# TODO : remake this test to make workable https://mirantis.jira.com/browse/PROD-25958
81
82# def _check_services_on_special_node(local_salt_client, nodes_in_group):
83# """
84# Check that specific node has service.
85# Nodes and proper services should be defined in inconsistency_rule dictionary
86#
87# :print: Table with nodes which don't have required services and not existed services
88# """
89#
90# output = local_salt_client.cmd("L@" + ','.join(nodes_in_group), 'service.get_all', expr_form='compound')
91# if len(output.keys()) < 2:
92# pytest.skip("Nothing to compare - just 1 node")
93#
94# def is_proper_service_for_node(_service, _node):
95# """
96# Return True if service exists on node and exists in inconsistency_rule
97# Return True if service doesn't exists on node and doesn't exists in inconsistency_rule
98# Return False otherwise
99# :param _service: string
100# :param _node: string full name of node
101# :return: bool, read description for further details
102# """
103# short_name_of_node = _node.split('.')[0]
104# if short_name_of_node not in inconsistency_rule.keys():
105# return False
106#
107# if _service in inconsistency_rule[short_name_of_node] and \
108# _service in output[_node]:
109# # Return True if service exists on node and exists in inconsistency_rule
110# return True
111#
112# if _service not in inconsistency_rule[short_name_of_node] and \
113# _service not in output[_node]:
114# # Return True if service exists on node and exists in inconsistency_rule
115# return True
116# print("return False for {} in {}".format(_service, _node))
117# # error_text = ""
118# return False
119#
120# errors = list()
121# for node, expected_services in inconsistency_rule.items():
122# print("Check {} , {} ".format(node, expected_services))
123# # Skip if there is no proper node. Find nodes that contains node_title (like 'kvm03') in their titles
124# if not any([node in node_name for node_name in output.keys()]):
125# continue
126# for expected_service in expected_services:
127# service_on_nodes = {_node: expected_service if expected_service in _service else None
128# for _node, _service
129# in output.items()}
130# print([is_proper_service_for_node(expected_service, _node)
131# for _node
132# in output.keys()])
133# if not all([is_proper_service_for_node(expected_service, _node)
134# for _node
135# in output.keys()]):
136# errors.append(service_on_nodes)
137#
138# assert errors.__len__() == 0, json.dumps(errors, indent=4)
139# assert False