Home | History | Annotate | Download | only in network_NegotiatedLANSpeed
      1 import logging, re, utils
      2 from autotest_lib.client.bin import test
      3 from autotest_lib.client.common_lib import error
      4 
      5 class network_NegotiatedLANSpeed(test.test):
      6     version = 1
      7 
      8 
      9     def run_once(self, iface_name = 'eth0'):
     10         # bring up the interface if its not already up
     11         if not self.iface_up(iface_name):
     12             utils.system('ifconfig %s up' % iface_name)
     13             if not self.iface_up(iface_name):
     14                 raise error.TestFail('interface failed to come up')
     15         # confirm negotiated bandwidth is acceptable
     16         if not int(self.get_speed(iface_name)) >= 1000:
     17             raise error.TestFail('interface failed to negotiate at 1000Mbps')
     18 
     19 
     20     def iface_up(self, name):
     21         try:
     22             out = utils.system_output('ifconfig %s' % name)
     23         except error.CmdError, e:
     24             logging.info(e)
     25             raise error.TestFail('test interface not found')
     26         match = re.search('UP', out, re.S)
     27         return match
     28 
     29 
     30     def get_speed(self, name):
     31         try:
     32             out = utils.system_output('ethtool %s | grep Speed | \
     33                 sed s/^.*:.// | sed s/M.*$//' % name)
     34         except error.CmdError, e:
     35             logging.info(e)
     36             raise error.TestFail('unable to determine negotiated link speed')
     37         return out
     38