aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-11-29 18:21:18 +0100
committerNeels Hofmeyr <neels@hofmeyr.de>2017-11-29 18:21:18 +0100
commit48b951a7a6057f8072dbb17a5315a518d5d5112e (patch)
treeb65bfe6d54b8672a86da489cf412965b01a04f63
parent751491cdf9fba3a46911ac46bf0f640588bec286 (diff)
osmo_interact_common: add '... !regex' wildcard
Sometimes it is desirable to match any lines, just make sure that a given regex does *not* exist in the command reply. For example, during handover config tests, to verify that no handover config exists, one would have to match an entire 'show running-config' output, which is subject to change whenever the VTY changes. Add a wildcard '... !' which allows passing a regex that must not be encountered, e.g.: OsmoBSC(config-net)# show running-config ... network ... !handover bts 0 ... handover 1 ... This checks that there is no handover config on the network level while bts 0 does have handover config. Change-Id: I7c1ebb2e7f059047903a53de26a0ec1ce7fa9b98
-rw-r--r--osmopy/osmo_interact_common.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/osmopy/osmo_interact_common.py b/osmopy/osmo_interact_common.py
index 57f00bf..5efc22d 100644
--- a/osmopy/osmo_interact_common.py
+++ b/osmopy/osmo_interact_common.py
@@ -32,6 +32,7 @@ import time
import traceback
import socket
import shlex
+import re
class Interact:
@@ -210,25 +211,47 @@ class Interact:
- In 'expect', if a line is exactly '...', it matches any number of
arbitrary lines in 'got'; the implementation is trivial and skips
lines to the first occurence in 'got' that continues after '...'.
+ - If an 'expect' line is '... !regex', it matches any number of
+ lines like '...', but the given regex must not match any of those
+ lines.
Return 'True' on match, or a string describing the mismatch.
'''
def match_line(expect_line, got_line):
return expect_line == got_line
+ ANY = '...'
+ ANY_EXCEPT = '... !'
+
e = 0
g = 0
while e < len(expect):
- if expect[e] == '...':
+ if expect[e] == ANY or expect[e].startswith(ANY_EXCEPT):
+ wildcard = expect[e]
e += 1
+ g_end = g
if e >= len(expect):
# anything left in 'got' is accepted.
- return True
+ g_end = len(got)
# look for the next occurence of the expected line in 'got'
- while g < len(got) and not match_line(expect[e], got[g]):
- g += 1
+ while g_end < len(got) and not match_line(expect[e], got[g_end]):
+ g_end += 1
+
+ if wildcard == ANY:
+ # no restrictions on lines
+ g = g_end
+
+ elif wildcard.startswith(ANY_EXCEPT):
+ except_re = re.compile(wildcard[len(ANY_EXCEPT):])
+ while g < g_end:
+ if except_re.search(got[g]):
+ return ('Got forbidden line for wildcard %r:'
+ ' did not expect %r in line %d of response'
+ % (wildcard, got[g], g))
+ g += 1
+
continue
if g >= len(got):