Dale Curtis | 2468a32 | 2011-04-21 10:31:25 -0700 | [diff] [blame] | 1 | # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Sean O'Connor | 6fa1dea | 2010-04-12 13:19:16 -0700 | [diff] [blame] | 4 | |
Dale Curtis | a94c19c | 2011-05-02 15:05:17 -0700 | [diff] [blame] | 5 | from autotest_lib.client.bin import utils |
Eric Li | 538b704 | 2010-12-03 16:12:28 -0800 | [diff] [blame] | 6 | from autotest_lib.client.common_lib import global_config |
| 7 | from autotest_lib.client.common_lib.cros import autoupdater |
Sean O'Connor | 6fa1dea | 2010-04-12 13:19:16 -0700 | [diff] [blame] | 8 | from autotest_lib.server import autoserv_parser |
Dale Curtis | b478f17 | 2011-04-12 14:51:14 -0700 | [diff] [blame] | 9 | from autotest_lib.server import site_remote_power |
Sean O'Connor | 6fa1dea | 2010-04-12 13:19:16 -0700 | [diff] [blame] | 10 | from autotest_lib.server.hosts import base_classes |
| 11 | |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 12 | |
Sean O'Connor | 6fa1dea | 2010-04-12 13:19:16 -0700 | [diff] [blame] | 13 | parser = autoserv_parser.autoserv_parser |
Sean O'Connor | 6fa1dea | 2010-04-12 13:19:16 -0700 | [diff] [blame] | 14 | |
Dale Curtis | a94c19c | 2011-05-02 15:05:17 -0700 | [diff] [blame] | 15 | # Time to wait for new kernel to be marked successful. |
| 16 | _KERNEL_UPDATE_TIMEOUT = 60 |
| 17 | |
Dale Curtis | 53d5586 | 2011-05-16 12:17:59 -0700 | [diff] [blame] | 18 | # Ephemeral file to indicate that an update has just occurred. |
| 19 | _JUST_UPDATED_FLAG = '/tmp/just_updated' |
| 20 | |
Sean O'Connor | 6fa1dea | 2010-04-12 13:19:16 -0700 | [diff] [blame] | 21 | |
| 22 | class ChromiumOSHost(base_classes.Host): |
| 23 | """ChromiumOSHost is a special subclass of SSHHost that supports |
Sean O'Connor | 5346e4e | 2010-08-12 18:49:24 +0200 | [diff] [blame] | 24 | additional install methods. |
Sean O'Connor | 6fa1dea | 2010-04-12 13:19:16 -0700 | [diff] [blame] | 25 | """ |
| 26 | def __initialize(self, hostname, *args, **dargs): |
| 27 | """ |
| 28 | Construct a ChromiumOSHost object |
| 29 | |
| 30 | Args: |
| 31 | hostname: network hostname or address of remote machine |
| 32 | """ |
| 33 | super(ChromiumOSHost, self)._initialize(hostname, *args, **dargs) |
| 34 | |
| 35 | |
Dale Curtis | 53d5586 | 2011-05-16 12:17:59 -0700 | [diff] [blame] | 36 | def machine_install(self, update_url=None, force_update=False): |
Sean O'Connor | cee5143 | 2010-06-04 14:48:41 -0700 | [diff] [blame] | 37 | if parser.options.image: |
Dale Curtis | 2468a32 | 2011-04-21 10:31:25 -0700 | [diff] [blame] | 38 | update_url = parser.options.image |
Sean O'Connor | cee5143 | 2010-06-04 14:48:41 -0700 | [diff] [blame] | 39 | elif not update_url: |
Dale Curtis | a94c19c | 2011-05-02 15:05:17 -0700 | [diff] [blame] | 40 | raise autoupdater.ChromiumOSError( |
| 41 | 'Update failed. No update URL provided.') |
Eric Li | 67b7ed5 | 2011-04-04 16:40:24 -0700 | [diff] [blame] | 42 | |
Dale Curtis | a94c19c | 2011-05-02 15:05:17 -0700 | [diff] [blame] | 43 | # Attempt to update the system. |
| 44 | updater = autoupdater.ChromiumOSUpdater(update_url, host=self) |
Dale Curtis | 53d5586 | 2011-05-16 12:17:59 -0700 | [diff] [blame] | 45 | if updater.run_update(force_update): |
Dale Curtis | a94c19c | 2011-05-02 15:05:17 -0700 | [diff] [blame] | 46 | # Figure out active and inactive kernel. |
| 47 | active_kernel, inactive_kernel = updater.get_kernel_state() |
Eric Li | 67b7ed5 | 2011-04-04 16:40:24 -0700 | [diff] [blame] | 48 | |
Dale Curtis | a94c19c | 2011-05-02 15:05:17 -0700 | [diff] [blame] | 49 | # Ensure inactive kernel has higher priority than active. |
| 50 | if (updater.get_kernel_priority(inactive_kernel) |
| 51 | < updater.get_kernel_priority(active_kernel)): |
| 52 | raise autoupdater.ChromiumOSError( |
| 53 | 'Update failed. The priority of the inactive kernel' |
| 54 | ' partition is less than that of the active kernel' |
| 55 | ' partition.') |
| 56 | |
| 57 | # Updater has returned, successfully, reboot the host. |
| 58 | self.reboot(timeout=60, wait=True) |
| 59 | |
| 60 | # Following the reboot, verify the correct version. |
| 61 | updater.check_version() |
| 62 | |
| 63 | # Figure out newly active kernel. |
| 64 | new_active_kernel, _ = updater.get_kernel_state() |
| 65 | |
| 66 | # Ensure that previously inactive kernel is now the active kernel. |
| 67 | if new_active_kernel != inactive_kernel: |
| 68 | raise autoupdater.ChromiumOSError( |
| 69 | 'Update failed. New kernel partition is not active after' |
| 70 | ' boot.') |
| 71 | |
Dale Curtis | de2a384 | 2011-05-31 12:50:18 -0700 | [diff] [blame^] | 72 | # Wait until tries == 0 and success, or until timeout. |
| 73 | utils.poll_for_condition( |
| 74 | lambda: (updater.get_kernel_tries(new_active_kernel) == 0 |
| 75 | and updater.get_kernel_success(new_active_kernel)), |
| 76 | exception=autoupdater.ChromiumOSError( |
| 77 | 'Update failed. Timed out waiting for system to mark' |
| 78 | ' new kernel as successful.'), |
| 79 | timeout=_KERNEL_UPDATE_TIMEOUT, sleep_interval=5) |
Dale Curtis | fb2b9f2 | 2011-02-14 16:11:25 -0800 | [diff] [blame] | 80 | |
Dale Curtis | 8b9e661 | 2011-05-06 15:10:35 -0700 | [diff] [blame] | 81 | # TODO(dalecurtis): Hack for R12 builds to make sure BVT runs of |
| 82 | # platform_Shutdown pass correctly. |
Dale Curtis | f57a25f | 2011-05-24 14:40:55 -0700 | [diff] [blame] | 83 | if updater.update_version.startswith('0.12'): |
Dale Curtis | 8b9e661 | 2011-05-06 15:10:35 -0700 | [diff] [blame] | 84 | self.reboot(timeout=60, wait=True) |
| 85 | |
Dale Curtis | 1770db5 | 2011-05-23 14:53:45 -0700 | [diff] [blame] | 86 | # Mark host as recently updated. Hosts are rebooted at the end of |
| 87 | # every test cycle which will remove the file. |
| 88 | self.run('touch %s' % _JUST_UPDATED_FLAG) |
| 89 | |
Dale Curtis | fb2b9f2 | 2011-02-14 16:11:25 -0800 | [diff] [blame] | 90 | # Clean up any old autotest directories which may be lying around. |
| 91 | for path in global_config.global_config.get_config_value( |
| 92 | 'AUTOSERV', 'client_autodir_paths', type=list): |
| 93 | self.run('rm -rf ' + path) |
Dale Curtis | b478f17 | 2011-04-12 14:51:14 -0700 | [diff] [blame] | 94 | |
Dale Curtis | 53d5586 | 2011-05-16 12:17:59 -0700 | [diff] [blame] | 95 | |
| 96 | def has_just_updated(self): |
| 97 | """Indicates whether the host was updated within this boot.""" |
| 98 | # Check for the existence of the just updated flag file. |
| 99 | return self.run( |
| 100 | '[ -f %s ] && echo T || echo F' |
| 101 | % _JUST_UPDATED_FLAG).stdout.strip() == 'T' |
| 102 | |
Dale Curtis | b478f17 | 2011-04-12 14:51:14 -0700 | [diff] [blame] | 103 | |
| 104 | def cleanup(self): |
| 105 | """Special cleanup method to make sure hosts always get power back.""" |
| 106 | super(ChromiumOSHost, self).cleanup() |
| 107 | remote_power = site_remote_power.RemotePower(self.hostname) |
| 108 | if remote_power: |
| 109 | remote_power.set_power_on() |
Dale Curtis | 2468a32 | 2011-04-21 10:31:25 -0700 | [diff] [blame] | 110 | |
| 111 | |
| 112 | def verify(self): |
| 113 | """Override to ensure only our version of verify_software() is run.""" |
| 114 | self.verify_hardware() |
| 115 | self.verify_connectivity() |
| 116 | self.__verify_software() |
| 117 | |
| 118 | |
| 119 | def __verify_software(self): |
| 120 | """Ensure the stateful partition has space for Autotest and updates. |
| 121 | |
| 122 | Similar to what is done by AbstractSSH, except instead of checking the |
| 123 | Autotest installation path, just check the stateful partition. |
| 124 | |
| 125 | Checking the stateful partition is preferable in case it has been wiped, |
| 126 | resulting in an Autotest installation path which doesn't exist and isn't |
| 127 | writable. We still want to pass verify in this state since the partition |
| 128 | will be recovered with the next install. |
| 129 | """ |
| 130 | super(ChromiumOSHost, self).verify_software() |
| 131 | self.check_diskspace( |
| 132 | '/mnt/stateful_partition', |
| 133 | global_config.global_config.get_config_value( |
| 134 | 'SERVER', 'gb_diskspace_required', type=int, |
| 135 | default=20)) |