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 errno, logging, os, re, signal, subprocess, time | 5 import errno, logging, os, re, signal, subprocess, time |
6 import common | 6 import common |
7 import constants, cros_logging, cros_ui, cryptohome | 7 import constants, cros_logging, cros_ui, cryptohome |
8 from autotest_lib.client.bin import utils | 8 from autotest_lib.client.bin import utils |
9 from autotest_lib.client.common_lib import error | 9 from autotest_lib.client.common_lib import error |
10 | 10 |
11 | 11 |
12 _DEFAULT_TIMEOUT = 30 | 12 _DEFAULT_TIMEOUT = 30 |
13 | 13 |
| 14 # Log messages used to signal when we're in a logout situation. Used to detect |
| 15 # crashes by cros_ui_test.UITest. |
| 16 LOGOUT_ATTEMPT_MSG = 'cros/login.py: Attempting logout...' |
| 17 LOGOUT_COMPLETE_MSG = 'cros/login.py: Logout complete.' |
| 18 |
14 | 19 |
15 class TimeoutError(error.TestError): | 20 class TimeoutError(error.TestError): |
16 """Error raised when we time out while waiting on a condition.""" | 21 """Error raised when we time out while waiting on a condition.""" |
17 pass | 22 pass |
18 | 23 |
19 | 24 |
20 class CrashError(error.TestError): | 25 class CrashError(error.TestError): |
21 """Error raised when a pertinent process crashes while waiting on | 26 """Error raised when a pertinent process crashes while waiting on |
22 a condition. | 27 a condition. |
23 """ | 28 """ |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 Args: | 179 Args: |
175 timeout: float number of seconds to wait | 180 timeout: float number of seconds to wait |
176 | 181 |
177 Raises: | 182 Raises: |
178 TimeoutError: logout didn't complete before timeout | 183 TimeoutError: logout didn't complete before timeout |
179 UnexpectedCondition: user is not logged in | 184 UnexpectedCondition: user is not logged in |
180 """ | 185 """ |
181 if not logged_in(): | 186 if not logged_in(): |
182 raise UnexpectedCondition('Already logged out') | 187 raise UnexpectedCondition('Already logged out') |
183 | 188 |
184 oldpid = __get_session_manager_pid() | 189 # Log what we're about to do to /var/log/messages. Used to log crashes later |
| 190 # in cleanup by cros_ui_test.UITest. |
| 191 utils.system('logger "%s"' % LOGOUT_ATTEMPT_MSG) |
185 | 192 |
186 # Mark /var/log/messages now; we'll run through all subsequent log messages | 193 try: |
187 # if we couldn't TERM and restart the session manager. | 194 oldpid = __get_session_manager_pid() |
188 | 195 |
189 log_reader = cros_logging.LogReader() | 196 # Mark /var/log/messages now; we'll run through all subsequent log |
190 log_reader.set_start_by_current() | 197 # messages if we couldn't TERM and restart the session manager. |
191 | 198 |
192 # Gracefully exiting the session manager causes the user's session to end. | 199 log_reader = cros_logging.LogReader() |
193 utils.system('pkill -TERM -o ^%s$' % constants.SESSION_MANAGER) | 200 log_reader.set_start_by_current() |
194 | 201 |
195 wait_for_condition( | 202 # Gracefully exiting the session manager causes the user's session to end. |
196 condition=lambda: __session_manager_restarted(oldpid), | 203 utils.system('pkill -TERM -o ^%s$' % constants.SESSION_MANAGER) |
197 timeout_msg='Timed out waiting for logout', | 204 |
198 timeout=timeout, | 205 wait_for_condition( |
199 process='session_manager', | 206 condition=lambda: __session_manager_restarted(oldpid), |
200 log_reader=log_reader, | 207 timeout_msg='Timed out waiting for logout', |
201 crash_msg='session_manager crashed while shutting down.') | 208 timeout=timeout, |
| 209 process='session_manager', |
| 210 log_reader=log_reader, |
| 211 crash_msg='session_manager crashed while shutting down.') |
| 212 finally: |
| 213 utils.system('logger "%s"' % LOGOUT_COMPLETE_MSG) |
202 | 214 |
203 | 215 |
204 def wait_for_browser(timeout=_DEFAULT_TIMEOUT): | 216 def wait_for_browser(timeout=_DEFAULT_TIMEOUT): |
205 """Wait until a Chrome process is running. | 217 """Wait until a Chrome process is running. |
206 | 218 |
207 Args: | 219 Args: |
208 timeout: float number of seconds to wait | 220 timeout: float number of seconds to wait |
209 | 221 |
210 Raises: | 222 Raises: |
211 TimeoutError: Chrome didn't start before timeout | 223 TimeoutError: Chrome didn't start before timeout |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 except (IOError, OSError) as error: | 392 except (IOError, OSError) as error: |
381 logging.error(error) | 393 logging.error(error) |
382 | 394 |
383 # Restart the UI. | 395 # Restart the UI. |
384 nuke_login_manager() | 396 nuke_login_manager() |
385 utils.poll_for_condition( | 397 utils.poll_for_condition( |
386 lambda: __session_manager_restarted(oldpid), | 398 lambda: __session_manager_restarted(oldpid), |
387 TimeoutError('Timed out waiting for logout'), | 399 TimeoutError('Timed out waiting for logout'), |
388 timeout) | 400 timeout) |
389 wait_for_login_prompt() | 401 wait_for_login_prompt() |
OLD | NEW |