Restore old assert_ping behavior

assert_ping() was changed recently to be async-friendly, but
the change caused the drop of a single packet to throw an
error.  Since occasionally the first packet is lost due to
address resolution (ARP) we can't use it for checking liveness
of an IP.

Restored assert_ping() and moved updated code to
assert_async_ping() since that is a special-case.

Change-Id: Ibe69417a0d819d4cd87e2f487c08fd126b1024e2
This commit is contained in:
Brian Haley 2016-08-04 15:31:44 -04:00
parent a96b84e1c1
commit ca2aa3ca05
1 changed files with 10 additions and 2 deletions

View File

@ -98,7 +98,15 @@ def set_namespace_gateway(port_dev, gateway_ip):
port_dev.route.add_gateway(gateway_ip)
def assert_ping(src_namespace, dst_ip, timeout=1, count=1, interval=1):
def assert_ping(src_namespace, dst_ip, timeout=1, count=1):
ipversion = netaddr.IPAddress(dst_ip).version
ping_command = 'ping' if ipversion == 4 else 'ping6'
ns_ip_wrapper = ip_lib.IPWrapper(src_namespace)
ns_ip_wrapper.netns.execute([ping_command, '-c', count, '-W', timeout,
dst_ip])
def assert_async_ping(src_namespace, dst_ip, timeout=1, count=1, interval=1):
ipversion = netaddr.IPAddress(dst_ip).version
ping_command = 'ping' if ipversion == 4 else 'ping6'
ns_ip_wrapper = ip_lib.IPWrapper(src_namespace)
@ -119,7 +127,7 @@ def assert_ping(src_namespace, dst_ip, timeout=1, count=1, interval=1):
@contextlib.contextmanager
def async_ping(namespace, ips):
with futures.ThreadPoolExecutor(max_workers=len(ips)) as executor:
fs = [executor.submit(assert_ping, namespace, ip, count=10)
fs = [executor.submit(assert_async_ping, namespace, ip, count=10)
for ip in ips]
yield lambda: all(f.done() for f in fs)
futures.wait(fs)