mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-06 14:29:47 +00:00
tests: JSON comparison command for LabN topotests
The changes add the "jsoncmp_pass" and the "jsoncmp_fail" commands to compare VTY shell's JSON output to an expected JSON object during topotests using the LabN testing framework. This helps to eliminate false negative test results (i.e. due to routes beeing out of order after convergence or cosmetic changes in VTY shell's text output). Signed-off-by: David Schweizer <dschweizer@opensourcerouting.org>
This commit is contained in:
parent
2031dbf31c
commit
4e3828b771
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user