Merge "Fix of ping usage in net_helpers.async_ping()"
This commit is contained in:
commit
1db9a8157e
@ -24,6 +24,7 @@ import select
|
||||
import shlex
|
||||
import signal
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
import fixtures
|
||||
import netaddr
|
||||
@ -96,12 +97,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
|
||||
|
Loading…
Reference in New Issue
Block a user