mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 15:33:56 +00:00
tests: Test if ip
and fqdn
are included in show [ip] bgp json
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
This commit is contained in:
parent
515c260288
commit
6d9a2ec9b4
@ -5,7 +5,7 @@
|
|||||||
# Part of NetDEF Topology Tests
|
# Part of NetDEF Topology Tests
|
||||||
#
|
#
|
||||||
# Copyright (c) 2019 by
|
# Copyright (c) 2019 by
|
||||||
# Network Device Education Foundation, Inc. ("NetDEF")
|
# Donatas Abraitis <donatas.abraitis@gmail.com>
|
||||||
#
|
#
|
||||||
# Permission to use, copy, modify, and/or distribute this software
|
# Permission to use, copy, modify, and/or distribute this software
|
||||||
# for any purpose with or without fee is hereby granted, provided
|
# for any purpose with or without fee is hereby granted, provided
|
||||||
@ -33,6 +33,7 @@ import sys
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import pytest
|
import pytest
|
||||||
|
import functools
|
||||||
|
|
||||||
CWD = os.path.dirname(os.path.realpath(__file__))
|
CWD = os.path.dirname(os.path.realpath(__file__))
|
||||||
sys.path.append(os.path.join(CWD, '../'))
|
sys.path.append(os.path.join(CWD, '../'))
|
||||||
@ -76,33 +77,40 @@ def teardown_module(mod):
|
|||||||
tgen = get_topogen()
|
tgen = get_topogen()
|
||||||
tgen.stop_topology()
|
tgen.stop_topology()
|
||||||
|
|
||||||
def test_bgp_maximum_prefix_invalid():
|
def test_bgp_show_ip_bgp_hostname():
|
||||||
tgen = get_topogen()
|
tgen = get_topogen()
|
||||||
|
|
||||||
if tgen.routers_have_failure():
|
if tgen.routers_have_failure():
|
||||||
pytest.skip(tgen.errors)
|
pytest.skip(tgen.errors)
|
||||||
|
|
||||||
def _bgp_converge(router, neighbor):
|
router = tgen.gears['r2']
|
||||||
cmd = "show ip bgp neighbor {0} json".format(neighbor)
|
|
||||||
while True:
|
def _bgp_converge(router):
|
||||||
output = json.loads(tgen.gears[router].vtysh_cmd(cmd))
|
output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
|
||||||
if output[neighbor]['bgpState'] == 'Established':
|
expected = {
|
||||||
time.sleep(3)
|
'192.168.255.1': {
|
||||||
|
'bgpState': 'Established',
|
||||||
|
'addressFamilyInfo': {
|
||||||
|
'ipv4Unicast': {
|
||||||
|
'acceptedPrefixCounter': 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return topotest.json_cmp(output, expected)
|
||||||
|
|
||||||
|
def _bgp_show_nexthop_hostname_and_ip(router):
|
||||||
|
output = json.loads(router.vtysh_cmd("show ip bgp json"))
|
||||||
|
for nh in output['routes']['172.16.255.253/32'][0]['nexthops']:
|
||||||
|
if 'hostname' in nh and 'ip' in nh:
|
||||||
return True
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def _bgp_show_nexthop(router, prefix):
|
test_func = functools.partial(_bgp_converge, router)
|
||||||
cmd = "show ip bgp json"
|
success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
|
||||||
output = json.loads(tgen.gears[router].vtysh_cmd(cmd))
|
|
||||||
for nh in output['routes'][prefix][0]['nexthops']:
|
|
||||||
if 'fqdn' in nh:
|
|
||||||
return 'fqdn'
|
|
||||||
return 'ip'
|
|
||||||
|
|
||||||
if _bgp_converge('r2', '192.168.255.1'):
|
assert result is None, 'Failed bgp convergence in "{}"'.format(router)
|
||||||
assert _bgp_show_nexthop('r2', '172.16.255.254/32') == 'fqdn'
|
assert _bgp_show_nexthop_hostname_and_ip(router) == True
|
||||||
|
|
||||||
if _bgp_converge('r1', '192.168.255.2'):
|
|
||||||
assert _bgp_show_nexthop('r1', '172.16.255.253/32') == 'ip'
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = ["-s"] + sys.argv[1:]
|
args = ["-s"] + sys.argv[1:]
|
||||||
|
Loading…
Reference in New Issue
Block a user