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 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 # hosting_server is a machine which hosts network services, | 145 # hosting_server is a machine which hosts network services, |
146 # such as VPN. | 146 # such as VPN. |
147 self.hosting_server = site_linux_server.LinuxServer(self.server, server) | 147 self.hosting_server = site_linux_server.LinuxServer(self.server, server) |
148 | 148 |
149 # potential bg thread for ping untilstop | 149 # potential bg thread for ping untilstop |
150 self.ping_thread = None | 150 self.ping_thread = None |
151 | 151 |
152 # potential bg thread for client network monitoring | 152 # potential bg thread for client network monitoring |
153 self.client_netdump_thread = None | 153 self.client_netdump_thread = None |
154 self.__client_discover_commands(client) | 154 self.__client_discover_commands(client) |
155 self.profile_save({}) | 155 self.profile_create({'name':'test'}) |
| 156 self.profile_push({'name':'test'}) |
156 self.firewall_rules = [] | 157 self.firewall_rules = [] |
157 | 158 |
158 # interface name on client | 159 # interface name on client |
159 self.client_wlanif = client.get('wlandev', | 160 self.client_wlanif = client.get('wlandev', |
160 self.__get_wlan_devs(self.client)[0]) | 161 self.__get_wlan_devs(self.client)[0]) |
161 | 162 |
162 # Synchronize time on all devices | 163 # Synchronize time on all devices |
163 self.time_sync([]) | 164 self.time_sync([]) |
164 | 165 |
165 # Find all repeated steps and create iterators for them | 166 # Find all repeated steps and create iterators for them |
166 self.iterated_steps = {} | 167 self.iterated_steps = {} |
167 step_names = [step[0] for step in steps] | 168 step_names = [step[0] for step in steps] |
168 for step_name in list(set(step_names)): | 169 for step_name in list(set(step_names)): |
169 if step_names.count(step_name) > 1: | 170 if step_names.count(step_name) > 1: |
170 self.iterated_steps[step_name] = 0 | 171 self.iterated_steps[step_name] = 0 |
171 | 172 |
172 def cleanup(self, params): | 173 def cleanup(self, params): |
173 """ Cleanup state: disconnect client and destroy ap """ | 174 """ Cleanup state: disconnect client and destroy ap """ |
174 if params.get('force_disconnect'): | 175 if params.get('force_disconnect'): |
175 self.disconnect({}) | 176 self.disconnect({}) |
176 self.wifi.destroy({}) | 177 self.wifi.destroy({}) |
177 self.profile_cleanup({}) | 178 self.profile_pop({'name':'test'}) |
| 179 self.profile_remove({'name':'test'}) |
178 self.client_netdump_stop({}) | 180 self.client_netdump_stop({}) |
179 self.firewall_cleanup({}) | 181 self.firewall_cleanup({}) |
180 | 182 |
181 | 183 |
182 def __must_be_installed(self, host, cmd): | 184 def __must_be_installed(self, host, cmd): |
183 if not self.__is_installed(host, cmd): | 185 if not self.__is_installed(host, cmd): |
184 # TODO(sleffler): temporary debugging | 186 # TODO(sleffler): temporary debugging |
185 host.run("ls -a /usr/bin /usr/local/bin" % cmd, ignore_status=True) | 187 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)) | 188 raise error.TestFail('Unable to find %s on %s' % (cmd, host.ip)) |
187 return cmd | 189 return cmd |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 | 1095 |
1094 self.client_suspend_thread.join() | 1096 self.client_suspend_thread.join() |
1095 if self.client_suspend_thread.result.exit_status: | 1097 if self.client_suspend_thread.result.exit_status: |
1096 raise error.TestError('suspend failed') | 1098 raise error.TestError('suspend failed') |
1097 | 1099 |
1098 def restart_supplicant(self, params): | 1100 def restart_supplicant(self, params): |
1099 """ Restart wpa_supplicant. Cert params are unfortunately "sticky". """ | 1101 """ Restart wpa_supplicant. Cert params are unfortunately "sticky". """ |
1100 | 1102 |
1101 self.client.run("stop wpasupplicant; start wpasupplicant") | 1103 self.client.run("stop wpasupplicant; start wpasupplicant") |
1102 | 1104 |
1103 def __list_profile(self): | |
1104 ret = [] | |
1105 result = self.client.run('%s/test/list-entries' % | |
1106 self.client_cmd_flimflam_lib) | |
1107 for line in result.stdout.splitlines(): | |
1108 m = re.search('\[(wifi_.*)\]', line) | |
1109 if m is not None: | |
1110 ret.append(m.group(1)) | |
1111 return ret | |
1112 | 1105 |
1113 def profile_save(self, params): | 1106 def profile_create(self, params): |
1114 self.client_profile_list = self.__list_profile() | 1107 """ Create a profile with the specified name """ |
| 1108 self.client.run('%s/test/create-profile %s' % |
| 1109 (self.client_cmd_flimflam_lib, params['name'])) |
1115 | 1110 |
1116 def profile_cleanup(self, params): | 1111 def profile_remove(self, params): |
1117 exceptions = params.get('except', self.client_profile_list) | 1112 """ Remove the specified profile """ |
1118 for entry in self.__list_profile(): | 1113 self.client.run('%s/test/rm-profile %s' % |
1119 if entry not in exceptions: | 1114 (self.client_cmd_flimflam_lib, params['name'])) |
1120 self.client.run('%s/test/delete-entry %s' % | 1115 |
1121 (self.client_cmd_flimflam_lib, entry)) | 1116 def profile_push(self, params): |
| 1117 """ Push the specified profile on the stack """ |
| 1118 self.client.run('%s/test/push-profile %s' % |
| 1119 (self.client_cmd_flimflam_lib, params['name'])) |
| 1120 |
| 1121 def profile_pop(self, params): |
| 1122 """ Pop the specified profile from the stack or any profile |
| 1123 if no name is specified. |
| 1124 """ |
| 1125 if 'name' in params: |
| 1126 self.client.run('%s/test/pop-profile %s' % |
| 1127 (self.client_cmd_flimflam_lib, params['name'])) |
| 1128 else: |
| 1129 self.client.run('%s/test/pop-profile' % |
| 1130 (self.client_cmd_flimflam_lib)) |
| 1131 |
1122 | 1132 |
1123 def __get_wifi_device_path(self): | 1133 def __get_wifi_device_path(self): |
1124 if self.client_wifi_device_path: | 1134 if self.client_wifi_device_path: |
1125 return self.client_wifi_device_path | 1135 return self.client_wifi_device_path |
1126 ret = [] | 1136 ret = [] |
1127 result = self.client.run('%s/test/list-devices' % | 1137 result = self.client.run('%s/test/list-devices' % |
1128 self.client_cmd_flimflam_lib) | 1138 self.client_cmd_flimflam_lib) |
1129 device_path = None | 1139 device_path = None |
1130 for line in result.stdout.splitlines(): | 1140 for line in result.stdout.splitlines(): |
1131 m = re.match('\[\s*(\S*)\s*\]', line) | 1141 m = re.match('\[\s*(\S*)\s*\]', line) |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1395 except error.TestFail: | 1405 except error.TestFail: |
1396 if 'expect_failure' in testcase: | 1406 if 'expect_failure' in testcase: |
1397 self.expect_failure(name, testcase['expect_failure']) | 1407 self.expect_failure(name, testcase['expect_failure']) |
1398 else: | 1408 else: |
1399 raise | 1409 raise |
1400 except Exception, e: | 1410 except Exception, e: |
1401 if 'expect_failure' in testcase: | 1411 if 'expect_failure' in testcase: |
1402 self.expect_failure(name, testcase['expect_failure']) | 1412 self.expect_failure(name, testcase['expect_failure']) |
1403 else: | 1413 else: |
1404 raise | 1414 raise |
OLD | NEW |