Ejemplo n.º 1
0
    def TestDeploy(self):
        """Tests the deploy command."""
        packages = ['dev-python/cherrypy', 'app-portage/portage-utils']
        # Set the installation root to /usr/local so that the command does not
        # attempt to remount rootfs (which leads to VM reboot).
        cmd = self.BuildCommand(
            'deploy',
            device=self.vm.device_addr,
            pos_args=packages,
            opt_args=['--log-level=info', '--root=/usr/local'])

        logging.info('Test to uninstall packages on the VM device.')
        with cros_build_lib.OutputCapturer() as output:
            result = cros_build_lib.RunCommand(cmd + ['--unmerge'],
                                               error_code_ok=True)

        if result.returncode:
            logging.error('Failed to uninstall packages on the VM device.')
            raise CommandError(result.error)

        captured_output = output.GetStdout() + output.GetStderr()
        for event in deploy.BrilloDeployOperation.UNMERGE_EVENTS:
            if event not in captured_output:
                logging.error(
                    'Strings used by deploy.BrilloDeployOperation to update '
                    'the progress bar have been changed. Please update the '
                    'strings in UNMERGE_EVENTS')
                raise CommandError()

        logging.info('Test to install packages on the VM device.')
        with cros_build_lib.OutputCapturer() as output:
            result = cros_build_lib.RunCommand(cmd, error_code_ok=True)

        if result.returncode:
            logging.error('Failed to install packages on the VM device.')
            raise CommandError(result.error)

        captured_output = output.GetStdout() + output.GetStderr()
        for event in deploy.BrilloDeployOperation.MERGE_EVENTS:
            if event not in captured_output:
                logging.error(
                    'Strings used by deploy.BrilloDeployOperation to update '
                    'the progress bar have been changed. Please update the '
                    'strings in MERGE_EVENTS')
                raise CommandError()

        # Verify that the packages are installed.
        with remote_access.ChromiumOSDeviceHandler(
                remote_access.LOCALHOST, port=self.vm.port) as device:
            try:
                device.RunCommand(['python', '-c', '"import cherrypy"'])
                device.RunCommand(['qmerge', '-h'])
            except cros_build_lib.RunCommandError as e:
                logging.error('Unable to verify packages installed on VM: %s',
                              e)
                raise CommandError()
Ejemplo n.º 2
0
    def _UpdateConfigDump(self):
        """Generate and dump configs base on the new template_file"""
        # Clear the cached SiteConfig, if there was one.
        config_lib.ClearConfigCache()

        view_config_path = os.path.join(self.chromite_dir, 'bin',
                                        'cbuildbot_view_config')
        cmd = [view_config_path, '--update']

        try:
            cros_build_lib.RunCommand(cmd,
                                      cwd=os.path.dirname(self.chromite_dir))
        except:
            logging.error(
                'Failed to update configs. Please check the format of the '
                'remote template file %s and the local template copy %s',
                self.template_gs_path, self.CONFIG_DUMP_PATH)
            raise

        show_waterfall_path = os.path.join(self.chromite_dir, 'bin',
                                           'cros_show_waterfall_layout')
        cmd = [show_waterfall_path]
        layout_file_name = os.path.join(self.chromite_dir,
                                        'cbuildbot/waterfall_layout_dump.txt')
        with cros_build_lib.OutputCapturer(stdout_path=layout_file_name):
            cros_build_lib.RunCommand(cmd,
                                      cwd=os.path.dirname(self.chromite_dir))
Ejemplo n.º 3
0
  def testListTryjobs(self):
    """Test we can generate results for --list."""
    with cros_build_lib.OutputCapturer() as output:
      cros_tryjob.PrintKnownConfigs(
          self.site_config, production=False, build_config_fragments=[])

    # We have at least 100 lines of output, and no error out.
    self.assertGreater(len(output.GetStdoutLines()), 100)
    self.assertFalse(output.GetStderr())
Ejemplo n.º 4
0
  def testListProduction(self):
    """Test option verification with config list behavior."""
    self.SetupCommandMock([
        '--list', '--production',
    ])

    with self.assertRaises(cros_build_lib.DieSystemExit) as cm:
      with cros_build_lib.OutputCapturer(quiet_fail=True):  # Hide list output.
        cros_tryjob.VerifyOptions(self.cmd_mock.inst.options, self.site_config)
    self.assertEqual(cm.exception.code, 0)
Ejemplo n.º 5
0
def main(argv):
  parser = _GetParser()
  opts = parser.parse_args(argv)
  opts.Freeze()

  if opts.dry_run:
    logging.getLogger().setLevel(logging.DEBUG)

  if not os.path.isfile(opts.source_image):
    raise UploadGceImageRuntimError('%s is not a valid file.')

  source_dir, source_image_name = os.path.split(opts.source_image)
  with osutils.TempDir() as tempdir:
    logging.info('Generating tarball from %s', opts.source_image)
    tarball_name = commands.BuildGceTarball(tempdir, source_dir,
                                            source_image_name)
    # We must generate a uuid when uploading the tarball because repeated
    # uploads are likely to be named similarly. We'll just use tempdir to keep
    # files separate.
    temp_tarball_dir = os.path.join(opts.temp_gcs_path,
                                    os.path.basename(tempdir))
    gs_context = gs.GSContext(init_boto=True, retries=5, acl='private',
                              dry_run=opts.dry_run)
    gc_context = gcloud.GCContext(opts.project, dry_run=opts.dry_run)
    try:
      logging.info('Uploading tarball %s to %s',
                   tarball_name, temp_tarball_dir)
      gs_context.CopyInto(os.path.join(tempdir, tarball_name), temp_tarball_dir)
      logging.info('Creating image %s', opts.target_name)
      gc_context.CreateImage(opts.target_name,
                             source_uri=os.path.join(temp_tarball_dir,
                                                     tarball_name))
    except:
      logging.error('Oops! Something went wonky.')
      logging.error('Trying to clean up temporary artifacts...')
      try:
        with cros_build_lib.OutputCapturer() as output_capturer:
          gc_context.ListImages()
        if opts.target_name in ''.join(output_capturer.GetStdoutLines()):
          logging.info('Removing image %s', opts.target_name)
          gc_context.DeleteImage(opts.target_name, quiet=True)
      except gcloud.GCContextException:
        # Gobble up this error so external error is visible.
        logging.error('Failed to clean up image %s', opts.target_name)

      raise
    finally:
      logging.info('Removing GS tempdir %s', temp_tarball_dir)
      gs_context.Remove(temp_tarball_dir, ignore_missing=True)

  logging.info('All done!')
Ejemplo n.º 6
0
    def CaptureOutputInBackground(self, func, *args, **kwargs):
        """Launch func in background and capture its output.

    Args:
      func: Function to execute in the background and whose output is to be
        captured.
      log_level: Logging level to run the func at. By default, it runs at log
        level info.
    """
        log_level = kwargs.pop('log_level', logging.INFO)
        restore_log_level = logging.getLogger().getEffectiveLevel()
        logging.getLogger().setLevel(log_level)
        try:
            with cros_build_lib.OutputCapturer(stdout_path=self._stdout_path,
                                               stderr_path=self._stderr_path,
                                               quiet_fail=False):
                func(*args, **kwargs)
        finally:
            self._queue.put(_BackgroundTaskComplete())
            logging.getLogger().setLevel(restore_log_level)
Ejemplo n.º 7
0
    def _UpdateConfigDump(self):
        """Generate and dump configs base on the new template_file"""
        # Clear the cached SiteConfig, if there was one.
        config_lib.ClearConfigCache()

        view_config_path = os.path.join(self.chromite_dir, 'bin',
                                        'cbuildbot_view_config')
        cmd = [view_config_path, '--update']

        cros_build_lib.RunCommand(cmd, cwd=os.path.dirname(self.chromite_dir))

        show_waterfall_path = os.path.join(self.chromite_dir, 'bin',
                                           'cros_show_waterfall_layout')
        cmd = [show_waterfall_path]
        layout_file_name = os.path.join(self.chromite_dir,
                                        'cbuildbot/waterfall_layout_dump.txt')
        with cros_build_lib.OutputCapturer(
                stdout_path=layout_file_name) as output:
            cros_build_lib.RunCommand(cmd,
                                      cwd=os.path.dirname(self.chromite_dir))

        logging.info("waterfall_layout_dump %s" % output.GetStdout())