Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import json |
| 2 | import pytest |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame] | 3 | import os |
Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame] | 4 | import utils |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 5 | |
| 6 | |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 7 | def test_check_default_gateways(local_salt_client, nodes_in_group): |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 8 | netstat_info = local_salt_client.cmd( |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 9 | "L@"+','.join(nodes_in_group), 'cmd.run', ['ip r | sed -n 1p'], expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 10 | |
| 11 | gateways = {} |
| 12 | nodes = netstat_info.keys() |
| 13 | |
| 14 | for node in nodes: |
| 15 | if netstat_info[node] not in gateways: |
| 16 | gateways[netstat_info[node]] = [node] |
| 17 | else: |
| 18 | gateways[netstat_info[node]].append(node) |
| 19 | |
| 20 | assert len(gateways.keys()) == 1, \ |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 21 | "There were found few gateways: {gw}".format( |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 22 | gw=json.dumps(gateways, indent=4) |
| 23 | ) |