Ejemplo n.º 1
0
 def testUpdateRootfs(self):
     """Tests that update methods are called correctly."""
     with mock.patch('os.path.exists', return_value=True):
         flash.Flash(self.DEVICE, self.IMAGE, stateful_update=False)
         self.assertFalse(
             self.updater_mock.patched['UpdateStateful'].called)
         self.assertTrue(self.updater_mock.patched['UpdateRootfs'].called)
Ejemplo n.º 2
0
    def Run(self):
        """Perform the cros flash command."""
        self.options.Freeze()

        try:
            flash.Flash(
                self.options.device,
                self.options.image,
                board=self.options.board,
                version=self._GetDefaultVersion(),
                install=self.options.install,
                src_image_to_delta=self.options.src_image_to_delta,
                rootfs_update=self.options.rootfs_update,
                stateful_update=self.options.stateful_update,
                clobber_stateful=self.options.clobber_stateful,
                reboot=self.options.reboot,
                wipe=self.options.wipe,
                ssh_private_key=self.options.private_key,
                ping=self.options.ping,
                disable_rootfs_verification=self.options.
                disable_rootfs_verification,
                clear_cache=self.options.clear_cache,
                yes=self.options.yes,
                force=self.options.force,
                debug=self.options.debug,
                send_payload_in_parallel=self.options.send_payload_in_parallel)
            logging.notice('cros flash completed successfully.')
        except dev_server_wrapper.ImagePathError:
            logging.error(
                'To get the latest remote image, please run:\n'
                'cros flash --board=%s %s remote/latest', self.options.board,
                self.options.device.raw)
            raise
Ejemplo n.º 3
0
 def testLocalBadImagePath(self):
   """Tests that using an image not having the magic bytes has prompt."""
   self.isgpt_mock.return_value = False
   with mock.patch('os.path.isfile', return_value=True):
     with mock.patch.object(cros_build_lib, 'BooleanPrompt') as mock_prompt:
       mock_prompt.return_value = False
       flash.Flash(self.Device('/dev/foo'), self.IMAGE)
       self.assertTrue(mock_prompt.called)
Ejemplo n.º 4
0
 def testLocalImagePathInstall(self):
     """Tests that imaging methods are called correctly."""
     with mock.patch('os.path.isfile', return_value=True):
         flash.Flash(self.Device('/dev/foo'),
                     self.IMAGE,
                     board='taco',
                     install=True)
         self.assertTrue(
             self.imager_mock.patched['InstallImageToDevice'].called)
Ejemplo n.º 5
0
 def testNonLocalImagePath(self):
     """Tests that we try to get the image path using xbuddy."""
     with mock.patch.object(
             dev_server_wrapper,
             'GetImagePathWithXbuddy',
             return_value=('translated/xbuddy/path',
                           'resolved/xbuddy/path')) as mock_xbuddy:
         with mock.patch('os.path.isfile', return_value=False):
             with mock.patch('os.path.isdir', return_value=False):
                 flash.Flash(self.Device('/dev/foo'), self.IMAGE)
                 self.assertTrue(mock_xbuddy.called)
Ejemplo n.º 6
0
    def testTestImage(self):
        """Tests that we download the test image when the full payload fails."""
        with mock.patch.object(
                dev_server_wrapper,
                'GetImagePathWithXbuddy',
                side_effect=(dev_server_wrapper.ImagePathError,
                             ('translated/xbuddy/path',
                              'resolved/xbuddy/path'))) as mock_xbuddy:
            with mock.patch('os.path.exists', side_effect=self._ExistsMock):
                flash.Flash(self.DEVICE, self.IMAGE)

            # Call to download full_payload and image. No other calls.
            mock_xbuddy.assert_has_calls([
                mock.call('/path/to/image/full_payload',
                          'board',
                          None,
                          silent=True),
                mock.call('/path/to/image', 'board', None)
            ])
            self.assertEqual(mock_xbuddy.call_count, 2)
Ejemplo n.º 7
0
    def testFullPayload(self):
        """Tests that we download full_payload and stateful using xBuddy."""
        with mock.patch.object(
                dev_server_wrapper,
                'GetImagePathWithXbuddy',
                return_value=('translated/xbuddy/path',
                              'resolved/xbuddy/path')) as mock_xbuddy:
            with mock.patch('os.path.exists', return_value=True):
                flash.Flash(self.DEVICE, self.IMAGE)

            # Call to download full_payload and stateful. No other calls.
            mock_xbuddy.assert_has_calls([
                mock.call('/path/to/image/full_payload',
                          mock.ANY,
                          static_dir=flash.DEVSERVER_STATIC_DIR,
                          silent=True),
                mock.call('/path/to/image/stateful',
                          mock.ANY,
                          static_dir=flash.DEVSERVER_STATIC_DIR,
                          silent=True)
            ])
            self.assertEqual(mock_xbuddy.call_count, 2)
Ejemplo n.º 8
0
  def Run(self):
    """Perfrom the cros flash command."""
    self.options.Freeze()

    if (self.options.device.scheme == commandline.DEVICE_SCHEME_SSH and
        not cros_build_lib.IsInsideChroot()):
      chroot_dir = os.path.join(constants.SOURCE_ROOT,
                                constants.DEFAULT_CHROOT_DIR)

      if not cros_sdk_lib.MountChroot(chroot=chroot_dir, create=False):
        raise Exception('Unable to find chroot.')

    try:
      flash.Flash(
          self.options.device,
          self.options.image,
          board=self.options.board,
          install=self.options.install,
          src_image_to_delta=self.options.src_image_to_delta,
          rootfs_update=self.options.rootfs_update,
          stateful_update=self.options.stateful_update,
          clobber_stateful=self.options.clobber_stateful,
          reboot=self.options.reboot,
          wipe=self.options.wipe,
          ssh_private_key=self.options.private_key,
          ping=self.options.ping,
          disable_rootfs_verification=self.options.disable_rootfs_verification,
          clear_cache=self.options.clear_cache,
          yes=self.options.yes,
          force=self.options.force,
          debug=self.options.debug,
          send_payload_in_parallel=self.options.send_payload_in_parallel,
          experimental_au=self.options.experimental_au)
      logging.notice('cros flash completed successfully.')
    except dev_server_wrapper.ImagePathError:
      logging.error('To get the latest remote image, please run:\n'
                    'cros flash --board=%s %s remote/latest',
                    self.options.board, self.options.device.raw)
      raise
Ejemplo n.º 9
0
 def flash_with_retry():
     flash.Flash(self.remote,
                 xbuddy_path,
                 board=self.board,
                 clobber_stateful=True,
                 disable_rootfs_verification=True)
Ejemplo n.º 10
0
 def testChooseRemovableDevice(self):
     """Tests that we ask user to choose a device if none is given."""
     flash.Flash(self.Device(''), self.IMAGE)
     self.assertTrue(
         self.imager_mock.patched['ChooseRemovableDevice'].called)
Ejemplo n.º 11
0
 def testSkipPromptNonRemovableDevice(self):
     """Tests that we skip the prompt for non-removable with --yes."""
     with mock.patch.object(cros_build_lib, 'BooleanPrompt') as mock_prompt:
         flash.Flash(self.Device('/dev/dummy'), self.IMAGE, yes=True)
         self.assertFalse(mock_prompt.called)
Ejemplo n.º 12
0
 def testConfirmNonRemovableDevice(self):
     """Tests that we ask user to confirm if the device is not removable."""
     with mock.patch.object(cros_build_lib, 'BooleanPrompt') as mock_prompt:
         flash.Flash(self.Device('/dev/dummy'), self.IMAGE)
         self.assertTrue(mock_prompt.called)
Ejemplo n.º 13
0
 def testUpdateStateful(self):
     """Tests that update methods are called correctly."""
     with mock.patch('os.path.exists', side_effect=self._ExistsMock):
         flash.Flash(self.DEVICE, self.IMAGE, rootfs_update=False)
         self.assertTrue(self.updater_mock.patched['UpdateStateful'].called)
         self.assertFalse(self.updater_mock.patched['UpdateRootfs'].called)