From 5cffda18823fc27f4aa1eddef87f7e137267401a Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Fri, 3 Aug 2018 13:23:52 -0300 Subject: [PATCH] lib: implement standardized compare functions In a effort to migrate more tests to use `run_and_expect` instead of `sleep`s, this commit imports some common functions used to compare router output. Retrying output comparison for N times, instead of relying on arbitrary code `sleep`s, should help CI system tests fail less and possibly run for less time. Signed-off-by: Rafael Zalamena --- tests/topotests/lib/topotest.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index d2617c4960..bf3cfe5322 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -199,6 +199,24 @@ def json_cmp(d1, d2): return None +def router_output_cmp(router, cmd, expected): + """ + Runs `cmd` in router and compares the output with `expected`. + """ + return difflines(normalize_text(router.vtysh_cmd(cmd)), + normalize_text(expected), + title1="Current output", + title2="Expected output") + + +def router_json_cmp(router, cmd, data): + """ + Runs `cmd` that returns JSON data (normally the command ends with 'json') + and compare with `data` contents. + """ + return json_cmp(router.vtysh_cmd(cmd, isjson=True), data) + + def run_and_expect(func, what, count=20, wait=3): """ Run `func` and compare the result with `what`. Do it for `count` times @@ -207,6 +225,12 @@ def run_and_expect(func, what, count=20, wait=3): Returns (True, func-return) on success or (False, func-return) on failure. + + --- + + Helper functions to use with this function: + - router_output_cmp + - router_json_cmp """ start_time = time.time() func_name = "" -- 2.39.5