blob: 31c2447eb53628c6a813a3c090b4c423cee84173 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import json
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -05002import pytest
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00003
4
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -05005@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05006def test_check_default_gateways(local_salt_client, nodes_in_group):
Dmitriy Kruglova34a3042019-08-20 11:45:35 +02007 group, nodes = nodes_in_group
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00008 netstat_info = local_salt_client.cmd(
Dmitriy Kruglova34a3042019-08-20 11:45:35 +02009 tgt="L@"+','.join(nodes),
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050010 param='ip r | sed -n 1p',
11 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000012
13 gateways = {}
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000014
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030015 for node in list(netstat_info.keys()):
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050016 gateway = netstat_info[node]
17 if isinstance(gateway, bool):
18 gateway = 'Cannot access node(-s)'
19 if gateway not in gateways:
20 gateways[gateway] = [node]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000021 else:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050022 gateways[gateway].append(node)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000023
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030024 assert len(list(gateways.keys())) == 1, (
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020025 "There is a problem with default gateway for '{}' group of nodes:\n"
26 "{}".format(group, json.dumps(gateways, indent=4))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000027 )