rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 1 | # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 5 | from buildutil import BuildObject |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 6 | from xml.dom import minidom |
| 7 | |
| 8 | import os |
Darin Petkov | 798fe7d | 2010-03-22 15:18:13 -0700 | [diff] [blame] | 9 | import shutil |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 10 | import sys |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 11 | import web |
| 12 | |
rtc@google.com | 6424466 | 2009-11-12 00:52:08 +0000 | [diff] [blame] | 13 | class Autoupdate(BuildObject): |
Darin Petkov | 798fe7d | 2010-03-22 15:18:13 -0700 | [diff] [blame] | 14 | # Basic functionality of handling ChromeOS autoupdate pings |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 15 | # and building/serving update images. |
| 16 | # TODO(rtc): Clean this code up and write some tests. |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 17 | |
Sean O'Connor | 1f7fd36 | 2010-04-07 16:34:52 -0700 | [diff] [blame] | 18 | def __init__(self, serve_only=None, test_image=False, urlbase=None, |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 19 | factory_config_path=None, validate_factory_config=None, |
Sean O'Connor | 1f7fd36 | 2010-04-07 16:34:52 -0700 | [diff] [blame] | 20 | *args, **kwargs): |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 21 | super(Autoupdate, self).__init__(*args, **kwargs) |
Sean O'Connor | 1f7fd36 | 2010-04-07 16:34:52 -0700 | [diff] [blame] | 22 | self.serve_only = serve_only |
Sean O'Connor | 1b4b076 | 2010-06-02 17:37:32 -0700 | [diff] [blame] | 23 | self.factory_config = factory_config_path |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 24 | self.test_image = test_image |
Sean O'Connor | 1f7fd36 | 2010-04-07 16:34:52 -0700 | [diff] [blame] | 25 | self.static_urlbase = urlbase |
| 26 | if serve_only: |
| 27 | # If we're serving out of an archived build dir (e.g. a |
| 28 | # buildbot), prepare this webserver's magic 'static/' dir with a |
| 29 | # link to the build archive. |
| 30 | web.debug('Autoupdate in "serve update images only" mode.') |
| 31 | if os.path.exists('static/archive'): |
Sean O'Connor | 1b4b076 | 2010-06-02 17:37:32 -0700 | [diff] [blame] | 32 | if self.static_dir != os.readlink('static/archive'): |
Sean O'Connor | 1f7fd36 | 2010-04-07 16:34:52 -0700 | [diff] [blame] | 33 | web.debug('removing stale symlink to %s' % self.static_dir) |
| 34 | os.unlink('static/archive') |
Sean O'Connor | 1b4b076 | 2010-06-02 17:37:32 -0700 | [diff] [blame] | 35 | os.symlink(self.static_dir, 'static/archive') |
Sean O'Connor | 1f7fd36 | 2010-04-07 16:34:52 -0700 | [diff] [blame] | 36 | else: |
Sean O'Connor | 1b4b076 | 2010-06-02 17:37:32 -0700 | [diff] [blame] | 37 | os.symlink(self.static_dir, 'static/archive') |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 38 | if factory_config_path is not None: |
| 39 | self.ImportFactoryConfigFile(factory_config_path, validate_factory_config) |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 40 | |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 41 | def GetUpdatePayload(self, hash, size, url): |
| 42 | payload = """<?xml version="1.0" encoding="UTF-8"?> |
| 43 | <gupdate xmlns="http://www.google.com/update2/response" protocol="2.0"> |
| 44 | <app appid="{%s}" status="ok"> |
| 45 | <ping status="ok"/> |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 46 | <updatecheck |
| 47 | codebase="%s" |
| 48 | hash="%s" |
| 49 | needsadmin="false" |
| 50 | size="%s" |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 51 | status="ok"/> |
| 52 | </app> |
| 53 | </gupdate> |
| 54 | """ |
| 55 | return payload % (self.app_id, url, hash, size) |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 56 | |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 57 | def GetNoUpdatePayload(self): |
| 58 | payload = """<?xml version="1.0" encoding="UTF-8"?> |
| 59 | <gupdate xmlns="http://www.google.com/update2/response" protocol="2.0"> |
| 60 | <app appid="{%s}" status="ok"> |
| 61 | <ping status="ok"/> |
| 62 | <updatecheck status="noupdate"/> |
| 63 | </app> |
| 64 | </gupdate> |
| 65 | """ |
| 66 | return payload % self.app_id |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 67 | |
Sam Leffler | 7638204 | 2010-02-18 09:58:42 -0800 | [diff] [blame] | 68 | def GetLatestImagePath(self, board_id): |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 69 | cmd = '%s/get_latest_image.sh --board %s' % (self.scripts_dir, board_id) |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 70 | return os.popen(cmd).read().strip() |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 71 | |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 72 | def GetLatestVersion(self, latest_image_path): |
| 73 | latest_version = latest_image_path.split('/')[-1] |
Ryan Cairns | 1b05beb | 2010-02-05 17:05:24 -0800 | [diff] [blame] | 74 | |
| 75 | # Removes the portage build prefix. |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 76 | latest_version = latest_version.lstrip('g-') |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 77 | return latest_version.split('-')[0] |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 78 | |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 79 | def CanUpdate(self, client_version, latest_version): |
| 80 | """ |
| 81 | Returns true iff the latest_version is greater than the client_version. |
| 82 | """ |
Vincent Scheib | 904c664 | 2010-05-18 14:57:39 -0700 | [diff] [blame] | 83 | client_tokens = client_version.replace('_','').split('.') |
| 84 | latest_tokens = latest_version.replace('_','').split('.') |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 85 | web.debug('client version %s latest version %s' \ |
Charlie Lee | 8c99308 | 2010-02-24 13:27:37 -0800 | [diff] [blame] | 86 | % (client_version, latest_version)) |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 87 | for i in range(4): |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 88 | if int(latest_tokens[i]) == int(client_tokens[i]): |
| 89 | continue |
| 90 | return int(latest_tokens[i]) > int(client_tokens[i]) |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 91 | return False |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 92 | |
Sean O'Connor | a7f867e | 2010-05-27 17:53:32 -0700 | [diff] [blame] | 93 | def UnpackImage(self, image_path, image_file, stateful_file, |
| 94 | kernel_file, rootfs_file): |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 95 | unpack_command = 'cd %s && ./unpack_partitions.sh %s' % \ |
| 96 | (image_path, image_file) |
| 97 | if os.system(unpack_command) == 0: |
| 98 | shutil.move(os.path.join(image_path, 'part_1'), stateful_file) |
| 99 | shutil.move(os.path.join(image_path, 'part_2'), kernel_file) |
| 100 | shutil.move(os.path.join(image_path, 'part_3'), rootfs_file) |
| 101 | os.system('cd %s && rm part_*' % image_path) |
Darin Petkov | cbcd2bd | 2010-04-06 10:14:08 -0700 | [diff] [blame] | 102 | return True |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 103 | return False |
| 104 | |
| 105 | def UnpackZip(self, image_path, image_file): |
Sean O'Connor | a7f867e | 2010-05-27 17:53:32 -0700 | [diff] [blame] | 106 | image = os.path.join(image_path, image_file) |
| 107 | if os.path.exists(image): |
| 108 | return True |
| 109 | else: |
Sean O'Connor | 1b4b076 | 2010-06-02 17:37:32 -0700 | [diff] [blame] | 110 | # -n, never clobber an existing file, in case we get invoked |
| 111 | # simultaneously by multiple request handlers. This means that |
| 112 | # we're assuming each image.zip file lives in a versioned |
| 113 | # directory (a la Buildbot). |
| 114 | return os.system('cd %s && unzip -n image.zip %s unpack_partitions.sh' % |
Sean O'Connor | a7f867e | 2010-05-27 17:53:32 -0700 | [diff] [blame] | 115 | (image_path, image_file)) == 0 |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 116 | |
| 117 | def GetImageBinPath(self, image_path): |
Darin Petkov | cbcd2bd | 2010-04-06 10:14:08 -0700 | [diff] [blame] | 118 | if self.test_image: |
| 119 | image_file = 'chromiumos_test_image.bin' |
| 120 | else: |
| 121 | image_file = 'chromiumos_image.bin' |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 122 | return image_file |
Darin Petkov | cbcd2bd | 2010-04-06 10:14:08 -0700 | [diff] [blame] | 123 | |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 124 | def BuildUpdateImage(self, image_path): |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 125 | stateful_file = '%s/stateful.image' % image_path |
Darin Petkov | 55604f1 | 2010-04-12 11:09:25 -0700 | [diff] [blame] | 126 | kernel_file = '%s/kernel.image' % image_path |
| 127 | rootfs_file = '%s/rootfs.image' % image_path |
Darin Petkov | cbcd2bd | 2010-04-06 10:14:08 -0700 | [diff] [blame] | 128 | |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 129 | image_file = self.GetImageBinPath(image_path) |
| 130 | bin_path = os.path.join(image_path, image_file) |
Darin Petkov | cbcd2bd | 2010-04-06 10:14:08 -0700 | [diff] [blame] | 131 | |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 132 | # Get appropriate update.gz to compare timestamps. |
| 133 | if self.serve_only: |
| 134 | cached_update_file = os.path.join(image_path, 'update.gz') |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 135 | else: |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 136 | cached_update_file = os.path.join(self.static_dir, 'update.gz') |
| 137 | |
Sean O'Connor | a7f867e | 2010-05-27 17:53:32 -0700 | [diff] [blame] | 138 | # If the rootfs image is newer, re-create everything. |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 139 | if (os.path.exists(cached_update_file) and |
| 140 | os.path.getmtime(cached_update_file) >= os.path.getmtime(bin_path)): |
| 141 | web.debug('Using cached update image at %s instead of %s' % |
| 142 | (cached_update_file, bin_path)) |
| 143 | else: |
| 144 | # Unpack zip file if we are serving from a directory. |
| 145 | if self.serve_only and not self.UnpackZip(image_path, image_file): |
| 146 | web.debug('unzip image.zip failed.') |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 147 | return False |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 148 | |
| 149 | if not self.UnpackImage(image_path, image_file, stateful_file, |
| 150 | kernel_file, rootfs_file): |
| 151 | web.debug('Failed to unpack image.') |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 152 | return False |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 153 | |
| 154 | update_file = os.path.join(image_path, 'update.gz') |
| 155 | web.debug('Generating update image %s' % update_file) |
| 156 | mkupdate_command = '%s/mk_memento_images.sh %s %s' % \ |
| 157 | (self.scripts_dir, kernel_file, rootfs_file) |
| 158 | if os.system(mkupdate_command) != 0: |
| 159 | web.debug('Failed to create update image') |
| 160 | return False |
| 161 | |
Sean O'Connor | a7f867e | 2010-05-27 17:53:32 -0700 | [diff] [blame] | 162 | mkstatefulupdate_command = 'gzip -f %s' % stateful_file |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 163 | if os.system(mkstatefulupdate_command) != 0: |
| 164 | web.debug('Failed to create stateful update image') |
| 165 | return False |
| 166 | |
| 167 | # Add gz suffix |
| 168 | stateful_file = '%s.gz' % stateful_file |
| 169 | |
| 170 | # Cleanup of image files |
| 171 | os.remove(kernel_file) |
| 172 | os.remove(rootfs_file) |
| 173 | if not self.serve_only: |
| 174 | try: |
| 175 | web.debug('Found a new image to serve, copying it to static') |
| 176 | shutil.copy(update_file, self.static_dir) |
| 177 | shutil.copy(stateful_file, self.static_dir) |
| 178 | os.remove(update_file) |
| 179 | os.remove(stateful_file) |
| 180 | except Exception, e: |
| 181 | web.debug('%s' % e) |
| 182 | return False |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 183 | return True |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 184 | |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 185 | def GetSize(self, update_path): |
| 186 | return os.path.getsize(update_path) |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 187 | |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 188 | def GetHash(self, update_path): |
Darin Petkov | 8ef8345 | 2010-03-23 16:52:29 -0700 | [diff] [blame] | 189 | cmd = "cat %s | openssl sha1 -binary | openssl base64 | tr \'\\n\' \' \';" \ |
| 190 | % update_path |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 191 | return os.popen(cmd).read().rstrip() |
Darin Petkov | 8ef8345 | 2010-03-23 16:52:29 -0700 | [diff] [blame] | 192 | |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 193 | def ImportFactoryConfigFile(self, filename, validate_checksums=False): |
| 194 | """Imports a factory-floor server configuration file. The file should |
| 195 | be in this format: |
| 196 | config = [ |
| 197 | { |
| 198 | 'qual_ids': set([1, 2, 3, "x86-generic"]), |
| 199 | 'factory_image': 'generic-factory.gz', |
| 200 | 'factory_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
| 201 | 'release_image': 'generic-release.gz', |
| 202 | 'release_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
| 203 | 'oempartitionimg_image': 'generic-oem.gz', |
| 204 | 'oempartitionimg_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
Nick Sanders | e1eea92 | 2010-05-19 22:17:08 -0700 | [diff] [blame] | 205 | 'efipartitionimg_image': 'generic-efi.gz', |
| 206 | 'efipartitionimg_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 207 | 'stateimg_image': 'generic-state.gz', |
Tom Wai-Hong Tam | 65fc607 | 2010-05-20 11:44:26 +0800 | [diff] [blame] | 208 | 'stateimg_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
Tom Wai-Hong Tam | dac3df1 | 2010-06-14 09:56:15 +0800 | [diff] [blame] | 209 | 'firmware_image': 'generic-firmware.gz', |
| 210 | 'firmware_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 211 | }, |
| 212 | { |
| 213 | 'qual_ids': set([6]), |
| 214 | 'factory_image': '6-factory.gz', |
| 215 | 'factory_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
| 216 | 'release_image': '6-release.gz', |
| 217 | 'release_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
| 218 | 'oempartitionimg_image': '6-oem.gz', |
| 219 | 'oempartitionimg_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
Nick Sanders | e1eea92 | 2010-05-19 22:17:08 -0700 | [diff] [blame] | 220 | 'efipartitionimg_image': '6-efi.gz', |
| 221 | 'efipartitionimg_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 222 | 'stateimg_image': '6-state.gz', |
Tom Wai-Hong Tam | 65fc607 | 2010-05-20 11:44:26 +0800 | [diff] [blame] | 223 | 'stateimg_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
Tom Wai-Hong Tam | dac3df1 | 2010-06-14 09:56:15 +0800 | [diff] [blame] | 224 | 'firmware_image': '6-firmware.gz', |
| 225 | 'firmware_checksum': 'AtiI8B64agHVN+yeBAyiNMX3+HM=', |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 226 | }, |
| 227 | ] |
| 228 | The server will look for the files by name in the static files |
| 229 | directory. |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 230 | |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 231 | If validate_checksums is True, validates checksums and exits. If |
| 232 | a checksum mismatch is found, it's printed to the screen. |
| 233 | """ |
| 234 | f = open(filename, 'r') |
| 235 | output = {} |
| 236 | exec(f.read(), output) |
| 237 | self.factory_config = output['config'] |
| 238 | success = True |
| 239 | for stanza in self.factory_config: |
Tom Wai-Hong Tam | 65fc607 | 2010-05-20 11:44:26 +0800 | [diff] [blame] | 240 | for key in stanza.copy().iterkeys(): |
| 241 | suffix = '_image' |
| 242 | if key.endswith(suffix): |
| 243 | kind = key[:-len(suffix)] |
| 244 | stanza[kind + '_size'] = \ |
| 245 | os.path.getsize(self.static_dir + '/' + stanza[kind + '_image']) |
| 246 | if validate_checksums: |
| 247 | factory_checksum = self.GetHash(self.static_dir + '/' + |
| 248 | stanza[kind + '_image']) |
| 249 | if factory_checksum != stanza[kind + '_checksum']: |
| 250 | print 'Error: checksum mismatch for %s. Expected "%s" but file ' \ |
| 251 | 'has checksum "%s".' % (stanza[kind + '_image'], |
| 252 | stanza[kind + '_checksum'], |
| 253 | factory_checksum) |
| 254 | success = False |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 255 | if validate_checksums: |
| 256 | if success is False: |
| 257 | raise Exception('Checksum mismatch in conf file.') |
| 258 | print 'Config file looks good.' |
| 259 | |
| 260 | def GetFactoryImage(self, board_id, channel): |
| 261 | kind = channel.rsplit('-', 1)[0] |
| 262 | for stanza in self.factory_config: |
| 263 | if board_id not in stanza['qual_ids']: |
| 264 | continue |
| 265 | return (stanza[kind + '_image'], |
| 266 | stanza[kind + '_checksum'], |
| 267 | stanza[kind + '_size']) |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 268 | |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 269 | def HandleUpdatePing(self, data, label=None): |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 270 | web.debug('handle update ping') |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 271 | update_dom = minidom.parseString(data) |
| 272 | root = update_dom.firstChild |
Andrew de los Reyes | 9223f13 | 2010-05-07 17:08:17 -0700 | [diff] [blame] | 273 | if root.hasAttribute('updaterversion') and \ |
| 274 | not root.getAttribute('updaterversion').startswith( |
| 275 | 'MementoSoftwareUpdate'): |
| 276 | web.debug('Got update from unsupported updater:' + \ |
| 277 | root.getAttribute('updaterversion')) |
| 278 | return self.GetNoUpdatePayload() |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 279 | query = root.getElementsByTagName('o:app')[0] |
Charlie Lee | 8c99308 | 2010-02-24 13:27:37 -0800 | [diff] [blame] | 280 | client_version = query.getAttribute('version') |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 281 | channel = query.getAttribute('track') |
Charlie Lee | 8c99308 | 2010-02-24 13:27:37 -0800 | [diff] [blame] | 282 | board_id = query.hasAttribute('board') and query.getAttribute('board') \ |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 283 | or 'x86-generic' |
Charlie Lee | 8c99308 | 2010-02-24 13:27:37 -0800 | [diff] [blame] | 284 | latest_image_path = self.GetLatestImagePath(board_id) |
| 285 | latest_version = self.GetLatestVersion(latest_image_path) |
Andrew de los Reyes | 5262080 | 2010-04-12 13:40:07 -0700 | [diff] [blame] | 286 | hostname = web.ctx.host |
| 287 | |
| 288 | # If this is a factory floor server, return the image here: |
| 289 | if self.factory_config: |
| 290 | (filename, checksum, size) = \ |
| 291 | self.GetFactoryImage(board_id, channel) |
| 292 | if filename is None: |
| 293 | web.debug('unable to find image for board %s' % board_id) |
| 294 | return self.GetNoUpdatePayload() |
| 295 | url = 'http://%s/static/%s' % (hostname, filename) |
| 296 | web.debug('returning update payload ' + url) |
| 297 | return self.GetUpdatePayload(checksum, size, url) |
| 298 | |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 299 | if client_version != 'ForcedUpdate' \ |
Charlie Lee | 8c99308 | 2010-02-24 13:27:37 -0800 | [diff] [blame] | 300 | and not self.CanUpdate(client_version, latest_version): |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 301 | web.debug('no update') |
rtc@google.com | 21a5ca3 | 2009-11-04 18:23:23 +0000 | [diff] [blame] | 302 | return self.GetNoUpdatePayload() |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 303 | if label: |
| 304 | web.debug('Client requested version %s' % label) |
| 305 | # Check that matching build exists |
| 306 | image_path = '%s/%s' % (self.static_dir, label) |
| 307 | if not os.path.exists(image_path): |
| 308 | web.debug('%s not found.' % image_path) |
| 309 | return self.GetNoUpdatePayload() |
| 310 | # Construct a response |
| 311 | ok = self.BuildUpdateImage(image_path) |
| 312 | if ok != True: |
| 313 | web.debug('Failed to build an update image') |
| 314 | return self.GetNoUpdatePayload() |
| 315 | web.debug('serving update: ') |
| 316 | hash = self.GetHash('%s/%s/update.gz' % (self.static_dir, label)) |
| 317 | size = self.GetSize('%s/%s/update.gz' % (self.static_dir, label)) |
Sean O'Connor | 1f7fd36 | 2010-04-07 16:34:52 -0700 | [diff] [blame] | 318 | # In case we configured images to be hosted elsewhere |
| 319 | # (e.g. buildbot's httpd), use that. Otherwise, serve it |
| 320 | # ourselves using web.py's static resource handler. |
| 321 | if self.static_urlbase: |
| 322 | urlbase = self.static_urlbase |
| 323 | else: |
| 324 | urlbase = 'http://%s/static/archive/' % hostname |
| 325 | |
| 326 | url = '%s/%s/update.gz' % (urlbase, label) |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 327 | return self.GetUpdatePayload(hash, size, url) |
Chris Sosa | a73ec16 | 2010-05-03 20:18:02 -0700 | [diff] [blame] | 328 | web.debug('DONE') |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 329 | else: |
| 330 | web.debug('update found %s ' % latest_version) |
| 331 | ok = self.BuildUpdateImage(latest_image_path) |
| 332 | if ok != True: |
| 333 | web.debug('Failed to build an update image') |
| 334 | return self.GetNoUpdatePayload() |
rtc@google.com | ded2240 | 2009-10-26 22:36:21 +0000 | [diff] [blame] | 335 | |
Sean O'Connor | 14b6a0a | 2010-03-20 23:23:48 -0700 | [diff] [blame] | 336 | hash = self.GetHash('%s/update.gz' % self.static_dir) |
| 337 | size = self.GetSize('%s/update.gz' % self.static_dir) |
| 338 | |
| 339 | url = 'http://%s/static/update.gz' % hostname |
| 340 | return self.GetUpdatePayload(hash, size, url) |