Merge "Fix of ping usage in net_helpers.async_ping()" into stable/mitaka

This commit is contained in:
Jenkins 2016-07-29 04:21:42 +00:00 committed by Gerrit Code Review
commit d1667a4bf5
1 changed files with 14 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import select
import shlex
import signal
import subprocess
import time
import fixtures
import netaddr
@ -95,12 +96,22 @@ 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):
def assert_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)
ns_ip_wrapper.netns.execute([ping_command, '-c', count, '-W', timeout,
dst_ip])
# See bug 1588731 for explanation why using -c count ping option
# cannot be used and it needs to be done using the following workaround.
for _index in range(count):
start_time = time.time()
ns_ip_wrapper.netns.execute([ping_command, '-c', '1', '-W', timeout,
dst_ip])
end_time = time.time()
diff = end_time - start_time
if 0 < diff < interval:
# wait at most "interval" seconds between individual pings
time.sleep(interval - diff)
@contextlib.contextmanager