OLD | NEW |
---|---|
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 |
2 # Copyright (c) 2010, 2011 The Chromium OS Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 4 # found in the LICENSE file. |
4 | 5 |
5 import common, datetime, fnmatch, logging, os, re, string, threading, time | 6 import common, datetime, fnmatch, logging, os, re, string, threading, time |
6 | 7 |
7 from autotest_lib.server import autotest, hosts, subcommand | 8 from autotest_lib.server import autotest, hosts, subcommand |
8 from autotest_lib.server import site_bsd_router | 9 from autotest_lib.server import site_bsd_router |
9 from autotest_lib.server import site_linux_router | 10 from autotest_lib.server import site_linux_router |
11 from autotest_lib.server import site_linux_server | |
10 from autotest_lib.server import site_host_attributes | 12 from autotest_lib.server import site_host_attributes |
11 from autotest_lib.server import site_eap_certs | 13 from autotest_lib.server import site_eap_certs |
12 from autotest_lib.server import test | 14 from autotest_lib.server import test |
13 from autotest_lib.client.common_lib import error | 15 from autotest_lib.client.common_lib import error |
14 | 16 |
15 class NotImplemented(Exception): | 17 class NotImplemented(Exception): |
16 def __init__(self, what): | 18 def __init__(self, what): |
17 self.what = what | 19 self.what = what |
18 | 20 |
19 | 21 |
(...skipping 27 matching lines...) Expand all Loading... | |
47 client_monitor_stop stop monitoring for wireless system events | 49 client_monitor_stop stop monitoring for wireless system events |
48 client_check_event_* check the client's event log for an event; | 50 client_check_event_* check the client's event log for an event; |
49 should always be preceded by client_monitor_start | 51 should always be preceded by client_monitor_start |
50 sleep pause on the autotest server for a time | 52 sleep pause on the autotest server for a time |
51 client_ping ping the server on the client machine | 53 client_ping ping the server on the client machine |
52 server_ping ping the client on the server machine | 54 server_ping ping the client on the server machine |
53 client_iperf run iperf on the client to the server | 55 client_iperf run iperf on the client to the server |
54 server_iperf run iperf on the server to the client | 56 server_iperf run iperf on the server to the client |
55 client_netperf run netperf on the client to the server | 57 client_netperf run netperf on the client to the server |
56 server_netperf run netperf on the server to the client | 58 server_netperf run netperf on the server to the client |
59 vpn_launch_client launch a VPN client to connect with the | |
60 VPN server | |
57 | 61 |
58 Steps that are done on the client or server machine are implemented in | 62 Steps that are done on the client or server machine are implemented in |
59 this class. Steps that are done on the wifi router are implemented in | 63 this class. Steps that are done on the wifi router are implemented in |
60 a separate class that knows how to control the router. There are presently | 64 a separate class that knows how to control the router. There are presently |
61 two classes: BSDRouter for routers based on FreeBSD and LinuxRouter for | 65 two classes: BSDRouter for routers based on FreeBSD and LinuxRouter for |
62 those based on Linux/mac80211. Additional router support can be added | 66 those based on Linux/mac80211. Additional router support can be added |
63 by adding a new class and auto-selecting it in __init__. | 67 by adding a new class and auto-selecting it in __init__. |
64 | 68 |
65 The WiFiTest class could be generalized to handle clients other than | 69 The WiFiTest class could be generalized to handle clients other than |
66 ChromeOS; this would useful for systems that use Network Manager or | 70 ChromeOS; this would useful for systems that use Network Manager or |
67 wpa_supplicant directly. | 71 wpa_supplicant directly. |
68 """ | 72 """ |
69 | 73 |
70 def __init__(self, name, steps, config): | 74 def __init__(self, name, steps, config): |
71 self.name = name | 75 self.name = name |
72 self.steps = steps | 76 self.steps = steps |
73 self.perf_keyvals = {} | 77 self.perf_keyvals = {} |
74 | 78 |
75 self.cur_frequency = None; | 79 self.cur_frequency = None; |
76 self.cur_phymode = None; | 80 self.cur_phymode = None; |
77 self.cur_security = None; | 81 self.cur_security = None; |
78 | 82 |
79 router = config['router'] | 83 router = config['router'] |
84 # | |
85 # The server machine may be multi-homed or only on the wifi | |
86 # network. When only on the wifi net we suppress server_* | |
87 # requests since we cannot initiate them from the control machine. | |
88 # | |
89 server = config['server'] | |
90 # NB: server may not be reachable on the control network | |
91 | |
80 self.router = hosts.create_host(router['addr']) | 92 self.router = hosts.create_host(router['addr']) |
81 # NB: truncate SSID to 32 characters | 93 # NB: truncate SSID to 32 characters |
82 self.defssid = self.__get_defssid(router['addr'])[0:32] | 94 self.defssid = self.__get_defssid(router['addr'])[0:32] |
83 | 95 |
84 defaults = config.get('defaults', {}) | 96 defaults = config.get('defaults', {}) |
85 self.deftimeout = defaults.get('timeout', 30) | 97 self.deftimeout = defaults.get('timeout', 30) |
86 self.defpingcount = defaults.get('pingcount', 10) | 98 self.defpingcount = defaults.get('pingcount', 10) |
87 self.defwaittime = defaults.get('netperf_wait_time', 3) | 99 self.defwaittime = defaults.get('netperf_wait_time', 3) |
88 self.defiperfport = str(defaults.get('iperf_port', 12866)) | 100 self.defiperfport = str(defaults.get('iperf_port', 12866)) |
89 self.defnetperfport = str(defaults.get('netperf_port', 12865)) | 101 self.defnetperfport = str(defaults.get('netperf_port', 12865)) |
(...skipping 19 matching lines...) Expand all Loading... | |
109 # The address on the wifi network is retrieved each time it | 121 # The address on the wifi network is retrieved each time it |
110 # associates to the router. | 122 # associates to the router. |
111 # | 123 # |
112 client = config['client'] | 124 client = config['client'] |
113 self.client = hosts.create_host(client['addr']) | 125 self.client = hosts.create_host(client['addr']) |
114 self.client_at = autotest.Autotest(self.client) | 126 self.client_at = autotest.Autotest(self.client) |
115 self.client_wifi_ip = None # client's IP address on wifi net | 127 self.client_wifi_ip = None # client's IP address on wifi net |
116 self.client_wifi_device_path = None # client's flimflam wifi path | 128 self.client_wifi_device_path = None # client's flimflam wifi path |
117 self.client_installed_scripts = {} | 129 self.client_installed_scripts = {} |
118 | 130 |
119 # | |
120 # The server machine may be multi-homed or only on the wifi | |
121 # network. When only on the wifi net we suppress server_* | |
122 # requests since we cannot initiate them from the control machine. | |
123 # | |
124 server = config['server'] | |
125 # NB: server may not be reachable on the control network | |
126 if 'addr' in server: | 131 if 'addr' in server: |
127 self.server = hosts.create_host(server['addr']) | 132 self.server = hosts.create_host(server['addr']) |
128 self.server_at = autotest.Autotest(self.server) | 133 self.server_at = autotest.Autotest(self.server) |
129 # if not specified assume the same as the control address | 134 # if not specified assume the same as the control address |
130 self.server_wifi_ip = server.get('wifi_addr', self.server.ip) | 135 self.server_wifi_ip = server.get('wifi_addr', self.server.ip) |
131 self.__server_discover_commands(server) | 136 self.__server_discover_commands(server) |
132 else: | 137 else: |
133 self.server = None | 138 self.server = None |
134 # NB: wifi address must be set if not reachable from control | 139 # NB: wifi address must be set if not reachable from control |
135 self.server_wifi_ip = server['wifi_addr'] | 140 self.server_wifi_ip = server['wifi_addr'] |
136 | 141 |
142 # hosting_server is a machine which hosts network services, | |
143 # such as VPN. | |
144 self.hosting_server = site_linux_server.LinuxServer(self.server, server) | |
145 | |
137 # potential bg thread for ping untilstop | 146 # potential bg thread for ping untilstop |
138 self.ping_thread = None | 147 self.ping_thread = None |
139 | 148 |
140 # potential bg thread for client network monitoring | 149 # potential bg thread for client network monitoring |
141 self.client_netdump_thread = None | 150 self.client_netdump_thread = None |
142 self.__client_discover_commands(client) | 151 self.__client_discover_commands(client) |
143 self.profile_save({}) | 152 self.profile_save({}) |
144 self.firewall_rules = [] | 153 self.firewall_rules = [] |
145 | 154 |
146 # interface name on client | 155 # interface name on client |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 logging.info("%s: step '%s' (expect failure) params %s", | 264 logging.info("%s: step '%s' (expect failure) params %s", |
256 self.name, method, params) | 265 self.name, method, params) |
257 else: | 266 else: |
258 logging.info("%s: step '%s' params %s", self.name, method, | 267 logging.info("%s: step '%s' params %s", self.name, method, |
259 params) | 268 params) |
260 | 269 |
261 self.error_message = '' | 270 self.error_message = '' |
262 func = getattr(self, method, None) | 271 func = getattr(self, method, None) |
263 if func is None: | 272 if func is None: |
264 func = getattr(self.wifi, method, None) | 273 func = getattr(self.wifi, method, None) |
274 if func is None: | |
275 func = getattr(self.hosting_server, method, None) | |
265 if func is not None: | 276 if func is not None: |
266 try: | 277 try: |
267 func(params) | 278 func(params) |
268 if expect_failure is True: | 279 if expect_failure is True: |
269 expect_failure = False | 280 expect_failure = False |
270 raise error.TestFail("Expected failure") | 281 raise error.TestFail("Expected failure") |
271 except Exception, e: | 282 except Exception, e: |
272 if expect_failure is True: | 283 if expect_failure is True: |
273 if not failure_string: | 284 if not failure_string: |
274 continue | 285 continue |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 | 363 |
353 def install_files(self, params): | 364 def install_files(self, params): |
354 """ Install files on the client or router with the provided | 365 """ Install files on the client or router with the provided |
355 contents""" | 366 contents""" |
356 | 367 |
357 systemname = params.get('system', None) | 368 systemname = params.get('system', None) |
358 if systemname == 'router': | 369 if systemname == 'router': |
359 system = self.router | 370 system = self.router |
360 elif systemname == 'client': | 371 elif systemname == 'client': |
361 system = self.client | 372 system = self.client |
373 elif systemname == 'server': | |
374 system = self.server | |
362 else: | 375 else: |
363 raise error.TestFail('install_files: Must specify router or client') | 376 raise error.TestFail('install_files: Must specify router, server or client') |
364 | 377 |
365 for name,contents in params.get('files', {}).iteritems(): | 378 for name,contents in params.get('files', {}).iteritems(): |
366 self.insert_file(system, name, contents) | 379 self.insert_file(system, name, contents) |
367 | 380 |
368 | 381 |
369 def connect(self, params): | 382 def connect(self, params): |
370 """ Connect client to AP/router """ | 383 """ Connect client to AP/router """ |
371 | 384 |
372 script_client_file = self.install_script('site_wlan_connect.py', | 385 script_client_file = self.install_script('site_wlan_connect.py', |
373 'site_wlan_wait_state.py') | 386 'site_wlan_wait_state.py') |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1160 system = { 'client': self.client, | 1173 system = { 'client': self.client, |
1161 'server': self.server, | 1174 'server': self.server, |
1162 'router': self.router }.get(name) | 1175 'router': self.router }.get(name) |
1163 if not system: | 1176 if not system: |
1164 raise error.TestFail('time_sync: Must specify ' | 1177 raise error.TestFail('time_sync: Must specify ' |
1165 'router, client or server') | 1178 'router, client or server') |
1166 datefmt = '%m%d%H%M%Y.%S' if name == 'client' else '%Y%m%d%H%M.%S' | 1179 datefmt = '%m%d%H%M%Y.%S' if name == 'client' else '%Y%m%d%H%M.%S' |
1167 system.run('date -u %s' % | 1180 system.run('date -u %s' % |
1168 datetime.datetime.utcnow().strftime(datefmt)) | 1181 datetime.datetime.utcnow().strftime(datefmt)) |
1169 | 1182 |
1183 def vpn_launch_client(self, params): | |
Paul Stewart
2011/03/03 23:18:42
I suggest you call these "openvpn_*" instead of "v
| |
1184 result = self.client.run('modprobe tun'); | |
1185 # connect-vpn openvpn <name> <host> <domain> <cafile> <certfile> | |
1186 result = self.client.run('%s/test/connect-vpn openvpn ' | |
1187 'vpn-name 192.168.2.254 vpn-domain ' | |
1188 '/tmp/ca.crt ' | |
1189 '/tmp/client.crt ' | |
1190 '/tmp/client.key ' % | |
1191 self.client_cmd_flimflam_lib) | |
1192 | |
1193 def vpn_kill_client(self, params): | |
1194 """ Kill the VPN client. """ | |
1195 self.server.run("pkill openvpn") | |
1170 | 1196 |
1171 class HelperThread(threading.Thread): | 1197 class HelperThread(threading.Thread): |
1172 # Class that wraps a ping command in a thread so it can run in the bg. | 1198 # Class that wraps a ping command in a thread so it can run in the bg. |
1173 def __init__(self, client, cmd): | 1199 def __init__(self, client, cmd): |
1174 threading.Thread.__init__(self) | 1200 threading.Thread.__init__(self) |
1175 self.client = client | 1201 self.client = client |
1176 self.cmd = cmd | 1202 self.cmd = cmd |
1177 | 1203 |
1178 def run(self): | 1204 def run(self): |
1179 # NB: set ignore_status as we're always terminated w/ pkill | 1205 # NB: set ignore_status as we're always terminated w/ pkill |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1295 except error.TestFail: | 1321 except error.TestFail: |
1296 if 'expect_failure' in testcase: | 1322 if 'expect_failure' in testcase: |
1297 self.expect_failure(name, testcase['expect_failure']) | 1323 self.expect_failure(name, testcase['expect_failure']) |
1298 else: | 1324 else: |
1299 raise | 1325 raise |
1300 except Exception, e: | 1326 except Exception, e: |
1301 if 'expect_failure' in testcase: | 1327 if 'expect_failure' in testcase: |
1302 self.expect_failure(name, testcase['expect_failure']) | 1328 self.expect_failure(name, testcase['expect_failure']) |
1303 else: | 1329 else: |
1304 raise | 1330 raise |
OLD | NEW |