def ParseGomaConfig(goma_message, chroot_path):
  """Parse a goma config message."""
  assert isinstance(goma_message, common_pb2.GomaConfig)

  if not goma_message.goma_dir:
    return None

  # Parse the goma config.
  chromeos_goma_dir = goma_message.chromeos_goma_dir or None
  if goma_message.goma_approach == common_pb2.GomaConfig.RBE_STAGING:
    goma_approach = goma_util.GomaApproach('?staging',
                                           'staging-goma.chromium.org', True)
  else:
    goma_approach = goma_util.GomaApproach('?prod', 'goma.chromium.org', True)

  # Note that we are not specifying the goma log_dir so that goma will create
  # and use a tmp dir for the logs.
  stats_filename = goma_message.stats_file or None
  counterz_filename = goma_message.counterz_file or None

  return goma_util.Goma(goma_message.goma_dir,
                        goma_message.goma_client_json,
                        stage_name='BuildAPI',
                        chromeos_goma_dir=chromeos_goma_dir,
                        chroot_dir=chroot_path,
                        goma_approach=goma_approach,
                        stats_filename=stats_filename,
                        counterz_filename=counterz_filename)
  def testExtraEnvGomaApproach(self):
    """Test the chroot env building with a goma approach."""
    goma_dir = os.path.join(self.tempdir, 'goma')
    goma_client_json = os.path.join(self.tempdir, 'goma_client.json')
    chroot_dir = os.path.join(self.tempdir, 'chroot')
    chroot_tmp = os.path.join(chroot_dir, 'tmp')
    osutils.Touch(goma_client_json)
    osutils.SafeMakedirs(goma_dir)
    osutils.SafeMakedirs(chroot_tmp)
    goma_approach = goma_util.GomaApproach('foo', 'bar', True)

    goma = goma_util.Goma(goma_dir, goma_client_json,
                          chroot_dir=chroot_dir, goma_approach=goma_approach)

    env = goma.GetExtraEnv()

    # Make sure the extra environment specified by goma_approach is present.
    self.assertEqual(env['GOMA_RPC_EXTRA_PARAMS'], 'foo')
    self.assertEqual(env['GOMA_SERVER_HOST'], 'bar')
    self.assertEqual(env['GOMA_ARBITRARY_TOOLCHAIN_SUPPORT'], 'true')
Esempio n. 3
0
    def _SetupGomaIfNecessary(self):
        """Sets up goma envs if necessary.

    Updates related env vars, and returns args to chroot.

    Returns:
      args which should be provided to chroot in order to enable goma.
      If goma is unusable or disabled, None is returned.
    """
        if not self._ShouldEnableGoma():
            return None

        # TODO(crbug.com/751010): Revisit to enable DepsCache for non-chrome-pfq
        # bots, too.
        use_goma_deps_cache = self._run.config.name.endswith('chrome-pfq')
        goma_approach = goma_util.GomaApproach('?prod', 'goma.chromium.org',
                                               True)
        goma = goma_util.Goma(
            self._run.options.goma_dir,
            self._run.options.goma_client_json,
            stage_name=self.StageNamePrefix() if use_goma_deps_cache else None,
            chromeos_goma_dir=self._run.options.chromeos_goma_dir,
            goma_approach=goma_approach)

        # Set USE_GOMA env var so that chrome is built with goma.
        if not self._IsGomaEnabledOnlyForLogs():
            self._portage_extra_env['USE_GOMA'] = 'true'
        self._portage_extra_env.update(goma.GetChrootExtraEnv())

        # Keep GOMA_TMP_DIR for Report stage to upload logs.
        self._run.attrs.metadata.UpdateWithDict(
            {'goma_tmp_dir': goma.goma_tmp_dir})

        # Mount goma directory and service account json file (if necessary)
        # into chroot.
        chroot_args = ['--goma_dir', goma.chromeos_goma_dir]
        if goma.goma_client_json:
            chroot_args.extend(['--goma_client_json', goma.goma_client_json])
        return chroot_args
Esempio n. 4
0
    def testChrootCallToGoma(self):
        """Test calls to goma."""
        path = '/chroot/path'
        cache_dir = '/cache/dir'
        chrome_root = '/chrome/root'
        use_flags = [{'flag': 'useflag1'}, {'flag': 'useflag2'}]
        features = [{'feature': 'feature1'}, {'feature': 'feature2'}]
        goma_test_dir = '/goma/test/dir'
        goma_test_json_string = 'goma_json'
        chromeos_goma_test_dir = '/chromeos/goma/test/dir'

        # Patch goma constructor to avoid creating misc dirs.
        patch = self.PatchObject(goma_util, 'Goma')

        goma_config = common_pb2.GomaConfig(
            goma_dir=goma_test_dir, goma_client_json=goma_test_json_string)
        chroot_message = common_pb2.Chroot(path=path,
                                           cache_dir=cache_dir,
                                           chrome_dir=chrome_root,
                                           env={
                                               'use_flags': use_flags,
                                               'features': features
                                           },
                                           goma=goma_config)

        controller_util.ParseChroot(chroot_message)
        patch.assert_called_with(goma_test_dir,
                                 goma_test_json_string,
                                 stage_name='BuildAPI',
                                 chromeos_goma_dir=None,
                                 chroot_dir=path,
                                 goma_approach=None)

        goma_config.chromeos_goma_dir = chromeos_goma_test_dir
        chroot_message = common_pb2.Chroot(path=path,
                                           cache_dir=cache_dir,
                                           chrome_dir=chrome_root,
                                           env={
                                               'use_flags': use_flags,
                                               'features': features
                                           },
                                           goma=goma_config)

        controller_util.ParseChroot(chroot_message)
        patch.assert_called_with(goma_test_dir,
                                 goma_test_json_string,
                                 stage_name='BuildAPI',
                                 chromeos_goma_dir=chromeos_goma_test_dir,
                                 chroot_dir=path,
                                 goma_approach=None)

        goma_config.goma_approach = common_pb2.GomaConfig.RBE_PROD
        chroot_message = common_pb2.Chroot(path=path,
                                           cache_dir=cache_dir,
                                           chrome_dir=chrome_root,
                                           env={
                                               'use_flags': use_flags,
                                               'features': features
                                           },
                                           goma=goma_config)

        controller_util.ParseChroot(chroot_message)
        patch.assert_called_with(goma_test_dir,
                                 goma_test_json_string,
                                 stage_name='BuildAPI',
                                 chromeos_goma_dir=chromeos_goma_test_dir,
                                 chroot_dir=path,
                                 goma_approach=goma_util.GomaApproach(
                                     '?prod', 'goma.chromium.org', True))

        goma_config.goma_approach = common_pb2.GomaConfig.RBE_STAGING
        chroot_message = common_pb2.Chroot(path=path,
                                           cache_dir=cache_dir,
                                           chrome_dir=chrome_root,
                                           env={
                                               'use_flags': use_flags,
                                               'features': features
                                           },
                                           goma=goma_config)

        controller_util.ParseChroot(chroot_message)
        patch.assert_called_with(goma_test_dir,
                                 goma_test_json_string,
                                 stage_name='BuildAPI',
                                 chromeos_goma_dir=chromeos_goma_test_dir,
                                 chroot_dir=path,
                                 goma_approach=goma_util.GomaApproach(
                                     '?staging', 'staging-goma.chromium.org',
                                     True))