Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import json |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 2 | |
| 3 | |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 4 | def test_check_default_gateways(local_salt_client, nodes_in_group): |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 5 | netstat_info = local_salt_client.cmd( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame^] | 6 | tgt="L@"+','.join(nodes_in_group), |
| 7 | param='ip r | sed -n 1p', |
| 8 | expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 9 | |
| 10 | gateways = {} |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 11 | |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame^] | 12 | 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 Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 18 | else: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame^] | 19 | gateways[gateway].append(node) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 20 | |
| 21 | assert len(gateways.keys()) == 1, \ |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 22 | "There were found few gateways: {gw}".format( |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 23 | gw=json.dumps(gateways, indent=4) |
| 24 | ) |