diff options
author | Paul Larson <paul.larson@canonical.com> | 2019-09-13 12:37:39 -0500 |
---|---|---|
committer | Paul Larson <paul.larson@canonical.com> | 2019-09-13 12:37:39 -0500 |
commit | 98c72afe7246149e4cf9262da39e0a24ad62a9ad (patch) | |
tree | 9f506cf24ee5f6dc270963fd1fd40d558e550c00 /bin | |
parent | a22ffcd829e4febf94194e1f2090df9dc5d116b6 (diff) |
Attempt to get the gateway ip address for the interface and ping it before ARPing for available IPs to use in gateway_ping_test
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/gateway_ping_test | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/bin/gateway_ping_test b/bin/gateway_ping_test index 914792c..7bac0f8 100755 --- a/bin/gateway_ping_test +++ b/bin/gateway_ping_test @@ -133,6 +133,18 @@ def get_host_to_ping(interface=None, verbose=False, default=None): stderr=subprocess.STDOUT) except subprocess.CalledProcessError: pass + # Try to get the gateway address for the interface from networkctl + cmd = 'networkctl status --no-pager --no-legend {}'.format(interface) + try: + output = subprocess.check_output(cmd, shell=True) + for line in output.decode(sys.stdout.encoding).splitlines(): + key, val = line.strip().split(':', maxsplit=1) + if key == "Gateway": + subprocess.check_output(["ping", "-q", "-c", "1", val], + stderr=subprocess.STDOUT) + break + except subprocess.CalledProcessError: + pass ARP_POPULATE_TRIES = 10 num_tries = 0 while num_tries < ARP_POPULATE_TRIES: |