| 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 httplib | 5 import httplib |
| 6 import logging | 6 import logging |
| 7 import re | 7 import re |
| 8 import socket | 8 import socket |
| 9 import urlparse | 9 import urlparse |
| 10 | 10 |
| 11 from autotest_lib.client.bin import chromeos_constants | 11 from autotest_lib.client.bin import chromeos_constants |
| 12 from autotest_lib.client.common_lib import error | 12 from autotest_lib.client.common_lib import error |
| 13 | 13 |
| 14 STATEFULDEV_UPDATER = '/usr/local/bin/stateful_update' | 14 STATEFULDEV_UPDATER = '/usr/local/bin/stateful_update' |
| 15 UPDATER_BIN = '/usr/bin/update_engine_client' | 15 UPDATER_BIN = '/usr/bin/update_engine_client' |
| 16 UPDATER_IDLE = 'UPDATE_STATUS_IDLE' | 16 UPDATER_IDLE = 'UPDATE_STATUS_IDLE' |
| 17 UPDATER_NEED_REBOOT = 'UPDATE_STATUS_UPDATED_NEED_REBOOT' | 17 UPDATER_NEED_REBOOT = 'UPDATE_STATUS_UPDATED_NEED_REBOOT' |
| 18 UPDATED_MARKER = '/var/run/update_engine_autoupdate_completed' |
| 18 | 19 |
| 19 | 20 |
| 20 class ChromiumOSError(error.InstallError): | 21 class ChromiumOSError(error.InstallError): |
| 21 """Generic error for ChromiumOS-specific exceptions.""" | 22 """Generic error for ChromiumOS-specific exceptions.""" |
| 22 pass | 23 pass |
| 23 | 24 |
| 24 | 25 |
| 25 def url_to_version(update_url): | 26 def url_to_version(update_url): |
| 26 # The ChromiumOS updater respects the last element in the path as | 27 # The ChromiumOS updater respects the last element in the path as |
| 27 # the requested version. Parse it out. | 28 # the requested version. Parse it out. |
| 28 return urlparse.urlparse(update_url).path.split('/')[-1] | 29 return urlparse.urlparse(update_url).path.split('/')[-1] |
| 29 | 30 |
| 30 | 31 |
| 31 class ChromiumOSUpdater(): | 32 class ChromiumOSUpdater(): |
| 32 def __init__(self, host=None, update_url=None): | 33 def __init__(self, host=None, update_url=None): |
| 33 self.host = host | 34 self.host = host |
| 34 self.update_url = update_url | 35 self.update_url = update_url |
| 35 self.update_version = url_to_version(update_url) | 36 self.update_version = url_to_version(update_url) |
| 36 | 37 |
| 37 | 38 |
| 38 def check_update_status(self): | 39 def check_update_status(self): |
| 39 update_status_cmd = ' '.join([UPDATER_BIN, '-status', '2>&1', | 40 update_status_cmd = ' '.join([UPDATER_BIN, '-status', '2>&1', |
| 40 '| grep CURRENT_OP']) | 41 '| grep CURRENT_OP']) |
| 41 update_status = self._run(update_status_cmd) | 42 update_status = self._run(update_status_cmd) |
| 42 return update_status.stdout.strip().split('=')[-1] | 43 return update_status.stdout.strip().split('=')[-1] |
| 43 | 44 |
| 44 | 45 |
| 45 def reset_update_engine(self): | 46 def reset_update_engine(self): |
| 46 logging.info('Resetting update-engine.') | 47 logging.info('Resetting update-engine.') |
| 47 self._run('rm -f /tmp/update_engine_autoupdate_completed') | 48 self._run('rm -f %s' % UPDATED_MARKER) |
| 48 try: | 49 try: |
| 49 self._run('initctl stop update-engine') | 50 self._run('initctl stop update-engine') |
| 50 except error.AutoservRunError, e: | 51 except error.AutoservRunError, e: |
| 51 logging.warn('Stopping update-engine service failed. Already dead?') | 52 logging.warn('Stopping update-engine service failed. Already dead?') |
| 52 self._run('initctl start update-engine') | 53 self._run('initctl start update-engine') |
| 53 # May need to wait if service becomes slow to restart. | 54 # May need to wait if service becomes slow to restart. |
| 54 if self.check_update_status() != UPDATER_IDLE: | 55 if self.check_update_status() != UPDATER_IDLE: |
| 55 raise ChromiumOSError('%s is not in an installable state' % | 56 raise ChromiumOSError('%s is not in an installable state' % |
| 56 self.host.hostname) | 57 self.host.hostname) |
| 57 | 58 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 if not version_match: | 156 if not version_match: |
| 156 raise ChromiumOSError('Unable to get build ID from %s. Found "%s"', | 157 raise ChromiumOSError('Unable to get build ID from %s. Found "%s"', |
| 157 self.host.hostname, version) | 158 self.host.hostname, version) |
| 158 version, build_id, builder = version_match.groups() | 159 version, build_id, builder = version_match.groups() |
| 159 build_match = re.match(r'.*: (\d+)', builder) | 160 build_match = re.match(r'.*: (\d+)', builder) |
| 160 if build_match: | 161 if build_match: |
| 161 builder_num = '-b%s' % build_match.group(1) | 162 builder_num = '-b%s' % build_match.group(1) |
| 162 else: | 163 else: |
| 163 builder_num = '' | 164 builder_num = '' |
| 164 return '%s-r%s%s' % (version, build_id, builder_num) | 165 return '%s-r%s%s' % (version, build_id, builder_num) |
| OLD | NEW |