Merge "Fix of ping usage in net_helpers.async_ping()" into stable/liberty
This commit is contained in:
commit
6d28df0c29
|
@ -24,6 +24,7 @@ import select
|
||||||
import shlex
|
import shlex
|
||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
import netaddr
|
import netaddr
|
||||||
|
@ -85,12 +86,22 @@ 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):
|
def assert_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)
|
||||||
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
|
@contextlib.contextmanager
|
||||||
|
|
Loading…
Reference in New Issue