blob: cfccf1fc06daf42fbb1e8aa0fc1b801005d0e298 [file] [log] [blame]
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
from autotest_lib.client.bin import test, utils
from autotest_lib.client.common_lib import error
class network_Ping(test.test):
"""
Verify we can ping internal and external hosts.
"""
version = 1
def get_gateway(self):
"""Determine the IP address of the default gateway.
Returns:
string, dotted ip address of gateway.
"""
cmd = 'ip route'
output = utils.system_output('%s' % cmd)
linesout = output.split('\n')
for line in linesout:
if 'default' in line:
s = line.split()
ipaddress = s[2]
if ipaddress:
return ipaddress
else:
logging.error('Error determining default gateway!')
return None
def run_once(self):
errors = 0
remote_hosts = ['www.google.com']
default_gateway = self.get_gateway()
if default_gateway:
remote_hosts.append(default_gateway)
else:
raise error.TestFail('Failure to get default gateway!')
for rhost in remote_hosts:
if utils.ping(rhost, tries=5):
logging.error('Error pinging %s' % rhost)
errors += 1
if errors:
raise error.TestFail('%d failures pinging %d hosts' % (
errors, len(remote_hosts)))