diff options
| author | Sri Mohana Singamsetty <srimohans@gmail.com> | 2019-09-13 11:03:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-13 11:03:36 -0700 |
| commit | 921308a53505c20bc08694af1fd8675e7cd68c99 (patch) | |
| tree | f4fc8359fb90f0fa68ae6b60551c712a9e4bbe71 | |
| parent | 3c5ae0248e375758e389f4adedf038bebafae704 (diff) | |
| parent | 65f40ecdb55bac82ea26f863d7aecc4d8d532766 (diff) | |
Merge pull request #4969 from ton31337/feature/rewrite_bgp_aggregate-address_route-map_test
tests: Improve bgp_aggregate-address_route-map test
| -rw-r--r-- | tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py b/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py index bee5115323..d6753e9b23 100644 --- a/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py +++ b/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py @@ -39,6 +39,7 @@ import sys import json import time import pytest +import functools CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, '../')) @@ -88,21 +89,42 @@ def test_bgp_maximum_prefix_invalid(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) + router = tgen.gears['r2'] + def _bgp_converge(router): - while True: - output = json.loads(tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) - if output['192.168.255.1']['bgpState'] == 'Established': - if output['192.168.255.1']['addressFamilyInfo']['ipv4Unicast']['acceptedPrefixCounter'] == 3: - return True + output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) + expected = { + '192.168.255.1': { + 'bgpState': 'Established', + 'addressFamilyInfo': { + 'ipv4Unicast': { + 'acceptedPrefixCounter': 3 + } + } + } + } + return topotest.json_cmp(output, expected) def _bgp_aggregate_address_has_metric(router): - output = json.loads(tgen.gears[router].vtysh_cmd("show ip bgp 172.16.255.0/24 json")) - if output['paths'][0]['med'] == 123: - return True - return False + output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.0/24 json")) + expected = { + 'paths': [ + { + 'med': 123 + } + ] + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge, router) + success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + + assert result is None, 'Failed to see bgp convergence in "{}"'.format(router) + + test_func = functools.partial(_bgp_aggregate_address_has_metric, router) + success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) - if _bgp_converge('r2'): - assert _bgp_aggregate_address_has_metric('r2') == True + assert result is None, 'Failed to see applied metric for aggregated prefix in "{}"'.format(router) if __name__ == '__main__': args = ["-s"] + sys.argv[1:] |
