diff --git a/neutron/tests/common/net_helpers.py b/neutron/tests/common/net_helpers.py index 8bc34a826ec..5085c220d22 100644 --- a/neutron/tests/common/net_helpers.py +++ b/neutron/tests/common/net_helpers.py @@ -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