| OLD | NEW |
| 1 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2009-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 from buildutil import BuildObject | 5 from buildutil import BuildObject |
| 6 from xml.dom import minidom | 6 from xml.dom import minidom |
| 7 | 7 |
| 8 import cherrypy | 8 import cherrypy |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 class Autoupdate(BuildObject): | 40 class Autoupdate(BuildObject): |
| 41 """Class that contains functionality that handles Chrome OS update pings. | 41 """Class that contains functionality that handles Chrome OS update pings. |
| 42 | 42 |
| 43 Members: | 43 Members: |
| 44 serve_only: Serve only pre-built updates. static_dir must contain update.gz | 44 serve_only: Serve only pre-built updates. static_dir must contain update.gz |
| 45 and stateful.tgz. | 45 and stateful.tgz. |
| 46 factory_config: Path to the factory config file if handling factory | 46 factory_config: Path to the factory config file if handling factory |
| 47 requests. | 47 requests. |
| 48 use_test_image: Use chromiumos_test_image.bin rather than the standard. | 48 use_test_image: Use chromiumos_test_image.bin rather than the standard. |
| 49 static_url_base: base URL, other than devserver, for update images. | 49 static_url_base: base URL, other than devserver, for update images. |
| 50 client_prefix: The prefix for the update engine client. | |
| 51 forced_image: Path to an image to use for all updates. | 50 forced_image: Path to an image to use for all updates. |
| 52 forced_payload: Path to pre-generated payload to serve. | 51 forced_payload: Path to pre-generated payload to serve. |
| 53 port: port to host devserver | 52 port: port to host devserver |
| 54 proxy_port: port of local proxy to tell client to connect to you through. | 53 proxy_port: port of local proxy to tell client to connect to you through. |
| 55 src_image: If specified, creates a delta payload from this image. | 54 src_image: If specified, creates a delta payload from this image. |
| 56 vm: Set for VM images (doesn't patch kernel) | 55 vm: Set for VM images (doesn't patch kernel) |
| 57 board: board for the image. Needed for pre-generating of updates. | 56 board: board for the image. Needed for pre-generating of updates. |
| 58 copy_to_static_root: Copies images generated from the cache to | 57 copy_to_static_root: Copies images generated from the cache to |
| 59 ~/static. | 58 ~/static. |
| 60 """ | 59 """ |
| 61 | 60 |
| 62 def __init__(self, serve_only=None, test_image=False, urlbase=None, | 61 def __init__(self, serve_only=None, test_image=False, urlbase=None, |
| 63 factory_config_path=None, client_prefix=None, | 62 factory_config_path=None, |
| 64 forced_image=None, forced_payload=None, | 63 forced_image=None, forced_payload=None, |
| 65 port=8080, proxy_port=None, src_image='', vm=False, board=None, | 64 port=8080, proxy_port=None, src_image='', vm=False, board=None, |
| 66 copy_to_static_root=True, private_key=None, | 65 copy_to_static_root=True, private_key=None, |
| 67 *args, **kwargs): | 66 *args, **kwargs): |
| 68 super(Autoupdate, self).__init__(*args, **kwargs) | 67 super(Autoupdate, self).__init__(*args, **kwargs) |
| 69 self.serve_only = serve_only | 68 self.serve_only = serve_only |
| 70 self.factory_config = factory_config_path | 69 self.factory_config = factory_config_path |
| 71 self.use_test_image = test_image | 70 self.use_test_image = test_image |
| 72 if urlbase: | 71 if urlbase: |
| 73 self.urlbase = urlbase | 72 self.urlbase = urlbase |
| 74 else: | 73 else: |
| 75 self.urlbase = None | 74 self.urlbase = None |
| 76 | 75 |
| 77 self.client_prefix = client_prefix | |
| 78 self.forced_image = forced_image | 76 self.forced_image = forced_image |
| 79 self.forced_payload = forced_payload | 77 self.forced_payload = forced_payload |
| 80 self.src_image = src_image | 78 self.src_image = src_image |
| 81 self.proxy_port = proxy_port | 79 self.proxy_port = proxy_port |
| 82 self.vm = vm | 80 self.vm = vm |
| 83 self.board = board | 81 self.board = board |
| 84 self.copy_to_static_root = copy_to_static_root | 82 self.copy_to_static_root = copy_to_static_root |
| 85 self.private_key = private_key | 83 self.private_key = private_key |
| 86 | 84 |
| 87 # Path to pre-generated file. | 85 # Path to pre-generated file. |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 os.system('rm -rf "%s"' % full_cache_dir) | 368 os.system('rm -rf "%s"' % full_cache_dir) |
| 371 os.makedirs(full_cache_dir) | 369 os.makedirs(full_cache_dir) |
| 372 return_path = self.GenerateUpdateImage(image_path, | 370 return_path = self.GenerateUpdateImage(image_path, |
| 373 full_cache_dir) | 371 full_cache_dir) |
| 374 | 372 |
| 375 # Clean up cache dir since it's not valid. | 373 # Clean up cache dir since it's not valid. |
| 376 if not return_path: | 374 if not return_path: |
| 377 os.system('rm -rf "%s"' % full_cache_dir) | 375 os.system('rm -rf "%s"' % full_cache_dir) |
| 378 return None | 376 return None |
| 379 else: | 377 else: |
| 380 assert (return_path == update_path, | 378 assert return_path == update_path, \ |
| 381 'Returned path %s not equal to %s' % (return_path, update_path)) | 379 'Returned path %s not equal to %s' % (return_path, update_path) |
| 382 | 380 |
| 383 self.pregenerated_path = update_path | 381 self.pregenerated_path = update_path |
| 384 | 382 |
| 385 # Generation complete, copy if requested. | 383 # Generation complete, copy if requested. |
| 386 if self.copy_to_static_root: | 384 if self.copy_to_static_root: |
| 387 # The final results exist directly in static | 385 # The final results exist directly in static |
| 388 update_payload = os.path.join(static_image_dir, | 386 update_payload = os.path.join(static_image_dir, |
| 389 UPDATE_FILE) | 387 UPDATE_FILE) |
| 390 stateful_payload = os.path.join(static_image_dir, | 388 stateful_payload = os.path.join(static_image_dir, |
| 391 STATEFUL_FILE) | 389 STATEFUL_FILE) |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 static_urlbase = '%s/static' % self.hostname | 608 static_urlbase = '%s/static' % self.hostname |
| 611 | 609 |
| 612 # If we have a proxy port, adjust the URL we instruct the client to | 610 # If we have a proxy port, adjust the URL we instruct the client to |
| 613 # use to go through the proxy. | 611 # use to go through the proxy. |
| 614 if self.proxy_port: | 612 if self.proxy_port: |
| 615 static_urlbase = _ChangeUrlPort(static_urlbase, self.proxy_port) | 613 static_urlbase = _ChangeUrlPort(static_urlbase, self.proxy_port) |
| 616 | 614 |
| 617 _LogMessage('Using static url base %s' % static_urlbase) | 615 _LogMessage('Using static url base %s' % static_urlbase) |
| 618 _LogMessage('Handling update ping as %s: %s' % (self.hostname, data)) | 616 _LogMessage('Handling update ping as %s: %s' % (self.hostname, data)) |
| 619 | 617 |
| 620 # Check the client prefix to make sure you can support this type of update. | |
| 621 update_dom = minidom.parseString(data) | 618 update_dom = minidom.parseString(data) |
| 622 root = update_dom.firstChild | 619 root = update_dom.firstChild |
| 623 if (root.hasAttribute('updaterversion') and | |
| 624 not root.getAttribute('updaterversion').startswith(self.client_prefix)): | |
| 625 _LogMessage('Got update from unsupported updater:' + | |
| 626 root.getAttribute('updaterversion')) | |
| 627 return self.GetNoUpdatePayload() | |
| 628 | 620 |
| 629 # We only generate update payloads for updatecheck requests. | 621 # We only generate update payloads for updatecheck requests. |
| 630 update_check = root.getElementsByTagName('o:updatecheck') | 622 update_check = root.getElementsByTagName('o:updatecheck') |
| 631 if not update_check: | 623 if not update_check: |
| 632 _LogMessage('Non-update check received. Returning blank payload.') | 624 _LogMessage('Non-update check received. Returning blank payload.') |
| 633 # TODO(sosa): Generate correct non-updatecheck payload to better test | 625 # TODO(sosa): Generate correct non-updatecheck payload to better test |
| 634 # update clients. | 626 # update clients. |
| 635 return self.GetNoUpdatePayload() | 627 return self.GetNoUpdatePayload() |
| 636 | 628 |
| 637 # Since this is an updatecheck, get information about the requester. | 629 # Since this is an updatecheck, get information about the requester. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 661 is_delta_format = self._IsDeltaFormatFile(filename) | 653 is_delta_format = self._IsDeltaFormatFile(filename) |
| 662 if label: | 654 if label: |
| 663 url = '%s/%s/%s' % (static_urlbase, label, payload_path) | 655 url = '%s/%s/%s' % (static_urlbase, label, payload_path) |
| 664 else: | 656 else: |
| 665 url = '%s/%s' % (static_urlbase, payload_path) | 657 url = '%s/%s' % (static_urlbase, payload_path) |
| 666 | 658 |
| 667 _LogMessage('Responding to client to use url %s to get image.' % url) | 659 _LogMessage('Responding to client to use url %s to get image.' % url) |
| 668 return self.GetUpdatePayload(hash, sha256, size, url, is_delta_format) | 660 return self.GetUpdatePayload(hash, sha256, size, url, is_delta_format) |
| 669 else: | 661 else: |
| 670 return self.GetNoUpdatePayload() | 662 return self.GetNoUpdatePayload() |
| OLD | NEW |