Merge "Restore old assert_ping behavior"

This commit is contained in:
Jenkins 2016-08-05 02:14:49 +00:00 committed by Gerrit Code Review
commit 261912d996
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)