| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import common, fnmatch, logging, os, re, string, threading, time | 5 import common, fnmatch, logging, os, re, string, threading, time |
| 6 | 6 |
| 7 from autotest_lib.server import autotest, hosts, subcommand | 7 from autotest_lib.server import autotest, hosts, subcommand |
| 8 from autotest_lib.server import site_bsd_router | 8 from autotest_lib.server import site_bsd_router |
| 9 from autotest_lib.server import site_linux_router | 9 from autotest_lib.server import site_linux_router |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 by adding a new class and auto-selecting it in __init__. | 59 by adding a new class and auto-selecting it in __init__. |
| 60 | 60 |
| 61 The WiFiTest class could be generalized to handle clients other than | 61 The WiFiTest class could be generalized to handle clients other than |
| 62 ChromeOS; this would useful for systems that use Network Manager or | 62 ChromeOS; this would useful for systems that use Network Manager or |
| 63 wpa_supplicant directly. | 63 wpa_supplicant directly. |
| 64 """ | 64 """ |
| 65 | 65 |
| 66 def __init__(self, name, steps, config): | 66 def __init__(self, name, steps, config): |
| 67 self.name = name | 67 self.name = name |
| 68 self.steps = steps | 68 self.steps = steps |
| 69 |
| 69 router = config['router'] | 70 router = config['router'] |
| 70 | |
| 71 self.router = hosts.create_host(router['addr']) | 71 self.router = hosts.create_host(router['addr']) |
| 72 # NB: truncate SSID to 32 characters | 72 # NB: truncate SSID to 32 characters |
| 73 self.defssid = self.__get_defssid(router['addr'])[0:32] | 73 self.defssid = self.__get_defssid(router['addr'])[0:32] |
| 74 | 74 |
| 75 if 'type' not in router: | 75 if 'type' not in router: |
| 76 # auto-detect router type | 76 # auto-detect router type |
| 77 if site_linux_router.isLinuxRouter(self.router): | 77 if site_linux_router.isLinuxRouter(self.router): |
| 78 router['type'] = 'linux' | 78 router['type'] = 'linux' |
| 79 elif site_bsd_router.isBSDRouter(self.router): | 79 elif site_bsd_router.isBSDRouter(self.router): |
| 80 router['type'] = 'bsd' | 80 router['type'] = 'bsd' |
| 81 else: | 81 else: |
| 82 raise Exception('Unable to autodetect router type') | 82 raise error.TestFail('Unable to autodetect router type') |
| 83 if router['type'] == 'linux': | 83 if router['type'] == 'linux': |
| 84 self.wifi = site_linux_router.LinuxRouter(self.router, router, | 84 self.wifi = site_linux_router.LinuxRouter(self.router, router, |
| 85 self.defssid) | 85 self.defssid) |
| 86 elif router['type'] == 'bsd': | 86 elif router['type'] == 'bsd': |
| 87 self.wifi = site_bsd_router.BSDRouter(self.router, router, | 87 self.wifi = site_bsd_router.BSDRouter(self.router, router, |
| 88 self.defssid) | 88 self.defssid) |
| 89 else: | 89 else: |
| 90 raise Exception('Unsupported router') | 90 raise error.TestFail('Unsupported router') |
| 91 | 91 |
| 92 # | 92 # |
| 93 # The client machine must be reachable from the control machine. | 93 # The client machine must be reachable from the control machine. |
| 94 # The address on the wifi network is retrieved each time it | 94 # The address on the wifi network is retrieved each time it |
| 95 # associates to the router. | 95 # associates to the router. |
| 96 # | 96 # |
| 97 client = config['client'] | 97 client = config['client'] |
| 98 self.client = hosts.create_host(client['addr']) | 98 self.client = hosts.create_host(client['addr']) |
| 99 self.client_at = autotest.Autotest(self.client) | 99 self.client_at = autotest.Autotest(self.client) |
| 100 self.client_wifi_ip = None # client's IP address on wifi net | 100 self.client_wifi_ip = None # client's IP address on wifi net |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 func = getattr(self, method, None) | 154 func = getattr(self, method, None) |
| 155 if func is None: | 155 if func is None: |
| 156 func = getattr(self.wifi, method, None) | 156 func = getattr(self.wifi, method, None) |
| 157 if func is not None: | 157 if func is not None: |
| 158 try: | 158 try: |
| 159 func(params) | 159 func(params) |
| 160 except Exception, e: | 160 except Exception, e: |
| 161 logging.error("%s: Step '%s' failed: %s; abort test", | 161 logging.error("%s: Step '%s' failed: %s; abort test", |
| 162 self.name, method, str(e)) | 162 self.name, method, str(e)) |
| 163 self.cleanup(params) | 163 self.cleanup(params) |
| 164 raise e |
| 164 break | 165 break |
| 165 else: | 166 else: |
| 166 logging.error("%s: Step '%s' unknown; abort test", | 167 logging.error("%s: Step '%s' unknown; abort test", |
| 167 self.name, method) | 168 self.name, method) |
| 168 self.cleanup(params) | 169 self.cleanup(params) |
| 169 break | 170 break |
| 170 | 171 |
| 171 | 172 |
| 172 def __get_connect_script(self, params): | 173 def __get_connect_script(self, params): |
| 173 # Something is off in our current setup so we'll set the assoc_timeout | 174 # Something is off in our current setup so we'll set the assoc_timeout |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 sys.exit(6) | 247 sys.exit(6) |
| 247 print "assoc %3.1f secs config %3.1f secs" % (assoc_time, config_time) | 248 print "assoc %3.1f secs config %3.1f secs" % (assoc_time, config_time) |
| 248 sys.exit(0)''' | 249 sys.exit(0)''' |
| 249 | 250 |
| 250 | 251 |
| 251 def __get_ipaddr(self, host, ifnet): | 252 def __get_ipaddr(self, host, ifnet): |
| 252 # XXX gotta be a better way to do this | 253 # XXX gotta be a better way to do this |
| 253 result = host.run("ifconfig %s" % ifnet) | 254 result = host.run("ifconfig %s" % ifnet) |
| 254 m = re.search('inet addr:([^ ]*)', result.stdout) | 255 m = re.search('inet addr:([^ ]*)', result.stdout) |
| 255 if m is None: | 256 if m is None: |
| 256 raise Except, "No inet address found" | 257 raise error.TestFail("No inet address found") |
| 257 return m.group(1) | 258 return m.group(1) |
| 258 | 259 |
| 259 | 260 |
| 260 def connect(self, params): | 261 def connect(self, params): |
| 261 """ Connect client to AP/router """ | 262 """ Connect client to AP/router """ |
| 262 if 'ssid' not in params: | 263 if 'ssid' not in params: |
| 263 params['ssid'] = self.defssid | 264 params['ssid'] = self.defssid |
| 264 script = self.__get_connect_script(params) | 265 script = self.__get_connect_script(params) |
| 265 result = self.client.run("python<<'EOF'\n%s\nEOF\n" % script) | 266 result = self.client.run("python<<'EOF'\n%s\nEOF\n" % script) |
| 266 print "%s: %s" % (self.name, result.stdout[0:-1]) | 267 print "%s: %s" % (self.name, result.stdout[0:-1]) |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 670 |
| 670 server = config['server'] | 671 server = config['server'] |
| 671 if server_addr is not None: | 672 if server_addr is not None: |
| 672 server['addr'] = server_addr; | 673 server['addr'] = server_addr; |
| 673 # TODO(sleffler) check for wifi_addr when no control address | 674 # TODO(sleffler) check for wifi_addr when no control address |
| 674 | 675 |
| 675 # tag jobs w/ the router's address on the control network | 676 # tag jobs w/ the router's address on the control network |
| 676 config['tagname'] = router['addr'] | 677 config['tagname'] = router['addr'] |
| 677 | 678 |
| 678 return config | 679 return config |
| OLD | NEW |