blob: 8cea8809d53d587c69388b15b8b54cc768e4333f [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import json
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00002
3
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05004def test_check_default_gateways(local_salt_client, nodes_in_group):
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00005 netstat_info = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -05006 tgt="L@"+','.join(nodes_in_group),
7 param='ip r | sed -n 1p',
8 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00009
10 gateways = {}
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000011
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050012 for node in netstat_info.keys():
13 gateway = netstat_info[node]
14 if isinstance(gateway, bool):
15 gateway = 'Cannot access node(-s)'
16 if gateway not in gateways:
17 gateways[gateway] = [node]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000018 else:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050019 gateways[gateway].append(node)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000020
21 assert len(gateways.keys()) == 1, \
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050022 "There were found few gateways: {gw}".format(
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000023 gw=json.dumps(gateways, indent=4)
24 )