blob: 31c2447eb53628c6a813a3c090b4c423cee84173 [file] [log] [blame]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03001import json
Oleksii Zhurba23c18332019-05-09 18:53:40 -05002import pytest
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03003
4
Oleksii Zhurba23c18332019-05-09 18:53:40 -05005@pytest.mark.full
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03006def test_check_default_gateways(local_salt_client, nodes_in_group):
Dmitriy Kruglovbc0a88b2019-08-20 11:45:35 +02007 group, nodes = nodes_in_group
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03008 netstat_info = local_salt_client.cmd(
Dmitriy Kruglovbc0a88b2019-08-20 11:45:35 +02009 tgt="L@"+','.join(nodes),
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030010 param='ip r | sed -n 1p',
11 expr_form='compound')
12
13 gateways = {}
14
Ekaterina Chernovac73bc4e2019-11-12 14:56:03 +030015 for node in list(netstat_info.keys()):
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030016 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]
21 else:
22 gateways[gateway].append(node)
23
Ekaterina Chernovac73bc4e2019-11-12 14:56:03 +030024 assert len(list(gateways.keys())) == 1, (
Dmitriy Kruglovbc0a88b2019-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))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030027 )