From 7f3197922ee0412863d88632c9d700e58ccb169e Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Tue, 9 Jun 2020 18:45:29 -0300 Subject: [PATCH] topotests: MPLS table output is not ordered Don't expect ordered output from `show mpls table json`. Signed-off-by: Rafael Zalamena --- .../ospf-sr-topo1/r1/zebra_mpls.json | 20 +++++----- .../ospf-sr-topo1/r2/zebra_mpls.json | 26 ++++++------- .../ospf-sr-topo1/r3/zebra_mpls.json | 14 +++---- .../ospf-sr-topo1/r4/zebra_mpls.json | 16 ++++---- .../ospf-sr-topo1/test_ospf_sr_topo1.py | 37 +++++++++++++------ 5 files changed, 63 insertions(+), 50 deletions(-) diff --git a/tests/topotests/ospf-sr-topo1/r1/zebra_mpls.json b/tests/topotests/ospf-sr-topo1/r1/zebra_mpls.json index a0059e625e..5ae2399e5c 100644 --- a/tests/topotests/ospf-sr-topo1/r1/zebra_mpls.json +++ b/tests/topotests/ospf-sr-topo1/r1/zebra_mpls.json @@ -1,5 +1,5 @@ -{ - "20100":{ +[ + { "inLabel":20100, "installed":true, "nexthops":[ @@ -11,7 +11,7 @@ } ] }, - "20200":{ + { "inLabel":20200, "installed":true, "nexthops":[ @@ -31,7 +31,7 @@ } ] }, - "20300":{ + { "inLabel":20300, "installed":true, "nexthops":[ @@ -51,7 +51,7 @@ } ] }, - "20400":{ + { "inLabel":20400, "installed":true, "nexthops":[ @@ -71,7 +71,7 @@ } ] }, - "label-1":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -84,7 +84,7 @@ } ] }, - "label-2":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -97,7 +97,7 @@ } ] }, - "label-3":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -110,7 +110,7 @@ } ] }, - "label-4":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -123,4 +123,4 @@ } ] } -} +] diff --git a/tests/topotests/ospf-sr-topo1/r2/zebra_mpls.json b/tests/topotests/ospf-sr-topo1/r2/zebra_mpls.json index a6dd22b5b7..aedcc5b8f8 100644 --- a/tests/topotests/ospf-sr-topo1/r2/zebra_mpls.json +++ b/tests/topotests/ospf-sr-topo1/r2/zebra_mpls.json @@ -1,5 +1,5 @@ -{ - "8100":{ +[ + { "inLabel":8100, "installed":true, "nexthops":[ @@ -19,7 +19,7 @@ } ] }, - "8300":{ + { "inLabel":8300, "installed":true, "nexthops":[ @@ -32,7 +32,7 @@ } ] }, - "8400":{ + { "inLabel":8400, "installed":true, "nexthops":[ @@ -45,7 +45,7 @@ } ] }, - "label-1":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -58,7 +58,7 @@ } ] }, - "label-2":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -71,7 +71,7 @@ } ] }, - "label-3":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -84,7 +84,7 @@ } ] }, - "label-4":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -97,7 +97,7 @@ } ] }, - "label-5":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -110,7 +110,7 @@ } ] }, - "label-6":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -123,7 +123,7 @@ } ] }, - "label-7":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -136,7 +136,7 @@ } ] }, - "label-8":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -149,4 +149,4 @@ } ] } -} +] diff --git a/tests/topotests/ospf-sr-topo1/r3/zebra_mpls.json b/tests/topotests/ospf-sr-topo1/r3/zebra_mpls.json index 6900f30502..71e8366137 100644 --- a/tests/topotests/ospf-sr-topo1/r3/zebra_mpls.json +++ b/tests/topotests/ospf-sr-topo1/r3/zebra_mpls.json @@ -1,5 +1,5 @@ -{ - "10100":{ +[ + { "inLabel":10100, "installed":true, "nexthops":[ @@ -12,7 +12,7 @@ } ] }, - "10200":{ + { "inLabel":10200, "installed":true, "nexthops":[ @@ -25,7 +25,7 @@ } ] }, - "10400":{ + { "inLabel":10400, "installed":true, "nexthops":[ @@ -38,7 +38,7 @@ } ] }, - "label-1":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -51,7 +51,7 @@ } ] }, - "label-2":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -64,4 +64,4 @@ } ] } -} +] diff --git a/tests/topotests/ospf-sr-topo1/r4/zebra_mpls.json b/tests/topotests/ospf-sr-topo1/r4/zebra_mpls.json index 1fff699b58..b5767e1d7d 100644 --- a/tests/topotests/ospf-sr-topo1/r4/zebra_mpls.json +++ b/tests/topotests/ospf-sr-topo1/r4/zebra_mpls.json @@ -1,5 +1,5 @@ -{ - "10100":{ +[ + { "inLabel":10100, "installed":true, "nexthops":[ @@ -12,7 +12,7 @@ } ] }, - "10200":{ + { "inLabel":10200, "installed":true, "nexthops":[ @@ -25,7 +25,7 @@ } ] }, - "10300":{ + { "inLabel":10300, "installed":true, "nexthops":[ @@ -38,7 +38,7 @@ } ] }, - "10400":{ + { "inLabel":10400, "installed":true, "nexthops":[ @@ -50,7 +50,7 @@ } ] }, - "label-1":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -63,7 +63,7 @@ } ] }, - "label-2":{ + { "inLabel":"*", "installed":true, "nexthops":[ @@ -76,4 +76,4 @@ } ] } -} +] diff --git a/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py b/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py index abf3bf3c02..6792c56b3b 100755 --- a/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py +++ b/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py @@ -151,18 +151,31 @@ def test_ospf_kernel_route(): logger.info("--- test OSPF Segment Routing MPLS tables ---") def show_mpls_table_json_cmp(rt, expected): - "Removes random label and use `label-X` instead." - text = rt.vtysh_cmd('show mpls table json') - - # Substitue random labels with fixed label value. - for label in range(1, 10): - text = re.sub(r'"5000[0-9]"', '"label-{}"'.format(label), text, - count=1) - - print '\n{}\n'.format(text) - - output = json.loads(text) - return topotest.json_cmp(output, expected) + """ + Reformat MPLS table output to use a list of labels instead of dict. + + Original: + { + "X": { + inLabel: "X", + # ... + } + } + + List format: + [ + { + inLabel: "X", + } + ] + """ + out = rt.vtysh_cmd('show mpls table json', isjson=True) + + outlist = [] + for key in out.keys(): + outlist.append(out[key]) + + return topotest.json_cmp(outlist, expected) for rnum in range(1, 5): router = "r{}".format(rnum) -- 2.39.5