Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2011 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, datetime, fnmatch, logging, os, re, string, threading, time | 5 import common, datetime, 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_linux_server | 10 from autotest_lib.server import site_linux_server |
| 11 from autotest_lib.server import site_host_attributes | 11 from autotest_lib.server import site_host_attributes |
| 12 from autotest_lib.server import site_host_route | |
| 12 from autotest_lib.server import site_eap_certs | 13 from autotest_lib.server import site_eap_certs |
| 13 from autotest_lib.server import test | 14 from autotest_lib.server import test |
| 14 from autotest_lib.client.common_lib import error | 15 from autotest_lib.client.common_lib import error |
| 15 | 16 |
| 16 class NotImplemented(Exception): | 17 class NotImplemented(Exception): |
| 17 def __init__(self, what): | 18 def __init__(self, what): |
| 18 self.what = what | 19 self.what = what |
| 19 | 20 |
| 20 | 21 |
| 21 def __str__(self): | 22 def __str__(self): |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 self.hosting_server = site_linux_server.LinuxServer(self.server, server) | 148 self.hosting_server = site_linux_server.LinuxServer(self.server, server) |
| 148 | 149 |
| 149 # potential bg thread for ping untilstop | 150 # potential bg thread for ping untilstop |
| 150 self.ping_thread = None | 151 self.ping_thread = None |
| 151 | 152 |
| 152 # potential bg thread for client network monitoring | 153 # potential bg thread for client network monitoring |
| 153 self.client_netdump_thread = None | 154 self.client_netdump_thread = None |
| 154 self.__client_discover_commands(client) | 155 self.__client_discover_commands(client) |
| 155 self.profile_save({}) | 156 self.profile_save({}) |
| 156 self.firewall_rules = [] | 157 self.firewall_rules = [] |
| 158 self.host_route_args = {} | |
| 157 | 159 |
| 158 # interface name on client | 160 # interface name on client |
| 159 self.client_wlanif = client.get('wlandev', | 161 self.client_wlanif = client.get('wlandev', |
| 160 self.__get_wlan_devs(self.client)[0]) | 162 self.__get_wlan_devs(self.client)[0]) |
| 161 | 163 |
| 162 # Synchronize time on all devices | 164 # Synchronize time on all devices |
| 163 self.time_sync([]) | 165 self.time_sync([]) |
| 164 | 166 |
| 165 # Find all repeated steps and create iterators for them | 167 # Find all repeated steps and create iterators for them |
| 166 self.iterated_steps = {} | 168 self.iterated_steps = {} |
| (...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1223 If not specified, the default is 'none'. | 1225 If not specified, the default is 'none'. |
| 1224 The value provided is passed directly to 'connect-vpn'. | 1226 The value provided is passed directly to 'connect-vpn'. |
| 1225 """ | 1227 """ |
| 1226 self.vpn_client_kill({}) # Must be first. Relies on self.vpn_kind. | 1228 self.vpn_client_kill({}) # Must be first. Relies on self.vpn_kind. |
| 1227 self.vpn_kind = params.get('kind', None) | 1229 self.vpn_kind = params.get('kind', None) |
| 1228 vpn_host_ip = params.get('vpn-host-ip', self.server_wifi_ip) | 1230 vpn_host_ip = params.get('vpn-host-ip', self.server_wifi_ip) |
| 1229 | 1231 |
| 1230 # Must get 'ca_certificate', 'client-certificate' and 'client-key'. | 1232 # Must get 'ca_certificate', 'client-certificate' and 'client-key'. |
| 1231 cert_pathnames = params.get('files', {}) | 1233 cert_pathnames = params.get('files', {}) |
| 1232 | 1234 |
| 1235 # Set up a host route on the DUT so that the VPN doesn't prevent us | |
|
thutt
2011/04/01 21:43:06
Can you make this comment more clear? It's rather
| |
| 1236 # from having IP traffic from it return to us | |
|
thutt
2011/04/01 21:43:06
This comment too.
In my implementation, I split th
Paul Stewart
2011/04/01 21:52:45
Feel free to move it where you'd like, and change
| |
| 1237 __add_host_route(self.client) | |
| 1238 | |
| 1233 if self.vpn_kind is None: | 1239 if self.vpn_kind is None: |
| 1234 raise error.TestFail('No VPN kind specified for this test.') | 1240 raise error.TestFail('No VPN kind specified for this test.') |
| 1235 elif self.vpn_kind == 'openvpn': | 1241 elif self.vpn_kind == 'openvpn': |
| 1236 remote_cert_tls_option = "" | 1242 remote_cert_tls_option = "" |
| 1237 remote_cert_tls = params.get('remote-cert-tls', None) | 1243 remote_cert_tls = params.get('remote-cert-tls', None) |
| 1238 | 1244 |
| 1239 if remote_cert_tls is not None: | 1245 if remote_cert_tls is not None: |
| 1240 remote_cert_tls_option = "--remote-cert-tls " + remote_cert_tls | 1246 remote_cert_tls_option = "--remote-cert-tls " + remote_cert_tls |
| 1241 | 1247 |
| 1242 # connect-vpn openvpn [options] <name> <host-ip> <domain> \ | 1248 # connect-vpn openvpn [options] <name> <host-ip> <domain> \ |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1261 def vpn_client_kill(self, params): | 1267 def vpn_client_kill(self, params): |
| 1262 """ Kill the VPN client if it's running. """ | 1268 """ Kill the VPN client if it's running. """ |
| 1263 if self.vpn_kind is not None: | 1269 if self.vpn_kind is not None: |
| 1264 if self.vpn_kind == 'openvpn': | 1270 if self.vpn_kind == 'openvpn': |
| 1265 self.client.run("pkill openvpn") | 1271 self.client.run("pkill openvpn") |
| 1266 else: | 1272 else: |
| 1267 raise error.TestFail('(internal error): No kill case ' | 1273 raise error.TestFail('(internal error): No kill case ' |
| 1268 'for VPN kind (%s)' % self.vpn_kind) | 1274 'for VPN kind (%s)' % self.vpn_kind) |
| 1269 self.vpn_kind = None | 1275 self.vpn_kind = None |
| 1270 | 1276 |
| 1277 __del_host_route(self.client) | |
| 1278 | |
| 1279 def __add_host_route(self, host): | |
| 1280 # What is the local address we use to get to the test host? | |
| 1281 local_ip = site_host_route.LocalHostRoute(host.ip).route_info["src"] | |
| 1282 | |
| 1283 # How does the test host currently get to this local address? | |
| 1284 host_route = site_host_route.RemoteHostRoute(host, local_ip).route_info | |
| 1285 | |
| 1286 # Flatten the returned dict into a single string | |
| 1287 route_args = " ".join(" ".join(x) for x in host_route.iteritems()) | |
| 1288 | |
| 1289 self.host_route_args[host.ip] = "%s %s" % (local_ip, route_args) | |
| 1290 host.run("ip route add %s" % self.host_route_args[host.ip]) | |
| 1291 | |
| 1292 def __del_host_route(self, host): | |
| 1293 if host.ip not in self.host_route_args: | |
| 1294 return | |
| 1295 | |
| 1296 host.run("ip route del %s" % self.host_route_args.pop(host.ip)) | |
| 1297 | |
| 1298 | |
| 1271 class HelperThread(threading.Thread): | 1299 class HelperThread(threading.Thread): |
| 1272 # Class that wraps a ping command in a thread so it can run in the bg. | 1300 # Class that wraps a ping command in a thread so it can run in the bg. |
| 1273 def __init__(self, client, cmd): | 1301 def __init__(self, client, cmd): |
| 1274 threading.Thread.__init__(self) | 1302 threading.Thread.__init__(self) |
| 1275 self.client = client | 1303 self.client = client |
| 1276 self.cmd = cmd | 1304 self.cmd = cmd |
| 1277 | 1305 |
| 1278 def run(self): | 1306 def run(self): |
| 1279 # NB: set ignore_status as we're always terminated w/ pkill | 1307 # NB: set ignore_status as we're always terminated w/ pkill |
| 1280 self.result = self.client.run(self.cmd, ignore_status=True) | 1308 self.result = self.client.run(self.cmd, ignore_status=True) |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1395 except error.TestFail: | 1423 except error.TestFail: |
| 1396 if 'expect_failure' in testcase: | 1424 if 'expect_failure' in testcase: |
| 1397 self.expect_failure(name, testcase['expect_failure']) | 1425 self.expect_failure(name, testcase['expect_failure']) |
| 1398 else: | 1426 else: |
| 1399 raise | 1427 raise |
| 1400 except Exception, e: | 1428 except Exception, e: |
| 1401 if 'expect_failure' in testcase: | 1429 if 'expect_failure' in testcase: |
| 1402 self.expect_failure(name, testcase['expect_failure']) | 1430 self.expect_failure(name, testcase['expect_failure']) |
| 1403 else: | 1431 else: |
| 1404 raise | 1432 raise |
| OLD | NEW |