diff --git a/tests/topotests/lib/lutil.py b/tests/topotests/lib/lutil.py index 0b6a946fda..f8f580632e 100644 --- a/tests/topotests/lib/lutil.py +++ b/tests/topotests/lib/lutil.py @@ -25,6 +25,7 @@ import json import math import time from lib.topolog import logger +from lib.topotest import json_cmp from mininet.net import Mininet @@ -194,6 +195,10 @@ Total %-4d %-4d %d\n\ global net if op != "wait": self.l_line += 1 + + if op == "jsoncmp_pass" or op == "jsoncmp_fail": + returnJson = True + self.log( "%s (#%d) %s:%s COMMAND:%s:%s:%s:%s:%s:" % ( @@ -227,6 +232,33 @@ Total %-4d %-4d %d\n\ ) self.log("COMMAND OUTPUT:%s:" % report) + # JSON comparison + if op == "jsoncmp_pass" or op == "jsoncmp_fail": + try: + expect = json.loads(regexp) + except: + expect = None + self.log( + "WARNING: JSON load failed -- confirm regex input is in JSON format." + ) + json_diff = json_cmp(js, expect) + if json_diff != None: + if op == "jsoncmp_fail": + success = True + else: + success = False + self.log("JSON DIFF:%s:" % json_diff) + ret = success + else: + if op == "jsoncmp_fail": + success = False + else: + success = True + self.result(target, success, result) + if js != None: + return js + return ret + # Experiment: can we achieve the same match behavior via DOTALL # without converting newlines to spaces? out_nl = out