Home | History | Annotate | Download | only in brillo_PingTest
      1 # Copyright 2015 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import common
      6 from autotest_lib.client.common_lib import error
      7 from autotest_lib.server import test
      8 
      9 
     10 _DEFAULT_PING_HOST = 'www.google.com'
     11 _DEFAULT_PING_COUNT = 4
     12 _DEFAULT_PING_TIMEOUT = 4
     13 
     14 
     15 class brillo_PingTest(test.test):
     16     """Ping an Internet host."""
     17     version = 1
     18 
     19     def run_once(self, host=None, ping_host=_DEFAULT_PING_HOST,
     20                  ping_count=_DEFAULT_PING_COUNT,
     21                  ping_timeout=_DEFAULT_PING_TIMEOUT):
     22         """Pings an Internet host with given timeout and count values.
     23 
     24         @param host: A host object representing the DUT.
     25         @param ping_host: The Internet host to ping.
     26         @param ping_count: The number of pings to attempt. The test passes if
     27                            we get at least one reply.
     28         @param ping_timeout: The number of seconds to wait for a reply.
     29 
     30         @raise TestFail: The test failed.
     31         """
     32         cmd = 'ping -q -c %s -W %s %s' % (ping_count, ping_timeout, ping_host)
     33         try:
     34             host.run(cmd)
     35         except error.AutoservRunError:
     36             raise error.TestFail(
     37                     'Failed to ping %s in %d seconds on all %d attempts' %
     38                     (ping_host, ping_timeout, ping_count))
     39