Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: server/site_wifitest.py

Issue 6689026: Add a route backwards from the DUT to the test host (Closed) Base URL: http://git.chromium.org/git/autotest.git@master
Patch Set: Rework comment Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « server/site_host_route.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 = {}
167 step_names = [step[0] for step in steps] 169 step_names = [step[0] for step in steps]
168 for step_name in list(set(step_names)): 170 for step_name in list(set(step_names)):
169 if step_names.count(step_name) > 1: 171 if step_names.count(step_name) > 1:
170 self.iterated_steps[step_name] = 0 172 self.iterated_steps[step_name] = 0
171 173
172 def cleanup(self, params): 174 def cleanup(self, params):
173 """ Cleanup state: disconnect client and destroy ap """ 175 """ Cleanup state: disconnect client and destroy ap """
174 if params.get('force_disconnect'): 176 if params.get('force_disconnect'):
175 self.disconnect({}) 177 self.disconnect({})
176 self.wifi.destroy({}) 178 self.wifi.destroy({})
177 self.profile_cleanup({}) 179 self.profile_cleanup({})
178 self.client_netdump_stop({}) 180 self.client_netdump_stop({})
179 self.firewall_cleanup({}) 181 self.firewall_cleanup({})
182 self.host_route_cleanup({})
180 183
181 184
182 def __must_be_installed(self, host, cmd): 185 def __must_be_installed(self, host, cmd):
183 if not self.__is_installed(host, cmd): 186 if not self.__is_installed(host, cmd):
184 # TODO(sleffler): temporary debugging 187 # TODO(sleffler): temporary debugging
185 host.run("ls -a /usr/bin /usr/local/bin" % cmd, ignore_status=True) 188 host.run("ls -a /usr/bin /usr/local/bin" % cmd, ignore_status=True)
186 raise error.TestFail('Unable to find %s on %s' % (cmd, host.ip)) 189 raise error.TestFail('Unable to find %s on %s' % (cmd, host.ip))
187 return cmd 190 return cmd
188 191
189 192
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 If not specified, the default is 'none'. 1226 If not specified, the default is 'none'.
1224 The value provided is passed directly to 'connect-vpn'. 1227 The value provided is passed directly to 'connect-vpn'.
1225 """ 1228 """
1226 self.vpn_client_kill({}) # Must be first. Relies on self.vpn_kind. 1229 self.vpn_client_kill({}) # Must be first. Relies on self.vpn_kind.
1227 self.vpn_kind = params.get('kind', None) 1230 self.vpn_kind = params.get('kind', None)
1228 vpn_host_ip = params.get('vpn-host-ip', self.server_wifi_ip) 1231 vpn_host_ip = params.get('vpn-host-ip', self.server_wifi_ip)
1229 1232
1230 # Must get 'ca_certificate', 'client-certificate' and 'client-key'. 1233 # Must get 'ca_certificate', 'client-certificate' and 'client-key'.
1231 cert_pathnames = params.get('files', {}) 1234 cert_pathnames = params.get('files', {})
1232 1235
1236 # Starting up the VPN client may cause the DUT's routing table (esp.
1237 # the default route) to change. Set up a host route backwards so
thutt 2011/04/01 22:01:56 Thanks, that looks great.
1238 # we don't lose our control connection in htat event.
1239 __add_host_route(self.client)
1240
1233 if self.vpn_kind is None: 1241 if self.vpn_kind is None:
1234 raise error.TestFail('No VPN kind specified for this test.') 1242 raise error.TestFail('No VPN kind specified for this test.')
1235 elif self.vpn_kind == 'openvpn': 1243 elif self.vpn_kind == 'openvpn':
1236 remote_cert_tls_option = "" 1244 remote_cert_tls_option = ""
1237 remote_cert_tls = params.get('remote-cert-tls', None) 1245 remote_cert_tls = params.get('remote-cert-tls', None)
1238 1246
1239 if remote_cert_tls is not None: 1247 if remote_cert_tls is not None:
1240 remote_cert_tls_option = "--remote-cert-tls " + remote_cert_tls 1248 remote_cert_tls_option = "--remote-cert-tls " + remote_cert_tls
1241 1249
1242 # connect-vpn openvpn [options] <name> <host-ip> <domain> \ 1250 # connect-vpn openvpn [options] <name> <host-ip> <domain> \
(...skipping 18 matching lines...) Expand all
1261 def vpn_client_kill(self, params): 1269 def vpn_client_kill(self, params):
1262 """ Kill the VPN client if it's running. """ 1270 """ Kill the VPN client if it's running. """
1263 if self.vpn_kind is not None: 1271 if self.vpn_kind is not None:
1264 if self.vpn_kind == 'openvpn': 1272 if self.vpn_kind == 'openvpn':
1265 self.client.run("pkill openvpn") 1273 self.client.run("pkill openvpn")
1266 else: 1274 else:
1267 raise error.TestFail('(internal error): No kill case ' 1275 raise error.TestFail('(internal error): No kill case '
1268 'for VPN kind (%s)' % self.vpn_kind) 1276 'for VPN kind (%s)' % self.vpn_kind)
1269 self.vpn_kind = None 1277 self.vpn_kind = None
1270 1278
1279 __del_host_route(self.client)
1280
1281 def __add_host_route(self, host):
1282 # What is the local address we use to get to the test host?
1283 local_ip = site_host_route.LocalHostRoute(host.ip).route_info["src"]
1284
1285 # How does the test host currently get to this local address?
1286 host_route = site_host_route.RemoteHostRoute(host, local_ip).route_info
1287
1288 # Flatten the returned dict into a single string
1289 route_args = " ".join(" ".join(x) for x in host_route.iteritems())
1290
1291 self.host_route_args[host.ip] = "%s %s" % (local_ip, route_args)
1292 host.run("ip route add %s" % self.host_route_args[host.ip])
1293
1294 def __del_host_route(self, host):
1295 if host.ip not in self.host_route_args:
1296 return
1297
1298 host.run("ip route del %s" % self.host_route_args.pop(host.ip))
1299
1300 def host_route_cleanup(self, params):
1301 for host in (self.client, self.server, self.router):
1302 self.__del_host_route(host)
1303
1304
1271 class HelperThread(threading.Thread): 1305 class HelperThread(threading.Thread):
1272 # Class that wraps a ping command in a thread so it can run in the bg. 1306 # Class that wraps a ping command in a thread so it can run in the bg.
1273 def __init__(self, client, cmd): 1307 def __init__(self, client, cmd):
1274 threading.Thread.__init__(self) 1308 threading.Thread.__init__(self)
1275 self.client = client 1309 self.client = client
1276 self.cmd = cmd 1310 self.cmd = cmd
1277 1311
1278 def run(self): 1312 def run(self):
1279 # NB: set ignore_status as we're always terminated w/ pkill 1313 # NB: set ignore_status as we're always terminated w/ pkill
1280 self.result = self.client.run(self.cmd, ignore_status=True) 1314 self.result = self.client.run(self.cmd, ignore_status=True)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 except error.TestFail: 1429 except error.TestFail:
1396 if 'expect_failure' in testcase: 1430 if 'expect_failure' in testcase:
1397 self.expect_failure(name, testcase['expect_failure']) 1431 self.expect_failure(name, testcase['expect_failure'])
1398 else: 1432 else:
1399 raise 1433 raise
1400 except Exception, e: 1434 except Exception, e:
1401 if 'expect_failure' in testcase: 1435 if 'expect_failure' in testcase:
1402 self.expect_failure(name, testcase['expect_failure']) 1436 self.expect_failure(name, testcase['expect_failure'])
1403 else: 1437 else:
1404 raise 1438 raise
OLDNEW
« no previous file with comments | « server/site_host_route.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698