diff options
| author | Christian Hopps <chopps@labn.net> | 2022-06-22 16:08:31 -0400 |
|---|---|---|
| committer | Christian Hopps <chopps@labn.net> | 2022-06-23 05:01:40 -0400 |
| commit | 9495c4056fef3a4c6b3d69c2fb11258d5dd8049f (patch) | |
| tree | 36f7c331dadebbadc64ea8feb7262d59a9b87d7c /tests/topotests/ospfapi/ctester.py | |
| parent | b059fb7f328464c5b284e81ff6fcc55ba20dc734 (diff) | |
tests: add ospf api router ID topotest
Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'tests/topotests/ospfapi/ctester.py')
| -rwxr-xr-x | tests/topotests/ospfapi/ctester.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/topotests/ospfapi/ctester.py b/tests/topotests/ospfapi/ctester.py index 243fc0613f..8fd202a023 100755 --- a/tests/topotests/ospfapi/ctester.py +++ b/tests/topotests/ospfapi/ctester.py @@ -42,6 +42,35 @@ sys.path[0:0] = [CLIENTDIR] import ospfclient as api # pylint: disable=E0401 # noqa: E402 +async def do_monitor(c, args): + cv = asyncio.Condition() + + async def cb(new_router_id, _): + assert new_router_id == c.router_id + logging.info("NEW ROUTER ID: %s", new_router_id) + sys.stdout.flush() + async with cv: + cv.notify_all() + + logging.debug("API using monitor router ID callback") + await c.monitor_router_id(callback=cb) + + for check in args.monitor: + logging.info("Waiting for %s", check) + + while True: + async with cv: + got = c.router_id + if str(check) == str(got): + break + logging.debug("expected '%s' != '%s'\nwaiting on notify", check, got) + await cv.wait() + + logging.info("SUCCESS: %s", check) + print("SUCCESS: {}".format(check)) + sys.stdout.flush() + + async def do_wait(c, args): cv = asyncio.Condition() @@ -51,7 +80,7 @@ async def do_wait(c, args): async with cv: cv.notify_all() - logging.debug("API using callback") + logging.debug("API using monitor reachable callback") await c.monitor_reachable(callback=cb) for w in args.wait: @@ -81,6 +110,8 @@ async def async_main(args): c._handle_msg_loop() # pylint: disable=W0212 ) + if args.monitor: + await do_monitor(c, args) if args.wait: await do_wait(c, args) return 0 @@ -88,6 +119,9 @@ async def async_main(args): def main(*args): ap = argparse.ArgumentParser(args) + ap.add_argument( + "--monitor", action="append", help="monitor and wait for this router ID" + ) ap.add_argument("--server", default="localhost", help="OSPF API server") ap.add_argument( "--wait", action="append", help="wait for comma-sep set of reachable routers" |
