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 from autotest_lib.server import site_host_attributes | 10 from autotest_lib.server import site_host_attributes |
11 from autotest_lib.server import site_eap_tls | 11 from autotest_lib.server import site_eap_certs |
12 from autotest_lib.server import test | 12 from autotest_lib.server import test |
13 from autotest_lib.client.common_lib import error | 13 from autotest_lib.client.common_lib import error |
14 | 14 |
15 class NotImplemented(Exception): | 15 class NotImplemented(Exception): |
16 def __init__(self, what): | 16 def __init__(self, what): |
17 self.what = what | 17 self.what = what |
18 | 18 |
19 | 19 |
20 def __str__(self): | 20 def __str__(self): |
21 return repr("Test method '%s' not implemented" % self.what) | 21 return repr("Test method '%s' not implemented" % self.what) |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 script_client_file = os.path.join(script_client_dir, script_name) | 313 script_client_file = os.path.join(script_client_dir, script_name) |
314 for copy_file in [script_name] + list(support_scripts): | 314 for copy_file in [script_name] + list(support_scripts): |
315 src_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), | 315 src_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), |
316 copy_file) | 316 copy_file) |
317 dest_file = os.path.join(script_client_dir, | 317 dest_file = os.path.join(script_client_dir, |
318 os.path.basename(src_file)) | 318 os.path.basename(src_file)) |
319 self.client.send_file(src_file, dest_file, delete_dest=True) | 319 self.client.send_file(src_file, dest_file, delete_dest=True) |
320 self.client_installed_scripts[script_name] = script_client_file | 320 self.client_installed_scripts[script_name] = script_client_file |
321 return script_client_file | 321 return script_client_file |
322 | 322 |
| 323 def insert_file(self, host, filename, contents): |
| 324 """ |
| 325 If config files are too big, the "host.run()" never returns. |
| 326 As a workaround, break the file up into lines and append the |
| 327 file piece by piece |
| 328 """ |
| 329 host.run('rm -f %s >/dev/null 2>&1' % filename, ignore_status=True) |
| 330 content_lines = contents.splitlines() |
| 331 while content_lines: |
| 332 buflist = [] |
| 333 buflen = 0 |
| 334 while content_lines and buflen + len(content_lines[0]) < 200: |
| 335 line = content_lines.pop(0) |
| 336 buflen += len(line) + 1 |
| 337 buflist.append(line) |
| 338 |
| 339 if not buflist: |
| 340 raise error.TestFail('Cert profile: line too long: %s' % |
| 341 content_lines[0]) |
| 342 host.run('cat <<EOF >>%s\n%s\nEOF\n' % |
| 343 (filename, '\n'.join(buflist))) |
| 344 |
| 345 def install_files(self, params): |
| 346 """ Install files on the client or router with the provided |
| 347 contents""" |
| 348 |
| 349 systemname = params.get('system', None) |
| 350 if systemname == 'router': |
| 351 system = self.router |
| 352 elif systemname == 'client': |
| 353 system = self.client |
| 354 else: |
| 355 raise error.TestFail('install_files: Must specify router or client') |
| 356 |
| 357 for name,contents in params.get('files', {}).iteritems(): |
| 358 self.insert_file(system, name, contents) |
| 359 |
323 | 360 |
324 def connect(self, params): | 361 def connect(self, params): |
325 """ Connect client to AP/router """ | 362 """ Connect client to AP/router """ |
326 | 363 |
327 script_client_file = self.install_script('site_wlan_connect.py', | 364 script_client_file = self.install_script('site_wlan_connect.py', |
328 'site_wlan_wait_state.py') | 365 'site_wlan_wait_state.py') |
329 if 'eap-tls' in params: | |
330 params.update(site_eap_tls.client_config(self.client, | |
331 params['eap-tls'], | |
332 params.get('server-auth', | |
333 None))) | |
334 | 366 |
335 flags = [] | 367 flags = [] |
336 if params.get('debug', True): | 368 if params.get('debug', True): |
337 flags.append('--debug') | 369 flags.append('--debug') |
338 if params.get('hidden', False): | 370 if params.get('hidden', False): |
339 flags.append('--hidden') | 371 flags.append('--hidden') |
340 | 372 |
341 result = self.client.run('python "%s" %s "%s" "%s" "%s" "%d" "%d"' % | 373 result = self.client.run('python "%s" %s "%s" "%s" "%s" "%d" "%d"' % |
342 (script_client_file, | 374 (script_client_file, |
343 ' '.join(flags), | 375 ' '.join(flags), |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 except error.TestFail: | 1206 except error.TestFail: |
1175 if 'expect_failure' in testcase: | 1207 if 'expect_failure' in testcase: |
1176 self.expect_failure(name, testcase['expect_failure']) | 1208 self.expect_failure(name, testcase['expect_failure']) |
1177 else: | 1209 else: |
1178 raise | 1210 raise |
1179 except Exception, e: | 1211 except Exception, e: |
1180 if 'expect_failure' in testcase: | 1212 if 'expect_failure' in testcase: |
1181 self.expect_failure(name, testcase['expect_failure']) | 1213 self.expect_failure(name, testcase['expect_failure']) |
1182 else: | 1214 else: |
1183 raise | 1215 raise |
OLD | NEW |