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 ca2aa3ca05
)
Change-Id: Ibe69417a0d819d4cd87e2f487c08fd126b1024e2
This commit is contained in:
parent
cc6c2029ba
commit
395f34d47d
|
@ -86,7 +86,15 @@ def set_namespace_gateway(port_dev, gateway_ip):
|
||||||
port_dev.route.add_gateway(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
|
ipversion = netaddr.IPAddress(dst_ip).version
|
||||||
ping_command = 'ping' if ipversion == 4 else 'ping6'
|
ping_command = 'ping' if ipversion == 4 else 'ping6'
|
||||||
ns_ip_wrapper = ip_lib.IPWrapper(src_namespace)
|
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
|
@contextlib.contextmanager
|
||||||
def async_ping(namespace, ips):
|
def async_ping(namespace, ips):
|
||||||
with futures.ThreadPoolExecutor(max_workers=len(ips)) as executor:
|
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]
|
for ip in ips]
|
||||||
yield lambda: all(f.done() for f in fs)
|
yield lambda: all(f.done() for f in fs)
|
||||||
futures.wait(fs)
|
futures.wait(fs)
|
||||||
|
|
Loading…
Reference in New Issue