]> git.proxmox.com Git - mirror_frr.git/commitdiff
tests: Test if `ip` and `fqdn` are included in `show [ip] bgp json`
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Fri, 6 Dec 2019 20:44:36 +0000 (22:44 +0200)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 12 Dec 2019 08:35:54 +0000 (10:35 +0200)
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
tests/topotests/bgp_show_ip_bgp_fqdn/test_bgp_show_ip_bgp_fqdn.py

index 59ffd36ef396ac8013d51c801781e3e896238c82..f5119468e01b7c3f86eb1dfabb6a601b1c33fbfd 100644 (file)
@@ -5,7 +5,7 @@
 # Part of NetDEF Topology Tests
 #
 # 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
 # for any purpose with or without fee is hereby granted, provided
@@ -33,6 +33,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, '../'))
@@ -76,33 +77,40 @@ def teardown_module(mod):
     tgen = get_topogen()
     tgen.stop_topology()
 
-def test_bgp_maximum_prefix_invalid():
+def test_bgp_show_ip_bgp_hostname():
     tgen = get_topogen()
 
     if tgen.routers_have_failure():
         pytest.skip(tgen.errors)
 
-    def _bgp_converge(router, neighbor):
-        cmd = "show ip bgp neighbor {0} json".format(neighbor)
-        while True:
-            output = json.loads(tgen.gears[router].vtysh_cmd(cmd))
-            if output[neighbor]['bgpState'] == 'Established':
-                time.sleep(3)
+    router = tgen.gears['r2']
+
+    def _bgp_converge(router):
+        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': 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 False
 
-    def _bgp_show_nexthop(router, prefix):
-        cmd = "show ip bgp json"
-        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'
+    test_func = functools.partial(_bgp_converge, router)
+    success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
 
-    if _bgp_converge('r2', '192.168.255.1'):
-        assert _bgp_show_nexthop('r2', '172.16.255.254/32') == 'fqdn'
-
-    if _bgp_converge('r1', '192.168.255.2'):
-        assert _bgp_show_nexthop('r1', '172.16.255.253/32') == 'ip'
+    assert result is None, 'Failed bgp convergence in "{}"'.format(router)
+    assert _bgp_show_nexthop_hostname_and_ip(router) == True
 
 if __name__ == '__main__':
     args = ["-s"] + sys.argv[1:]