def testConvertTranslatedPath(self): """Tests that we convert a translated path to a usable xbuddy path.""" path = 'remote/latest-canary' translated_path = 'taco-release/R36-5761.0.0/chromiumos_test_image.bin' self.assertEqual( dev_server_wrapper.ConvertTranslatedPath(path, translated_path), 'remote/taco-release/R36-5761.0.0/test') path = 'latest' translated_path = 'taco/R36-5600.0.0/chromiumos_image.bin' self.assertEqual( dev_server_wrapper.ConvertTranslatedPath(path, translated_path), 'local/taco/R36-5600.0.0/dev')
def GetPayloadDir(self, device): """Get directory of payload for update. This method is used to obtain the directory of payload for cros-flash. The given path 'self.image' is passed in when initializing RemoteDeviceUpdater. If self.image is a directory, we directly use the provided update payload(s) in this directory. If self.image is an image, let devserver access it and generate payloads. If not in the above cases, let devserver first obtain the image path. Then devserver will access the image and generate payloads. Args: device: A ChromiumOSDevice object. Returns: A string payload_dir, that represents the payload directory. """ payload_dir = self.tempdir if os.path.isdir(self.image): # The given path is a directory. payload_dir = self.image logging.info('Using provided payloads in %s', payload_dir) elif os.path.isfile(self.image): # The given path is an image. logging.info('Using image %s', self.image) ds_wrapper.GetUpdatePayloadsFromLocalPath( self.image, payload_dir, src_image_to_delta=self.src_image_to_delta, static_dir=DEVSERVER_STATIC_DIR) else: self.board = cros_build_lib.GetBoard(device_board=device.board, override_board=self.board, force=self.yes) if not self.board: raise FlashError('No board identified') if not self.force and self.board != device.board: # If a board was specified, it must be compatible with the device. raise FlashError('Device (%s) is incompatible with board %s' % (device.board, self.board)) logging.info('Board is %s', self.board) # Translate the xbuddy path to get the exact image to use. translated_path, resolved_path = ds_wrapper.GetImagePathWithXbuddy( self.image, self.board, static_dir=DEVSERVER_STATIC_DIR, lookup_only=True) logging.info('Using image %s', translated_path) # Convert the translated path to be used in the update request. image_path = ds_wrapper.ConvertTranslatedPath( resolved_path, translated_path) # Launch a local devserver to generate/serve update payloads. ds_wrapper.GetUpdatePayloads( image_path, payload_dir, board=self.board, src_image_to_delta=self.src_image_to_delta, static_dir=DEVSERVER_STATIC_DIR) return payload_dir