]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: lutil matching without changing newlines
authorG. Paul Ziemba <paulz@labn.net>
Thu, 12 Apr 2018 06:03:43 +0000 (23:03 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 28 Nov 2018 01:22:13 +0000 (20:22 -0500)
Prior behavior of luCommand was to convert newlines to spaces in DUT
output before pattern matching. New method operating in parallel uses
re.DOTALL to mimic same behavior and allow preserving original DUT output.
The original output is needed for some scripts that parse line-by-line.

There is also some test code to compare match results using the
old way and new way and log a message if they are different. After
some short time we can develop confidence that using this new method
will not break any existing tests.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
tests/topotests/lib/lutil.py

index 0fb7ef7fd8b54c777902c53edf2cbe0e94b36159..d74d806f0bce5facbaa9b9f80ddbc1cdb5dae1e1 100755 (executable)
@@ -46,6 +46,8 @@ class lUtil:
     l_filename = ''
     l_last = None
     l_line = 0
+    l_dotall_experiment = False
+    l_last_nl = None
 
     fout = ''
     fsum = ''
@@ -196,6 +198,17 @@ Total %-4d                                                           %-4d %d\n\
                     js = None
                     self.log('WARNING: JSON load failed -- confirm command output is in JSON format.')
         self.log('COMMAND OUTPUT:%s:' % report)
+
+       # Experiment: can we achieve the same match behavior via DOTALL
+       # without converting newlines to spaces?
+       out_nl = out
+       search_nl = re.search(regexp, out_nl, re.DOTALL);
+       self.l_last_nl = search_nl
+       # Set up for comparison
+       if search_nl != None:
+           group_nl = search_nl.group()
+           group_nl_converted = " ".join(group_nl.splitlines())
+
         out = " ".join(out.splitlines())
         search = re.search(regexp, out)
         self.l_last = search
@@ -212,6 +225,9 @@ Total %-4d                                                           %-4d %d\n\
                 success = True
             else:
                 success = False
+           # Experiment: compare matched strings obtained each way
+           if self.l_dotall_experiment and (group_nl_converted != ret):
+               self.log('DOTALL experiment: strings differ dotall=[%s] orig=[%s]' % (group_nl_converted, ret))
         if op == 'pass' or op == 'fail':
             self.result(target, success, result)
         if js != None:
@@ -255,6 +271,8 @@ def luStart(baseScriptDir='.', baseLogDir='.', net='',
     if fsum != None:
         LUtil.fsum_name = baseLogDir + '/' + fsum
     LUtil.l_level = level
+    LUtil.l_dotall_experiment = False
+    LUtil.l_dotall_experiment = True
 
 def luCommand(target, command, regexp='.', op='none', result='', time=10, returnJson=False):
     if op != 'wait':
@@ -262,10 +280,15 @@ def luCommand(target, command, regexp='.', op='none', result='', time=10, return
     else:
         return LUtil.wait(target, command, regexp, op, result, time, returnJson)
 
-def luLast():
-    if LUtil.l_last != None:
-        LUtil.log('luLast:%s:' %  LUtil.l_last.group())
-    return LUtil.l_last
+def luLast(usenl=False):
+    if usenl:
+       if LUtil.l_last_nl != None:
+           LUtil.log('luLast:%s:' %  LUtil.l_last_nl.group())
+       return LUtil.l_last_nl
+    else:
+       if LUtil.l_last != None:
+           LUtil.log('luLast:%s:' %  LUtil.l_last.group())
+       return LUtil.l_last
 
 def luInclude(filename, CallOnFail=None):
     tstFile = LUtil.base_script_dir + '/' + filename