vty_test_runner.py: fix nat_msc_test(): socket attach: reduce timeout, retry

In nat_msc_test(), upon socket timeout, retry up to six times. Reduce the
timeout between retries. This should get rid of sporadic test failures that
we've been seeing a lot on jenkins lately.

Raise an exception upon unexpected vty response.

Print more detail to stdout. Since we would actually want as much output as we
can get in a test suite, remove the 'if (verbose)' and just always print the
connection source. unittest is keeping all stdout silent by default anyway.

Change-Id: I2f83eef55592778e54164a90e1eabeb80fb918da
This commit is contained in:
Neels Hofmeyr 2016-09-28 23:38:45 +02:00
parent 7e5bb6283d
commit caeb62d7ff
1 changed files with 22 additions and 5 deletions

View File

@ -1228,16 +1228,33 @@ def data2str(d):
def nat_msc_test(x, ip, port, verbose = False):
msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
msc.settimeout(32)
msc.settimeout(5)
msc.bind((ip, port))
msc.listen(5)
if (verbose):
print "MSC is ready at " + ip
conn = None
while "MSC is connected: 0" == x.vty.command("show msc connection"):
conn, addr = msc.accept()
if (verbose):
print "MSC got connection from ", addr
while True:
vty_response = x.vty.command("show msc connection")
print "'show msc connection' says: %r" % vty_response
if vty_response == "MSC is connected: 1":
# success
break;
if vty_response != "MSC is connected: 0":
raise Exception("Unexpected response to 'show msc connection'"
" vty command: %r" % vty_response)
timeout_retries = 6
while timeout_retries > 0:
try:
conn, addr = msc.accept()
print "MSC got connection from ", addr
break
except socket.timeout:
print "socket timed out."
timeout_retries -= 1
continue
if not conn:
raise Exception("VTY reports MSC is connected, but I haven't"
" connected yet: %r %r" % (ip, port))