| OLD | NEW |
| 1 import logging, re, utils | 1 import logging, re, utils |
| 2 from autotest_lib.client.bin import test | 2 from autotest_lib.client.bin import test |
| 3 from autotest_lib.client.common_lib import error | 3 from autotest_lib.client.common_lib import error |
| 4 | 4 |
| 5 class network_DisableInterface(test.test): | 5 class network_DisableInterface(test.test): |
| 6 version = 1 | 6 version = 1 |
| 7 | 7 |
| 8 |
| 8 def run_once(self, iface_name='wlan0'): | 9 def run_once(self, iface_name='wlan0'): |
| 9 forced_up = False | |
| 10 | 10 |
| 11 # use the right interface configuration utility | 11 # use the right interface configuration utility |
| 12 self._ifconfig = 'ifconfig' | 12 self._ifconfig = 'ifconfig' |
| 13 if iface_name.startswith('hci'): | 13 if iface_name.startswith('hci'): |
| 14 self._ifconfig = 'hciconfig' | 14 self._ifconfig = 'hciconfig' |
| 15 utils.system('%s %s up' % (self._ifconfig, iface_name)) |
| 16 |
| 17 # Allow 'all' keyword - builds a list to test |
| 18 if iface_name == 'all': |
| 19 ifaces = utils.system_output('ls /sys/class/net/') |
| 20 for nic in ifaces.split(): |
| 21 if nic != 'lo' and not nic.startswith('sit'): |
| 22 self.test_one_nic(nic) |
| 23 else: |
| 24 self.test_one_nic(iface_name) |
| 25 |
| 26 |
| 27 def test_one_nic(self, iface_name='wlan0'): |
| 28 |
| 29 forced_up=False |
| 15 | 30 |
| 16 # bring up the interface if its not already up | 31 # bring up the interface if its not already up |
| 17 if not self.is_iface_up(iface_name): | 32 if not self.is_iface_up(iface_name): |
| 18 utils.system('%s %s up' % (self._ifconfig, iface_name)) | 33 utils.system('%s %s up' % (self._ifconfig, iface_name)) |
| 19 if not self.is_iface_up(iface_name): | 34 if not self.is_iface_up(iface_name): |
| 20 raise error.TestFail('interface failed to come up') | 35 raise error.TestFail('%s failed to come up' % iface_name) |
| 21 forced_up = True | 36 forced_up = True |
| 22 | 37 |
| 23 # bring interface down | 38 # bring interface down |
| 24 utils.system('%s %s down' % (self._ifconfig, iface_name)) | 39 utils.system('%s %s down' % (self._ifconfig, iface_name)) |
| 25 if self.is_iface_up(iface_name): | 40 if self.is_iface_up(iface_name): |
| 26 raise error.TestFail('interface failed to go down') | 41 raise error.TestFail('%s failed to go down' % iface_name) |
| 27 | 42 |
| 28 # if initial interface state was down, don't bring it back up | 43 # if initial interface state was down, don't bring it back up |
| 29 if forced_up: | 44 if forced_up: |
| 30 return | 45 return |
| 31 | 46 |
| 32 # bring interface back up | 47 # bring interface back up |
| 33 utils.system('%s %s up' % (self._ifconfig, iface_name)) | 48 utils.system('%s %s up' % (self._ifconfig, iface_name)) |
| 34 if not self.is_iface_up(iface_name): | 49 if not self.is_iface_up(iface_name): |
| 35 raise error.TestFail('interface failed to come up') | 50 raise error.TestFail('%s failed to come back up' % iface_name) |
| 36 | 51 |
| 37 | 52 |
| 38 def is_iface_up(self, name): | 53 def is_iface_up(self, name): |
| 39 try: | 54 try: |
| 40 out = utils.system_output('%s %s' % (self._ifconfig, name)) | 55 out = utils.system_output('%s %s' % (self._ifconfig, name)) |
| 41 except error.CmdError, e: | 56 except error.CmdError, e: |
| 42 logging.info(e) | 57 logging.info(e) |
| 43 raise error.TestNAError('test interface not found') | 58 raise error.TestNAError('"ifconfig %s" gave error %d' % (name,out) ) |
| 44 | 59 |
| 45 match = re.search('UP', out, re.S) | 60 match = re.search('UP', out, re.S) |
| 46 return match | 61 return match |
| OLD | NEW |