예제 #1
0
    def _initConfig(self,
                    bot_id,
                    extra_argv=None,
                    override_hw_test_config=None):
        """Return normal options/build_config for |bot_id|"""
        site_config = chromeos_config.GetConfig()
        build_config = copy.deepcopy(site_config[bot_id])
        build_config['master'] = False
        build_config['important'] = False

        # Use the cbuildbot parser to create properties and populate default values.
        parser = cbuildbot._CreateParser()
        argv = (
            ['-r', self.buildroot, '--buildbot', '--debug', '--nochromesdk'] +
            (extra_argv if extra_argv else []) + [bot_id])
        options, _ = cbuildbot._ParseCommandLine(parser, argv)

        # Yikes.
        options.managed_chrome = build_config['sync_chrome']

        # Iterate through override and update HWTestConfig attributes.
        if override_hw_test_config:
            for key, val in override_hw_test_config.iteritems():
                for hw_test in build_config.hw_tests:
                    setattr(hw_test, key, val)

        return cbuildbot_run.BuilderRun(options, site_config, build_config,
                                        self._manager)
    def setUp(self):
        self.buildroot = os.path.join(self.tempdir, 'buildroot')
        osutils.SafeMakedirs(self.buildroot)
        # Always stub RunCommmand out as we use it in every method.
        self.site_config = config_lib_unittest.MockSiteConfig()
        self.build_config = config_lib_unittest.MockBuildConfig()
        self.bot_id = self.build_config.name
        self.build_config['master'] = False
        self.build_config['important'] = False

        # Use the cbuildbot parser to create properties and populate default values.
        self.parser = cbuildbot._CreateParser()

        argv = ['-r', self.buildroot, '--buildbot', '--debug', self.bot_id]
        self.options, _ = cbuildbot._ParseCommandLine(self.parser, argv)
        self.options.bootstrap = False
        self.options.clean = False
        self.options.resume = False
        self.options.sync = False
        self.options.build = False
        self.options.uprev = False
        self.options.tests = False
        self.options.archive = False
        self.options.remote_test_status = False
        self.options.patches = None
        self.options.prebuilts = False

        self._manager = parallel.Manager()
        self._manager.__enter__()
        self.run = cbuildbot_run.BuilderRun(self.options, self.site_config,
                                            self.build_config, self._manager)

        self.rc.AddCmdResult(
            [constants.PATH_TO_CBUILDBOT, '--reexec-api-version'],
            output=constants.REEXEC_API_VERSION)
  def _InitConfig(self, bot_id, extra_argv=None):
    """Return normal options/build_config for |bot_id|"""
    build_config = self.site_config[bot_id]

    # Use the cbuildbot parser to create properties and populate default values.
    parser = cbuildbot._CreateParser()
    argv = (['--buildbot',
             '--buildroot', self.buildroot,
             '--workspace', self.workspace] +
            (extra_argv if extra_argv else []) + [bot_id])
    options = cbuildbot.ParseCommandLine(parser, argv)

    return cbuildbot_run.BuilderRun(
        options, self.site_config, build_config, self._manager)
예제 #4
0
    def _NewBuilderRun(self, options=None, config=None):
        """Create a BuilderRun objection from options and config values.

    Args:
      options: Specify options or default to DEFAULT_OPTIONS.
      config: Specify build config or default to DEFAULT_CONFIG.

    Returns:
      BuilderRun object.
    """
        options = options or DEFAULT_OPTIONS
        config = config or DEFAULT_CONFIG
        site_config = config_lib_unittest.MockSiteConfig()
        site_config[config.name] = config

        return cbuildbot_run.BuilderRun(options, site_config, config,
                                        self._manager)
예제 #5
0
    def setUp(self):
        # Always stub RunCommmand out as we use it in every method.
        self._bot_id = 'amd64-generic-paladin'
        self.buildstore = FakeBuildStore()
        site_config = config_lib_unittest.MockSiteConfig()
        build_config = site_config[self._bot_id]
        self.build_root = '/fake_root'
        # This test compares log output from the stages, so turn on buildbot
        # logging.
        logging.EnableBuildbotMarkers()

        self.db = fake_cidb.FakeCIDBConnection()
        cidb.CIDBConnectionFactory.SetupMockCidb(self.db)

        # Create a class to hold
        class Options(object):
            """Dummy class to hold option values."""

        options = Options()
        options.archive_base = 'gs://dontcare'
        options.buildroot = self.build_root
        options.debug = False
        options.prebuilts = False
        options.clobber = False
        options.nosdk = False
        options.remote_trybot = False
        options.latest_toolchain = False
        options.buildnumber = 1234
        options.android_rev = None
        options.chrome_rev = None
        options.branch = 'dontcare'
        options.chrome_root = False
        options.build_config_name = ''

        self._manager = parallel.Manager()
        # Pylint-1.9 has a false positive on this for some reason.
        self._manager.__enter__()  # pylint: disable=no-value-for-parameter

        self._run = cbuildbot_run.BuilderRun(options, site_config,
                                             build_config, self._manager)

        results_lib.Results.Clear()
예제 #6
0
def _RunBuildStagesWrapper(options, site_config, build_config):
    """Helper function that wraps RunBuildStages()."""
    logging.info('cbuildbot was executed with args %s' %
                 cros_build_lib.CmdToStr(sys.argv))

    chrome_rev = build_config['chrome_rev']
    if options.chrome_rev:
        chrome_rev = options.chrome_rev
    if chrome_rev == constants.CHROME_REV_TOT:
        options.chrome_version = gob_util.GetTipOfTrunkRevision(
            constants.CHROMIUM_GOB_URL)
        options.chrome_rev = constants.CHROME_REV_SPEC

    # If it's likely we'll need to build Chrome, fetch the source.
    if build_config['sync_chrome'] is None:
        options.managed_chrome = (chrome_rev != constants.CHROME_REV_LOCAL and
                                  (not build_config['usepkg_build_packages']
                                   or chrome_rev or build_config['profile']))
    else:
        options.managed_chrome = build_config['sync_chrome']

    if options.managed_chrome:
        # Tell Chrome to fetch the source locally.
        internal = constants.USE_CHROME_INTERNAL in build_config['useflags']
        chrome_src = 'chrome-src-internal' if internal else 'chrome-src'
        target_name = 'target'
        if options.branch:
            # Tie the cache per branch
            target_name = 'target-%s' % options.branch
        options.chrome_root = os.path.join(options.cache_dir, 'distfiles',
                                           target_name, chrome_src)
        # Create directory if in need
        osutils.SafeMakedirsNonRoot(options.chrome_root)

    # We are done munging options values, so freeze options object now to avoid
    # further abuse of it.
    # TODO(mtennant): one by one identify each options value override and see if
    # it can be handled another way.  Try to push this freeze closer and closer
    # to the start of the script (e.g. in or after _PostParseCheck).
    options.Freeze()

    metadata_dump_dict = {
        # A detected default has been set before now if it wasn't explicit.
        'branch': options.branch,
    }
    if options.metadata_dump:
        with open(options.metadata_dump, 'r') as metadata_file:
            metadata_dump_dict = json.loads(metadata_file.read())

    with parallel.Manager() as manager:
        builder_run = cbuildbot_run.BuilderRun(options, site_config,
                                               build_config, manager)
        if metadata_dump_dict:
            builder_run.attrs.metadata.UpdateWithDict(metadata_dump_dict)

        if builder_run.config.builder_class_name is None:
            # TODO: This should get relocated to chromeos_config.
            if _IsDistributedBuilder(options, chrome_rev, build_config):
                builder_cls_name = 'simple_builders.DistributedBuilder'
            else:
                builder_cls_name = 'simple_builders.SimpleBuilder'
            builder_cls = builders.GetBuilderClass(builder_cls_name)
            builder = builder_cls(builder_run)
        else:
            builder = builders.Builder(builder_run)

        if not builder.Run():
            sys.exit(1)
예제 #7
0
  def _Prepare(self, bot_id=None, extra_config=None, cmd_args=None,
               extra_cmd_args=None, build_id=DEFAULT_BUILD_ID,
               waterfall=constants.WATERFALL_INTERNAL,
               waterfall_url=constants.BUILD_INT_DASHBOARD,
               master_build_id=None,
               site_config=None):
    """Prepare a BuilderRun at self._run for this test.

    This method must allow being called more than once.  Subclasses can
    override this method, but those subclass methods should also call this one.

    The idea is that all test preparation that falls out from the choice of
    build config and cbuildbot options should go in _Prepare.

    This will populate the following attributes on self:
      run: A BuilderRun object.
      bot_id: The bot id (name) that was used from the site_config.
      self._boards: Same as self._run.config.boards.  TODO(mtennant): remove.
      self._current_board: First board in list, if there is one.

    Args:
      bot_id: Name of build config to use, defaults to self.BOT_ID.
      extra_config: Dict used to add to the build config for the given
        bot_id.  Example: {'push_image': True}.
      cmd_args: List to override the default cbuildbot command args.
      extra_cmd_args: List to add to default cbuildbot command args.  This
        is a good way to adjust an options value for your test.
        Example: ['branch-name', 'some-branch-name'] will effectively cause
        self._run.options.branch_name to be set to 'some-branch-name'.
      build_id: mock build id
      waterfall: Name of the current waterfall.
                 Possibly from constants.CIDB_KNOWN_WATERFALLS.
      waterfall_url: Url for the current waterfall.
      master_build_id: mock build id of master build.
      site_config: SiteConfig to use (or MockSiteConfig)
    """
    # Use cbuildbot parser to create options object and populate default values.
    parser = cbuildbot._CreateParser()
    if not cmd_args:
      # Fill in default command args.
      cmd_args = [
          '-r', self.build_root, '--buildbot', '--noprebuilts',
          '--buildnumber', str(DEFAULT_BUILD_NUMBER),
          '--branch', self.TARGET_MANIFEST_BRANCH,
      ]
    if extra_cmd_args:
      cmd_args += extra_cmd_args
    (options, args) = parser.parse_args(cmd_args)

    # The bot_id can either be specified as arg to _Prepare method or in the
    # cmd_args (as cbuildbot normally accepts it from command line).
    if args:
      self._bot_id = args[0]
      if bot_id:
        # This means bot_id was specified as _Prepare arg and in cmd_args.
        # Make sure they are the same.
        self.assertEquals(self._bot_id, bot_id)
    else:
      self._bot_id = bot_id or self.BOT_ID
      args = [self._bot_id]
    cbuildbot._FinishParsing(options, args)

    if site_config is None:
      site_config = chromeos_config.GetConfig()

    # Populate build_config corresponding to self._bot_id.
    build_config = copy.deepcopy(site_config[self._bot_id])
    build_config['manifest_repo_url'] = 'fake_url'
    if extra_config:
      build_config.update(extra_config)
    if options.remote_trybot:
      build_config = config_lib.OverrideConfigForTrybot(
          build_config, options)
    options.managed_chrome = build_config['sync_chrome']

    self._boards = build_config['boards']
    self._current_board = self._boards[0] if self._boards else None

    # Some preliminary sanity checks.
    self.assertEquals(options.buildroot, self.build_root)

    # Construct a real BuilderRun using options and build_config.
    self._run = cbuildbot_run.BuilderRun(
        options, site_config, build_config, self._manager)

    if build_id is not None:
      self._run.attrs.metadata.UpdateWithDict({'build_id': build_id})

    if master_build_id is not None:
      self._run.options.master_build_id = master_build_id

    self._run.attrs.metadata.UpdateWithDict({'buildbot-master-name': waterfall})
    self._run.attrs.metadata.UpdateWithDict({'buildbot-url': waterfall_url})

    if self.RELEASE_TAG is not None:
      self._run.attrs.release_tag = self.RELEASE_TAG

    portage_util._OVERLAY_LIST_CMD = '/bin/true'
    def _Prepare(self,
                 bot_id=None,
                 extra_config=None,
                 cmd_args=None,
                 extra_cmd_args=None,
                 build_id=DEFAULT_BUILD_ID,
                 master_build_id=None,
                 buildbucket_id=None,
                 site_config=None):
        """Prepare a BuilderRun at self._run for this test.

    This method must allow being called more than once.  Subclasses can
    override this method, but those subclass methods should also call this one.

    The idea is that all test preparation that falls out from the choice of
    build config and cbuildbot options should go in _Prepare.

    This will populate the following attributes on self:
      run: A BuilderRun object.
      bot_id: The bot id (name) that was used from the site_config.
      self._boards: Same as self._run.config.boards.  TODO(mtennant): remove.
      self._current_board: First board in list, if there is one.

    Args:
      bot_id: Name of build config to use, defaults to self.BOT_ID.
      extra_config: Dict used to add to the build config for the given
        bot_id.  Example: {'push_image': True}.
      cmd_args: List to override the default cbuildbot command args, including
        the bot_id.
      extra_cmd_args: List to add to default cbuildbot command args.  This
        is a good way to adjust an options value for your test.
        Example: ['branch-name', 'some-branch-name'] will effectively cause
        self._run.options.branch_name to be set to 'some-branch-name'.
      build_id: mock build id
      buildbucket_id: mock buildbucket_id
      master_build_id: mock build id of master build.
      site_config: SiteConfig to use (or MockSiteConfig)
    """
        assert not bot_id or not cmd_args

        # Use cbuildbot parser to create options object and populate default values.
        if not cmd_args:
            # Fill in default command args.
            cmd_args = [
                '-r', self.build_root, '--buildbot', '--noprebuilts',
                '--buildnumber',
                str(DEFAULT_BUILD_NUMBER), '--branch',
                self.TARGET_MANIFEST_BRANCH, bot_id or self.BOT_ID
            ]
        if extra_cmd_args:
            cmd_args += extra_cmd_args

        parser = cbuildbot._CreateParser()
        options = cbuildbot.ParseCommandLine(parser, cmd_args)
        self._bot_id = options.build_config_name

        if site_config is None:
            site_config = config_lib.GetConfig()

        # Populate build_config corresponding to self._bot_id.
        build_config = copy.deepcopy(site_config[self._bot_id])
        build_config['manifest_repo_url'] = 'fake_url'
        if extra_config:
            build_config.update(extra_config)
        options.managed_chrome = build_config['sync_chrome']

        self._boards = build_config['boards']
        self._current_board = self._boards[0] if self._boards else None
        self._model = self._current_board

        # Some preliminary sanity checks.
        self.assertEqual(options.buildroot, self.build_root)

        # Construct a real BuilderRun using options and build_config.
        self._run = cbuildbot_run.BuilderRun(options, site_config,
                                             build_config, self._manager)

        if build_id is not None:
            self._run.attrs.metadata.UpdateWithDict({'build_id': build_id})

        if buildbucket_id is not None:
            self._run.options.buildbucket_id = buildbucket_id

        if master_build_id is not None:
            self._run.options.master_build_id = master_build_id

        if self.RELEASE_TAG is not None:
            self._run.attrs.release_tag = self.RELEASE_TAG

        portage_util._OVERLAY_LIST_CMD = '/bin/true'