From 395f34d47ddbe7776deecf4b98a6270a963849de Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Thu, 4 Aug 2016 15:31:44 -0400 Subject: [PATCH] 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. (cherry picked from commit ca2aa3ca05aafcd3b7a81b81f8280ed363009f11) Change-Id: Ibe69417a0d819d4cd87e2f487c08fd126b1024e2 --- neutron/tests/common/net_helpers.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/neutron/tests/common/net_helpers.py b/neutron/tests/common/net_helpers.py index 8cc57f82f33..ebf89e3fa81 100644 --- a/neutron/tests/common/net_helpers.py +++ b/neutron/tests/common/net_helpers.py @@ -86,7 +86,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) @@ -107,7 +115,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)