aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrady Johnson <brady.allen.johnson@ericsson.com>2017-02-23 11:22:06 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-02-23 11:22:06 +0000
commitdf08639171bba0e86f6595849d864ad514bd8f3d (patch)
tree2fa4bfaa55a35907b0987178a991c2a5957a38c9
parent77df3a2bcced7975565d4b4ba7feac6a78848a78 (diff)
parent15e1470f6366e7e31522a7882781184817e55bcc (diff)
Merge "Improve readability of ping function"
-rw-r--r--sfc/lib/utils.py29
1 files changed, 6 insertions, 23 deletions
diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py
index b4807cc2..dde71b2b 100644
--- a/sfc/lib/utils.py
+++ b/sfc/lib/utils.py
@@ -177,31 +177,14 @@ def create_instance(nova_client, name, flavor, image_id, network_id, sg_id,
return instance
-def ping(remote, pkt_cnt=1, iface=None, retries=100, timeout=None):
- ping_cmd = 'ping'
-
- if timeout:
- ping_cmd = ping_cmd + ' -w %s' % timeout
-
- grep_cmd = "grep -e 'packet loss' -e rtt"
-
- if iface is not None:
- ping_cmd = ping_cmd + ' -I %s' % iface
-
- ping_cmd = ping_cmd + ' -i 0 -c %d %s' % (pkt_cnt, remote)
- cmd = ping_cmd + '|' + grep_cmd
+def ping(remote, retries=100, retry_timeout=1):
+ cmd = 'ping -c1 -w{timeout} {remote}'.format(
+ timeout=retry_timeout,
+ remote=remote)
while retries > 0:
- _, output, _ = run_cmd(cmd)
- if not output:
- return False
-
- match = re.search('(\d*)% packet loss', output)
- if not match:
- return False
-
- packet_loss = int(match.group(1))
- if packet_loss == 0:
+ rc, _, _ = run_cmd(cmd)
+ if rc == 0:
return True
retries -= 1