コード例 #1
0
    def __init__(self,
                 build_config,
                 luci_builder=None,
                 display_label=None,
                 branch='master',
                 extra_args=(),
                 extra_properties=None,
                 user_email=None,
                 email_template=None,
                 master_cidb_id=None,
                 master_buildbucket_id=None,
                 bucket=constants.INTERNAL_SWARMING_BUILDBUCKET_BUCKET,
                 requested_bot=None):
        """Construct the object.

    Args:
      build_config: A build config name to schedule.
      luci_builder: Name of builder to execute the build, or None.
                    For waterfall builds, this is the name of the build column.
                    For swarming builds, this is the LUCI builder name.
      display_label: String describing how build group on waterfall, or None.
      branch: Name of branch to build for.
      extra_args: Command line arguments to pass to cbuildbot in job.
      extra_properties: Additional input properties to add to the request.
      user_email: Email address of person requesting job, or None.
      email_template: Name of the luci-notify template to use. None for
                      default. Ignored if user_email is not set.
      master_cidb_id: CIDB id of scheduling builder, or None.
      master_buildbucket_id: buildbucket id of scheduling builder, or None.
      bucket: Which bucket do we request the build in?
      requested_bot: Name of bot to prefer (for performance), or None.
    """
        self.bucket = bucket
        self.extra_properties = extra_properties or {}

        site_config = config_lib.GetConfig()
        if build_config in site_config:
            # Extract from build_config, if possible.
            self.luci_builder = site_config[build_config].luci_builder
            self.display_label = site_config[build_config].display_label
            self.workspace_branch = site_config[build_config].workspace_branch
            self.goma_client_type = site_config[build_config].goma_client_type
        else:
            # Use generic defaults if needed (lowest priority)
            self.luci_builder = config_lib.LUCI_BUILDER_TRY
            self.display_label = config_lib.DISPLAY_LABEL_TRYJOB
            self.workspace_branch = None
            self.goma_client_type = None

        # But allow an explicit overrides.
        if luci_builder:
            self.luci_builder = luci_builder

        if display_label:
            self.display_label = display_label

        self.build_config = build_config
        self.branch = branch
        self.extra_args = extra_args
        self.user_email = user_email
        self.email_template = email_template or 'default'
        self.master_cidb_id = master_cidb_id
        self.master_buildbucket_id = master_buildbucket_id
        self.requested_bot = requested_bot
コード例 #2
0
# -*- coding: utf-8 -*-
# Copyright 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unittests for trybot_patch_pool."""

from __future__ import print_function

from chromite.lib import config_lib
from chromite.lib import constants
from chromite.cbuildbot import trybot_patch_pool
from chromite.lib import patch as cros_patch
from chromite.lib import patch_unittest

site_config = config_lib.GetConfig()


class FilterTests(patch_unittest.GitRepoPatchTestCase):
    """Tests for all the various filters."""

    patch_kls = cros_patch.LocalPatch

    def testChromiteFilter(self):
        """Make sure the chromite filter works"""
        _, _, patch = self._CommonGitSetup()
        patch.project = constants.CHROMITE_PROJECT
        self.assertTrue(trybot_patch_pool.ChromiteFilter(patch))
        patch.project = 'foooo'
        self.assertFalse(trybot_patch_pool.ChromiteFilter(patch))

    def testManifestFilters(self):
コード例 #3
0
ファイル: cbuildbot.py プロジェクト: msisov/chromium68
def main(argv):
    # We get false positives with the options object.
    # pylint: disable=attribute-defined-outside-init

    # Turn on strict sudo checks.
    cros_build_lib.STRICT_SUDO = True

    # Set umask to 022 so files created by buildbot are readable.
    os.umask(0o22)

    parser = _CreateParser()
    options = ParseCommandLine(parser, argv)

    # Fetch our site_config now, because we need it to do anything else.
    site_config = config_lib.GetConfig()

    _PostParseCheck(parser, options, site_config)

    cros_build_lib.AssertOutsideChroot()

    if options.enable_buildbot_tags:
        logging.EnableBuildbotMarkers()

    if (options.buildbot and not options.debug
            and not options.build_config_name == constants.BRANCH_UTIL_CONFIG
            and not cros_build_lib.HostIsCIBuilder()):
        # --buildbot can only be used on a real builder, unless it's debug, or
        # 'branch-util'.
        cros_build_lib.Die('This host is not a supported build machine.')

    # Only one config arg is allowed in this mode, which was confirmed earlier.
    build_config = site_config[options.build_config_name]

    # TODO: Re-enable this block when reference_repo support handles this
    #       properly. (see chromium:330775)
    # if options.reference_repo is None:
    #   repo_path = os.path.join(options.sourceroot, '.repo')
    #   # If we're being run from a repo checkout, reuse the repo's git pool to
    #   # cut down on sync time.
    #   if os.path.exists(repo_path):
    #     options.reference_repo = options.sourceroot

    if options.reference_repo:
        if not os.path.exists(options.reference_repo):
            parser.error('Reference path %s does not exist' %
                         (options.reference_repo, ))
        elif not os.path.exists(os.path.join(options.reference_repo, '.repo')):
            parser.error('Reference path %s does not look to be the base of a '
                         'repo checkout; no .repo exists in the root.' %
                         (options.reference_repo, ))

    if (options.buildbot or options.remote_trybot) and not options.resume:
        if not options.cgroups:
            parser.error(
                'Options --buildbot/--remote-trybot and --nocgroups cannot '
                'be used together.  Cgroup support is required for '
                'buildbot/remote-trybot mode.')
        if not cgroups.Cgroup.IsSupported():
            parser.error(
                'Option --buildbot/--remote-trybot was given, but this '
                'system does not support cgroups.  Failing.')

        missing = osutils.FindMissingBinaries(_BUILDBOT_REQUIRED_BINARIES)
        if missing:
            parser.error(
                'Option --buildbot/--remote-trybot requires the following '
                "binaries which couldn't be found in $PATH: %s" %
                (', '.join(missing)))

    if options.reference_repo:
        options.reference_repo = os.path.abspath(options.reference_repo)

    # Sanity check of buildroot- specifically that it's not pointing into the
    # midst of an existing repo since git-repo doesn't support nesting.
    if (not repository.IsARepoRoot(options.buildroot)
            and git.FindRepoDir(options.buildroot)):
        cros_build_lib.Die(
            'Configured buildroot %s is a subdir of an existing repo checkout.'
            % options.buildroot)

    if not options.log_dir:
        options.log_dir = os.path.join(options.buildroot, _DEFAULT_LOG_DIR)

    log_file = None
    if options.tee:
        log_file = os.path.join(options.log_dir, _BUILDBOT_LOG_FILE)
        osutils.SafeMakedirs(options.log_dir)
        _BackupPreviousLog(log_file)

    with cros_build_lib.ContextManagerStack() as stack:
        options.preserve_paths = set()
        if log_file is not None:
            # We don't want the critical section to try to clean up the tee process,
            # so we run Tee (forked off) outside of it. This prevents a deadlock
            # because the Tee process only exits when its pipe is closed, and the
            # critical section accidentally holds on to that file handle.
            stack.Add(tee.Tee, log_file)
            options.preserve_paths.add(_DEFAULT_LOG_DIR)

        critical_section = stack.Add(cleanup.EnforcedCleanupSection)
        stack.Add(sudo.SudoKeepAlive)

        if not options.resume:
            # If we're in resume mode, use our parents tempdir rather than
            # nesting another layer.
            stack.Add(osutils.TempDir, prefix='cbuildbot-tmp', set_global=True)
            logging.debug('Cbuildbot tempdir is %r.', os.environ.get('TMP'))

        if options.cgroups:
            stack.Add(cgroups.SimpleContainChildren, 'cbuildbot')

        # Mark everything between EnforcedCleanupSection and here as having to
        # be rolled back via the contextmanager cleanup handlers.  This
        # ensures that sudo bits cannot outlive cbuildbot, that anything
        # cgroups would kill gets killed, etc.
        stack.Add(critical_section.ForkWatchdog)

        if options.mock_tree_status is not None:
            stack.Add(_ObjectMethodPatcher,
                      tree_status,
                      '_GetStatus',
                      return_value=options.mock_tree_status)

        if options.mock_slave_status is not None:
            with open(options.mock_slave_status, 'r') as f:
                mock_statuses = pickle.load(f)
                for key, value in mock_statuses.iteritems():
                    mock_statuses[key] = builder_status_lib.BuilderStatus(
                        **value)
            stack.Add(_ObjectMethodPatcher,
                      completion_stages.MasterSlaveSyncCompletionStage,
                      '_FetchSlaveStatuses',
                      return_value=mock_statuses)

        stack.Add(_SetupConnections, options, build_config)
        retry_stats.SetupStats()

        timeout_display_message = None
        # For master-slave builds: Update slave's timeout using master's published
        # deadline.
        if options.buildbot and options.master_build_id is not None:
            slave_timeout = None
            if cidb.CIDBConnectionFactory.IsCIDBSetup():
                cidb_handle = cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder(
                )
                if cidb_handle:
                    slave_timeout = cidb_handle.GetTimeToDeadline(
                        options.master_build_id)

            if slave_timeout is not None:
                # We artificially set a minimum slave_timeout because '0' is handled
                # specially, and because we don't want to timeout while trying to set
                # things up.
                slave_timeout = max(slave_timeout, 20)
                if options.timeout == 0 or slave_timeout < options.timeout:
                    logging.info(
                        'Updating slave build timeout to %d seconds enforced '
                        'by the master', slave_timeout)
                    options.timeout = slave_timeout
                    timeout_display_message = (
                        'This build has reached the timeout deadline set by the master. '
                        'Either this stage or a previous one took too long (see stage '
                        'timing historical summary in ReportStage) or the build failed '
                        'to start on time.')
            else:
                logging.warning(
                    'Could not get master deadline for master-slave build. '
                    'Can not set slave timeout.')

        if options.timeout > 0:
            stack.Add(timeout_util.FatalTimeout, options.timeout,
                      timeout_display_message)
        try:
            _RunBuildStagesWrapper(options, site_config, build_config)
        except failures_lib.ExitEarlyException as ex:
            # This build finished successfully. Do not re-raise ExitEarlyException.
            logging.info('One stage exited early: %s', ex)
コード例 #4
0
 def testBotIdRemoteTrybotTrue(self):
     expected_result = (
         '%s/%s' % (config_lib.GetConfig().params.ARCHIVE_URL, self.BOT_ID))
     result = self._GetBaseUploadURI(bot_id=self.BOT_ID, remote_trybot=True)
     self.assertEqual(expected_result, result)
コード例 #5
0
 def testSanityAgainstProd(self):
   """Test we can generate a luci scheduler config with live data."""
   # If it runs without crashing, we pass.
   gen_luci_scheduler.genLuciSchedulerConfig(
       config_lib.GetConfig(), chromeos_config.BranchScheduleConfig())
コード例 #6
0
class PrebuiltCompatibilityTest(cros_test_lib.TestCase):
    """Ensure that prebuilts are present for all builders and are compatible."""

    # Whether to cache setup from run to run. If set, requires that you install
    # joblib (sudo easy_install joblib). This is useful for iterating on the
    # unit tests, but note that if you 'repo sync', you'll need to clear out
    # /tmp/joblib and blow away /build in order to update the caches. Note that
    # this is never normally set to True -- if you want to use this feature,
    # you'll need to hand-edit this file.
    # TODO(davidjames): Add a --caching option.
    CACHING = False

    # A dict mapping BoardKeys to their associated compat ids.
    COMPAT_IDS = None

    # Boards that don't have Chromium PFQs.
    # TODO(davidjames): Empty this list.
    BOARDS_WITHOUT_CHROMIUM_PFQS = ['rush_ryu', 'smaug', 'veyron_rialto']

    site_config = config_lib.GetConfig()

    @classmethod
    def setUpClass(cls):
        assert cros_build_lib.IsInsideChroot()
        logging.info('Generating board configs. This takes about 30m...')
        board_keys = binhost.GetAllImportantBoardKeys(cls.site_config)
        boards = set(key.board for key in board_keys)
        for board in sorted(boards):
            binhost.GenConfigsForBoard(board,
                                       regen=not cls.CACHING,
                                       error_code_ok=False)
        fetcher = binhost.CompatIdFetcher(caching=cls.CACHING)
        cls.COMPAT_IDS = fetcher.FetchCompatIds(list(board_keys))

    def setUp(self):
        self.complaints = []
        self.fatal_complaints = []

    def tearDown(self):
        if self.complaints:
            warnings.warn('\n' + '\n'.join(self.complaints))
        if self.fatal_complaints:
            self.assertFalse(self.fatal_complaints,
                             '\n'.join(self.fatal_complaints))

    def Complain(self, msg, fatal):
        """Complain about an error when the test exits.

    Args:
      msg: The message to print.
      fatal: Whether the message should be fatal. If not, the message will be
        considered a warning.
    """
        if fatal:
            self.fatal_complaints.append(msg)
        else:
            self.complaints.append(msg)

    def GetCompatIdDiff(self, expected, actual):
        """Return a string describing the differences between expected and actual.

    Args:
      expected: Expected value for CompatId.
      actual: Actual value for CompatId.
    """
        if expected.arch != actual.arch:
            return 'arch differs: %s != %s' % (expected.arch, actual.arch)
        elif expected.useflags != actual.useflags:
            msg = self.GetSequenceDiff(expected.useflags, actual.useflags)
            return msg.replace('Sequences', 'useflags')
        elif expected.cflags != actual.cflags:
            msg = self.GetSequenceDiff(expected.cflags, actual.cflags)
            return msg.replace('Sequences', 'cflags')
        else:
            assert expected == actual
            return 'no differences'

    def AssertChromePrebuilts(self, pfq_configs, config, skip_useflags=False):
        """Verify that the specified config has Chrome prebuilts.

    Args:
      pfq_configs: A PrebuiltMapping object.
      config: The config to check.
      skip_useflags: Don't use extra useflags from the config.
    """
        # Skip over useflags from the useflag if needed.
        msg_prefix = ''
        if skip_useflags and config.useflags:
            msg_prefix = 'When we take out config-requested useflags (%s), ' % (
                config.useflags)
            config = config.deepcopy()
            config.useflags = []

        compat_id = self.GetCompatId(config)
        pfqs = pfq_configs.by_compat_id.get(compat_id, set())
        if not pfqs:
            arch_useflags = (compat_id.arch, compat_id.useflags)
            for key in pfq_configs.by_arch_useflags[arch_useflags]:
                # If there wasn't an exact match for this CompatId, but there
                # was an (arch, useflags) match, then we'll be using mismatched
                # Chrome prebuilts. Complain.
                # TODO(davidjames): This should be a fatal error for important
                # builders, but we need to clean up existing cases first.
                pfq_compat_id = self.COMPAT_IDS.get(key)
                if pfq_compat_id:
                    err = self.GetCompatIdDiff(compat_id, pfq_compat_id)
                    msg = '%s%s uses mismatched Chrome prebuilts from %s -- %s'
                    self.Complain(msg %
                                  (msg_prefix, config.name, key.board, err),
                                  fatal=False)
                    pfqs.add(key)

        if not pfqs:
            pre_cq = (config.build_type == config_lib.CONFIG_TYPE_PRECQ)
            msg = '%s%s cannot find Chrome prebuilts -- %s'
            self.Complain(msg % (msg_prefix, config.name, compat_id),
                          fatal=pre_cq or config.important)

    def GetCompatId(self, config, board=None):
        """Get the CompatId for a config.

    Args:
      config: A config_lib.BuildConfig object.
      board: Board to use. Defaults to the first board in the config.
          Optional if len(config.boards) == 1.
    """
        if board is None:
            assert len(config.boards) == 1
            board = config.boards[0]
        else:
            assert board in config.boards

        board_key = binhost.GetBoardKey(config, board)
        compat_id = self.COMPAT_IDS.get(board_key)
        if compat_id is None:
            compat_id = binhost.CalculateCompatId(board, config.useflags)
            self.COMPAT_IDS[board_key] = compat_id
        return compat_id

    def testChromePrebuiltsPresent(self, filename=None):
        """Verify Chrome prebuilts exist for all configs that build Chrome.

    Args:
      filename: Filename to load our PFQ mappings from. By default, generate
        the PFQ mappings based on the current config.
    """
        if filename is not None:
            pfq_configs = binhost.PrebuiltMapping.Load(filename)
        else:
            keys = binhost.GetChromePrebuiltConfigs(self.site_config).keys()
            pfq_configs = binhost.PrebuiltMapping.Get(keys, self.COMPAT_IDS)

        for compat_id, pfqs in pfq_configs.by_compat_id.items():
            if len(pfqs) > 1:
                msg = 'The following Chrome PFQs produce identical prebuilts: %s -- %s'
                self.Complain(msg % (', '.join(str(x)
                                               for x in pfqs), compat_id),
                              fatal=False)

        for _name, config in sorted(self.site_config.items()):
            # Skip over configs that don't have Chrome or have >1 board.
            if config.sync_chrome is False or len(config.boards) != 1:
                continue

            # Look for boards with missing prebuilts.
            builds_chrome = config.usepkg_build_packages and not config.chrome_rev

            production_config = (
                (config.build_type == config_lib.CONFIG_TYPE_PRECQ)
                or (config.active_waterfall
                    and config.active_waterfall != constants.WATERFALL_TRYBOT))

            if builds_chrome and production_config:
                self.AssertChromePrebuilts(pfq_configs, config)

                # Check that we have a builder for the version w/o custom useflags as
                # well.
                if (config.useflags and config.boards[0]
                        not in self.BOARDS_WITHOUT_CHROMIUM_PFQS):
                    self.AssertChromePrebuilts(pfq_configs,
                                               config,
                                               skip_useflags=True)

    def testCurrentChromePrebuiltsEnough(self):
        """Verify Chrome prebuilts exist for all configs that build Chrome.

    This loads the list of Chrome prebuilts that were generated during the last
    Chrome PFQ run from disk and verifies that it is sufficient.
    """
        filename = binhost.PrebuiltMapping.GetFilename(constants.SOURCE_ROOT,
                                                       'chrome')
        if os.path.exists(filename):
            self.testChromePrebuiltsPresent(filename)

    def testReleaseGroupSharing(self):
        """Verify that the boards built in release groups have compatible settings.

    This means that all of the subconfigs in the release group have matching
    use flags, cflags, and architecture.
    """
        for config in self.site_config.values():
            # Only test release groups.
            if not config.name.endswith('-release-group'):
                continue

            # Get a list of the compatibility IDs.
            compat_ids_for_config = collections.defaultdict(set)
            for subconfig in config.child_configs:
                if subconfig.sync_chrome is not False:
                    for board in subconfig.boards:
                        compat_id = self.GetCompatId(subconfig, board)
                        compat_ids_for_config[compat_id].add(board)

            if len(compat_ids_for_config) > 1:
                arch_useflags = set(
                    tuple(x[:-1]) for x in compat_ids_for_config)
                if len(arch_useflags) > 1:
                    # If two configs in the same group have mismatched Chrome binaries
                    # (e.g. different use flags), Chrome may be built twice in parallel
                    # and this may result in flaky, slow, and possibly incorrect builds.
                    msg = '%s: %s and %s have mismatched Chrome binaries -- %s'
                    fatal = True
                else:
                    # TODO(davidjames): This should be marked fatal once the
                    # ivybridge-freon-release-group is cleaned up.
                    msg = '%s: %s and %s have mismatched cflags -- %s'
                    fatal = False
                ids, board_sets = zip(*compat_ids_for_config.iteritems())
                boards = [next(iter(x)) for x in board_sets]
                err = self.GetCompatIdDiff(ids[0], ids[1])
                msg %= (config.name, boards[0], boards[1], err)
                self.Complain(msg, fatal=fatal)

    def testDumping(self):
        """Verify Chrome prebuilts exist for all configs that build Chrome.

    This loads the list of Chrome prebuilts that were generated during the last
    Chrome PFQ run from disk and verifies that it is sufficient.
    """
        with osutils.TempDir() as tempdir:
            keys = binhost.GetChromePrebuiltConfigs(self.site_config).keys()
            pfq_configs = binhost.PrebuiltMapping.Get(keys, self.COMPAT_IDS)
            filename = os.path.join(tempdir, 'foo.json')
            pfq_configs.Dump(filename)
            self.assertEqual(pfq_configs,
                             binhost.PrebuiltMapping.Load(filename))
コード例 #7
0
    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'
コード例 #8
0
  def testGenLuciSchedulerConfig(self):
    """Test a full LUCI Scheduler config file."""
    site_config = config_lib.SiteConfig()

    site_config.Add(
        'not_scheduled',
        luci_builder='ReleaseBuilder',
        display_label='MockLabel',
    )

    site_config.Add(
        'build_prod',
        luci_builder='ReleaseBuilder',
        display_label='MockLabel',
        schedule='run once in a while',
    )

    site_config.Add(
        'build_tester',
        luci_builder='TestBuilder',
        display_label='TestLabel',
        schedule='run daily',
    )

    site_config.Add(
        'build_triggered_a',
        luci_builder='ReleaseBuilder',
        display_label='MockLabel',
        schedule='triggered',
        triggered_gitiles=[[
            'gitiles_url_a',
            ['ref_a', 'ref_b'],
        ], [
            'gitiles_url_b',
            ['ref_c'],
        ]],
    )

    site_config.Add(
        'build_triggered_b',
        luci_builder='ProdBuilder',
        display_label='MockLabel',
        schedule='triggered',
        triggered_gitiles=[[
            'gitiles_url_b',
            ['ref_c'],
        ]],
    )

    default_config = config_lib.GetConfig().GetDefault()

    branch_configs = [
        default_config.derive(
            name='branch_tester',
            luci_builder='TestBuilder',
            display_label='TestLabel',
            schedule='run daily',
            schedule_branch='test-branch',
        ),
        default_config.derive(
            name='branch_tester_triggered',
            luci_builder='TestBuilder',
            display_label='TestLabel',
            schedule='run daily',
            schedule_branch='test-branch',
            triggered_gitiles=[[
                'gitiles_url_a',
                ['ref_a', 'ref_b'],
            ]],
        ),
    ]

    expected = """# Defines buckets on luci-scheduler.appspot.com.
#
# For schema of this file and documentation see ProjectConfig message in
# https://github.com/luci/luci-go/blob/master/scheduler/appengine/messages/config.proto

# Generated with chromite/scripts/gen_luci_scheduler

# Autodeployed with:
# http://cros-goldeneye/chromeos/legoland/builderHistory?buildConfig=luci-scheduler-updater

acl_sets {
  name: "default"
  acls {
    role: READER
    granted_to: "group:googlers"
  }
  acls {
    role: OWNER
    granted_to: "group:project-chromeos-admins"
  }
  acls {
    role: TRIGGERER
    granted_to: "group:mdb/chromeos-build-access"
  }
  acls {
    role: TRIGGERER
    granted_to: "group:project-chromeos-buildbucket-schedulers"
  }
}

trigger {
  id: "trigger_0"
  acl_sets: "default"
  schedule: "with 5m interval"
  gitiles: {
    repo: "gitiles_url_a"
    refs: "ref_a"
    refs: "ref_b"
  }
  triggers: "build_triggered_a"
  triggers: "test-branch-branch_tester_triggered"
}

trigger {
  id: "trigger_1"
  acl_sets: "default"
  schedule: "with 5m interval"
  gitiles: {
    repo: "gitiles_url_b"
    refs: "ref_c"
  }
  triggers: "build_triggered_a"
  triggers: "build_triggered_b"
}

job {
  id: "build_prod"
  acl_sets: "default"
  schedule: "run once in a while"
  buildbucket: {
    server: "cr-buildbucket.appspot.com"
    bucket: "luci.chromeos.general"
    builder: "ReleaseBuilder"
    tags: "cbb_branch:master"
    tags: "cbb_config:build_prod"
    tags: "cbb_display_label:MockLabel"
    properties: "cbb_branch:master"
    properties: "cbb_config:build_prod"
    properties: "cbb_display_label:MockLabel"
    properties: "cbb_extra_args:[\\"--buildbot\\"]"
  }
}

job {
  id: "build_tester"
  acl_sets: "default"
  schedule: "run daily"
  buildbucket: {
    server: "cr-buildbucket.appspot.com"
    bucket: "luci.chromeos.general"
    builder: "TestBuilder"
    tags: "cbb_branch:master"
    tags: "cbb_config:build_tester"
    tags: "cbb_display_label:TestLabel"
    properties: "cbb_branch:master"
    properties: "cbb_config:build_tester"
    properties: "cbb_display_label:TestLabel"
    properties: "cbb_extra_args:[\\"--buildbot\\"]"
  }
}

job {
  id: "build_triggered_a"
  acl_sets: "default"
  schedule: "triggered"
  buildbucket: {
    server: "cr-buildbucket.appspot.com"
    bucket: "luci.chromeos.general"
    builder: "ReleaseBuilder"
    tags: "cbb_branch:master"
    tags: "cbb_config:build_triggered_a"
    tags: "cbb_display_label:MockLabel"
    properties: "cbb_branch:master"
    properties: "cbb_config:build_triggered_a"
    properties: "cbb_display_label:MockLabel"
    properties: "cbb_extra_args:[\\"--buildbot\\"]"
  }
}

job {
  id: "build_triggered_b"
  acl_sets: "default"
  schedule: "triggered"
  buildbucket: {
    server: "cr-buildbucket.appspot.com"
    bucket: "luci.chromeos.general"
    builder: "ProdBuilder"
    tags: "cbb_branch:master"
    tags: "cbb_config:build_triggered_b"
    tags: "cbb_display_label:MockLabel"
    properties: "cbb_branch:master"
    properties: "cbb_config:build_triggered_b"
    properties: "cbb_display_label:MockLabel"
    properties: "cbb_extra_args:[\\"--buildbot\\"]"
  }
}

job {
  id: "test-branch-branch_tester"
  acl_sets: "default"
  schedule: "run daily"
  buildbucket: {
    server: "cr-buildbucket.appspot.com"
    bucket: "luci.chromeos.general"
    builder: "TestBuilder"
    tags: "cbb_branch:test-branch"
    tags: "cbb_config:branch_tester"
    tags: "cbb_display_label:TestLabel"
    properties: "cbb_branch:test-branch"
    properties: "cbb_config:branch_tester"
    properties: "cbb_display_label:TestLabel"
    properties: "cbb_extra_args:[\\"--buildbot\\"]"
  }
}

job {
  id: "test-branch-branch_tester_triggered"
  acl_sets: "default"
  schedule: "run daily"
  buildbucket: {
    server: "cr-buildbucket.appspot.com"
    bucket: "luci.chromeos.general"
    builder: "TestBuilder"
    tags: "cbb_branch:test-branch"
    tags: "cbb_config:branch_tester_triggered"
    tags: "cbb_display_label:TestLabel"
    properties: "cbb_branch:test-branch"
    properties: "cbb_config:branch_tester_triggered"
    properties: "cbb_display_label:TestLabel"
    properties: "cbb_extra_args:[\\"--buildbot\\"]"
  }
}
"""
    result = gen_luci_scheduler.genLuciSchedulerConfig(
        site_config, branch_configs)

    self.assertEqual(result, expected)
コード例 #9
0
 def __init__(self, checkout_dir, dryrun):
     self._checkout_dir = checkout_dir
     self._dryrun = dryrun
     self._lkgm = None
     self._old_lkgm = None
     self.site_config = config_lib.GetConfig()
コード例 #10
0
 def setUp(self):
     self.real_config = config_lib.GetConfig()['test-ap-group']
     self.PatchObject(cbuildbot_run._BuilderRunBase,
                      'GetVersion',
                      return_value=DEFAULT_VERSION)
コード例 #11
0
def _main(argv):
    """main method of script.

  Args:
    argv: All command line arguments to pass as list of strings.

  Returns:
    Return code of cbuildbot as an integer.
  """
    options = PreParseArguments(argv)

    branchname = options.branch or 'master'
    root = options.buildroot
    buildroot = os.path.join(root, 'repository')
    depot_tools_path = os.path.join(buildroot, constants.DEPOT_TOOLS_SUBPATH)

    metrics_fields = {
        'branch_name': branchname,
        'build_config': options.build_config_name,
        'tryjob': options.remote_trybot,
    }

    # Does the entire build pass or fail.
    with metrics.Presence(METRIC_ACTIVE, metrics_fields), \
         metrics.SuccessCounter(METRIC_COMPLETED, metrics_fields) as s_fields:

        # Preliminary set, mostly command line parsing.
        with metrics.SuccessCounter(METRIC_INVOKED, metrics_fields):
            if options.enable_buildbot_tags:
                logging.EnableBuildbotMarkers()
            ConfigureGlobalEnvironment()

        # Prepare the buildroot with source for the build.
        with metrics.SuccessCounter(METRIC_PREP, metrics_fields):
            site_config = config_lib.GetConfig()
            manifest_url = site_config.params['MANIFEST_INT_URL']
            repo = repository.RepoRepository(
                manifest_url,
                buildroot,
                branch=branchname,
                git_cache_dir=options.git_cache_dir)
            previous_build_state = GetLastBuildState(root)

            # Clean up the buildroot to a safe state.
            with metrics.SecondsTimer(METRIC_CLEAN, fields=metrics_fields):
                build_state = GetCurrentBuildState(options, branchname)
                CleanBuildRoot(root, repo, metrics_fields, build_state)

            # Get a checkout close enough to the branch that cbuildbot can handle it.
            if options.sync:
                with metrics.SecondsTimer(METRIC_INITIAL,
                                          fields=metrics_fields):
                    InitialCheckout(repo)

            # Get a checkout close enough to the branch that cbuildbot can handle it.
            with metrics.SecondsTimer(METRIC_DEPOT_TOOLS,
                                      fields=metrics_fields):
                DepotToolsEnsureBootstrap(depot_tools_path)

        # Run cbuildbot inside the full ChromeOS checkout, on the specified branch.
        with metrics.SecondsTimer(METRIC_CBUILDBOT, fields=metrics_fields):
            if previous_build_state.is_valid():
                argv.append('--previous-build-state')
                argv.append(base64.b64encode(previous_build_state.to_json()))

            result = Cbuildbot(buildroot, depot_tools_path, argv)
            s_fields['success'] = (result == 0)

            build_state.status = (constants.BUILDER_STATUS_PASSED if result
                                  == 0 else constants.BUILDER_STATUS_FAILED)
            SetLastBuildState(root, build_state)

            CleanupChroot(buildroot)
            return result
コード例 #12
0
 def FindLabel(self, args):
   site_config = config_lib.GetConfig()
   options = self.SetupCommandMock(args)
   config_name = options.build_configs[-1]
   return cros_tryjob.DisplayLabel(site_config, options, config_name)
コード例 #13
0
 def setUp(self):
   self.site_config = config_lib.GetConfig()