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

Side by Side Diff: server/site_wifitest.py

Issue 6765030: Add automated StrongSwan test (Closed) Base URL: ssh://gitrw.chromium.org:9222/autotest.git@master
Patch Set: After fixing all merge issues from Paul 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
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
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 self.server = hosts.create_host(server['addr']) 136 self.server = hosts.create_host(server['addr'])
137 self.server_at = autotest.Autotest(self.server) 137 self.server_at = autotest.Autotest(self.server)
138 # if not specified assume the same as the control address 138 # if not specified assume the same as the control address
139 self.server_wifi_ip = server.get('wifi_addr', self.server.ip) 139 self.server_wifi_ip = server.get('wifi_addr', self.server.ip)
140 self.__server_discover_commands(server) 140 self.__server_discover_commands(server)
141 else: 141 else:
142 self.server = None 142 self.server = None
143 # NB: wifi address must be set if not reachable from control 143 # NB: wifi address must be set if not reachable from control
144 self.server_wifi_ip = server['wifi_addr'] 144 self.server_wifi_ip = server['wifi_addr']
145 145
146 # hosting_server is a machine which hosts network services, 146 # The 'hosting_server' is a machine which hosts network
147 # such as VPN. 147 # services, such as OpenVPN or StrongSwan.
148 self.hosting_server = site_linux_server.LinuxServer(self.server, server) 148 self.hosting_server = site_linux_server.LinuxServer(self.server, server)
149 149
150 # potential bg thread for ping untilstop 150 # potential bg thread for ping untilstop
151 self.ping_thread = None 151 self.ping_thread = None
152 152
153 # potential bg thread for client network monitoring 153 # potential bg thread for client network monitoring
154 self.client_netdump_thread = None 154 self.client_netdump_thread = None
155 self.__client_discover_commands(client) 155 self.__client_discover_commands(client)
156 self.profile_create({'name':'test'}) 156 self.profile_create({'name':'test'})
157 self.profile_push({'name':'test'}) 157 self.profile_push({'name':'test'})
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 'remote-cert-tls' : optional 1233 'remote-cert-tls' : optional
1234 If provided, this option can be 'server', 'client' or 1234 If provided, this option can be 'server', 'client' or
1235 'none'. 1235 'none'.
1236 If not specified, the default is 'none'. 1236 If not specified, the default is 'none'.
1237 The value provided is passed directly to 'connect-vpn'. 1237 The value provided is passed directly to 'connect-vpn'.
1238 """ 1238 """
1239 self.vpn_client_kill({}) # Must be first. Relies on self.vpn_kind. 1239 self.vpn_client_kill({}) # Must be first. Relies on self.vpn_kind.
1240 self.vpn_kind = params.get('kind', None) 1240 self.vpn_kind = params.get('kind', None)
1241 vpn_host_ip = params.get('vpn-host-ip', self.server_wifi_ip) 1241 vpn_host_ip = params.get('vpn-host-ip', self.server_wifi_ip)
1242 1242
1243 # Must get 'ca_certificate', 'client-certificate' and 'client-key'.
1244 cert_pathnames = params.get('files', {})
1245
1246 # Starting up the VPN client may cause the DUT's routing table (esp. 1243 # Starting up the VPN client may cause the DUT's routing table (esp.
1247 # the default route) to change. Set up a host route backwards so 1244 # the default route) to change. Set up a host route backwards so
1248 # we don't lose our control connection in that event. 1245 # we don't lose our control connection in that event.
1249 __add_host_route(self.client) 1246 self.__add_host_route(self.client)
1250 1247
1251 if self.vpn_kind is None: 1248 if self.vpn_kind is None:
1252 raise error.TestFail('No VPN kind specified for this test.') 1249 raise error.TestFail('No VPN kind specified for this test.')
1253 elif self.vpn_kind == 'openvpn': 1250 elif self.vpn_kind == 'openvpn':
1251 # 'ca_certificate', 'client-certificate' and 'client-key'.
1252 cert_pathnames = params.get('files', {})
1254 remote_cert_tls_option = "" 1253 remote_cert_tls_option = ""
1255 remote_cert_tls = params.get('remote-cert-tls', None) 1254 remote_cert_tls = params.get('remote-cert-tls', None)
1256 1255
1257 if remote_cert_tls is not None: 1256 if remote_cert_tls is not None:
1258 remote_cert_tls_option = "--remote-cert-tls " + remote_cert_tls 1257 remote_cert_tls_option = "--remote-cert-tls " + remote_cert_tls
1259 1258
1260 # connect-vpn openvpn [options] <name> <host-ip> <domain> \
1261 # <cafile> <certfile> <key-file>
1262 result = self.client.run('%s/test/connect-vpn ' 1259 result = self.client.run('%s/test/connect-vpn '
1263 '--verbose ' 1260 '--verbose '
1264 '%s ' 1261 '%s '
1265 'openvpn vpn-name %s vpn-domain ' 1262 'openvpn vpn-name %s vpn-domain '
1266 '%s ' # ca certificate 1263 '%s ' # ca certificate
1267 '%s ' # client certificate 1264 '%s ' # client certificate
1268 '%s' % # client key 1265 '%s' % # client key
1269 (self.client_cmd_flimflam_lib, 1266 (self.client_cmd_flimflam_lib,
1270 remote_cert_tls_option, 1267 remote_cert_tls_option,
1271 vpn_host_ip, 1268 vpn_host_ip,
1272 cert_pathnames['ca-certificate'], 1269 cert_pathnames['ca-certificate'],
1273 cert_pathnames['client-certificate'], 1270 cert_pathnames['client-certificate'],
1274 cert_pathnames['client-key'])) 1271 cert_pathnames['client-key']))
1272 elif self.vpn_kind == 'l2tpipsec-psk': # aka 'strongswan'
1273 result = self.client.run('%s/test/connect-vpn '
1274 '--verbose '
1275 'l2tpipsec-psk vpn-name %s vpn-domain '
1276 'password chapuser chapsecret' %
1277 (self.client_cmd_flimflam_lib,
1278 vpn_host_ip))
1279 elif self.vpn_kind == 'l2tpipsec-cert': # aka 'strongswan'
1280 # 'ca_certificate', 'client-certificate' and 'client-key'.
1281 cert_pathnames = params.get('files', {})
1282 result = self.client.run('%s/test/connect-vpn '
1283 '--verbose '
1284 'l2tpipsec-cert vpn-name %s vpn-domain '
1285 '%s ' # ca certificate
1286 '%s ' # client certificate
1287 '%s' % # client key
1288 (self.client_cmd_flimflam_lib,
1289 vpn_host_ip,
1290 cert_pathnames['ca-certificate'],
1291 cert_pathnames['client-certificate'],
1292 cert_pathnames['client-key']))
1275 else: 1293 else:
1276 raise error.TestFail('(internal error): No launch case ' 1294 raise error.TestFail('(internal error): No launch case '
1277 'for VPN kind (%s)' % self.vpn_kind) 1295 'for VPN kind (%s)' % self.vpn_kind)
1278 1296
1279 def vpn_client_kill(self, params): 1297 def vpn_client_kill(self, params):
1280 """ Kill the VPN client if it's running. """ 1298 """ Kill the VPN client if it's running. """
1281 if self.vpn_kind is not None: 1299 if self.vpn_kind is not None:
1282 if self.vpn_kind == 'openvpn': 1300 if self.vpn_kind == 'openvpn':
1283 self.client.run("pkill openvpn") 1301 self.client.run("pkill openvpn")
1302 elif (self.vpn_kind == 'l2tpipsec-psk' or # aka 'strongswan'
1303 self.vpn_kind == 'l2tpipsec-cert'):
1304 self.client.run("/usr/sbin/ipsec stop")
1284 else: 1305 else:
1285 raise error.TestFail('(internal error): No kill case ' 1306 raise error.TestFail('(internal error): No kill case '
1286 'for VPN kind (%s)' % self.vpn_kind) 1307 'for VPN kind (%s)' % self.vpn_kind)
1287 self.vpn_kind = None 1308 self.vpn_kind = None
1288 1309
1289 __del_host_route(self.client) 1310 self.__del_host_route(self.client)
1290 1311
1291 def __add_host_route(self, host): 1312 def __add_host_route(self, host):
1292 # What is the local address we use to get to the test host? 1313 # What is the local address we use to get to the test host?
1293 local_ip = site_host_route.LocalHostRoute(host.ip).route_info["src"] 1314 local_ip = site_host_route.LocalHostRoute(host.ip).route_info["src"]
1294 1315
1295 # How does the test host currently get to this local address? 1316 # How does the test host currently get to this local address?
1296 host_route = site_host_route.RemoteHostRoute(host, local_ip).route_info 1317 host_route = site_host_route.RemoteHostRoute(host, local_ip).route_info
1297 1318
1298 # Flatten the returned dict into a single string 1319 # Flatten the returned dict into a single string
1299 route_args = " ".join(" ".join(x) for x in host_route.iteritems()) 1320 route_args = " ".join(" ".join(x) for x in host_route.iteritems())
1300 1321
1301 self.host_route_args[host.ip] = "%s %s" % (local_ip, route_args) 1322 self.host_route_args[host.ip] = "%s %s" % (local_ip, route_args)
1302 host.run("ip route add %s" % self.host_route_args[host.ip]) 1323 host.run("ip route add %s" % self.host_route_args[host.ip])
1303 1324
1304 def __del_host_route(self, host): 1325 def __del_host_route(self, host):
1305 if host.ip not in self.host_route_args: 1326 if host.ip in self.host_route_args:
1306 return 1327 host.run("ip route del %s" % self.host_route_args.pop(host.ip))
1307
1308 host.run("ip route del %s" % self.host_route_args.pop(host.ip))
1309 1328
1310 def host_route_cleanup(self, params): 1329 def host_route_cleanup(self, params):
1311 for host in (self.client, self.server, self.router): 1330 for host in (self.client, self.server, self.router):
1312 self.__del_host_route(host) 1331 self.__del_host_route(host)
1313 1332
1314 1333
1315 class HelperThread(threading.Thread): 1334 class HelperThread(threading.Thread):
1316 # Class that wraps a ping command in a thread so it can run in the bg. 1335 # Class that wraps a ping command in a thread so it can run in the bg.
1317 def __init__(self, client, cmd): 1336 def __init__(self, client, cmd):
1318 threading.Thread.__init__(self) 1337 threading.Thread.__init__(self)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 except error.TestFail: 1458 except error.TestFail:
1440 if 'expect_failure' in testcase: 1459 if 'expect_failure' in testcase:
1441 self.expect_failure(name, testcase['expect_failure']) 1460 self.expect_failure(name, testcase['expect_failure'])
1442 else: 1461 else:
1443 raise 1462 raise
1444 except Exception, e: 1463 except Exception, e:
1445 if 'expect_failure' in testcase: 1464 if 'expect_failure' in testcase:
1446 self.expect_failure(name, testcase['expect_failure']) 1465 self.expect_failure(name, testcase['expect_failure'])
1447 else: 1466 else:
1448 raise 1467 raise
OLDNEW
« server/site_linux_server.py ('K') | « server/site_tests/network_VPN/055StrongSwanBadPSK ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698