Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import json |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 2 | import pytest |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 3 | |
| 4 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 5 | @pytest.mark.full |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 6 | def test_check_default_gateways(local_salt_client, nodes_in_group): |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 7 | netstat_info = local_salt_client.cmd( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 8 | tgt="L@"+','.join(nodes_in_group), |
| 9 | param='ip r | sed -n 1p', |
| 10 | expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 11 | |
| 12 | gateways = {} |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 13 | |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 14 | for node in netstat_info.keys(): |
| 15 | gateway = netstat_info[node] |
| 16 | if isinstance(gateway, bool): |
| 17 | gateway = 'Cannot access node(-s)' |
| 18 | if gateway not in gateways: |
| 19 | gateways[gateway] = [node] |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 20 | else: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 21 | gateways[gateway].append(node) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 22 | |
| 23 | assert len(gateways.keys()) == 1, \ |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 24 | "There were found few gateways: {gw}".format( |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 25 | gw=json.dumps(gateways, indent=4) |
| 26 | ) |