def _initConfig( self, bot_id, master=False, extra_argv=None, override_hw_test_config=None, models=None): """Return normal options/build_config for |bot_id|""" site_config = config_lib.GetConfig() build_config = copy.deepcopy(site_config[bot_id]) build_config['master'] = master build_config['important'] = False if models: build_config['models'] = models # 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 testIsDistributedBuilder(self): """Tests for _IsDistributedBuilder() under various configurations.""" parser = cbuildbot._CreateParser() argv = ['--buildroot', '/foo', 'amd64-generic-paladin'] options = cbuildbot.ParseCommandLine(parser, argv) options.buildbot = False build_config = dict(manifest_version=False) chrome_rev = None def _TestConfig(expected): self.assertEqual( expected, cbuildbot._IsDistributedBuilder(options=options, chrome_rev=chrome_rev, build_config=build_config)) # Default options. _TestConfig(False) build_config['manifest_version'] = True # Not running in buildbot mode even though manifest_version=True. _TestConfig(False) options.buildbot = True _TestConfig(True) for chrome_rev in (constants.CHROME_REV_TOT, constants.CHROME_REV_LOCAL, constants.CHROME_REV_SPEC): _TestConfig(False)
def testBuildbotDebugWithPatches(self): """Test we can test patches with --buildbot --debug.""" args = [ '-r', self._BUILD_ROOT, '--buildbot', '--debug', '-g', '1234', self._GENERIC_PREFLIGHT ] cbuildbot.ParseCommandLine(self.parser, args)
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 testBuildBotWithDebugOption(self): """Test that --debug option overrides --buildbot option.""" args = ['-r', self._BUILD_ROOT, '--buildbot', '--debug', self._GENERIC_PREFLIGHT] options = cbuildbot.ParseCommandLine(self.parser, args) self.assertTrue(options.debug) self.assertTrue(options.buildbot)
def testBuildBotWithProfileOption(self): """Test that --profile option gets parsed.""" args = [ '-r', self._BUILD_ROOT, '--buildbot', '--profile', 'carp', self._GENERIC_PREFLIGHT ] options = cbuildbot.ParseCommandLine(self.parser, args) self.assertEqual(options.profile, 'carp')
def testBuildPackages(self): parser = cbuildbot.CreateParser() argv = ['--buildroot', '/foo', '--buildbot', '--cbb_snapshot_revision', 'hash1234', '--cbb_build_packages', 'pkgA pkgB', 'caroline-postsubmit'] options = cbuildbot.ParseCommandLine(parser, argv) expected = ['pkgA', 'pkgB'] self.assertEqual(expected, options.cbb_build_packages) self.assertEqual('hash1234', options.cbb_snapshot_revision)
def testBuildBotWithGoodChromeRootOption(self): """chrome_root can be set without chrome_rev.""" args = [ '--buildbot', '--buildroot=/tmp', '--chrome_root=.', self._GENERIC_PREFLIGHT, ] options = cbuildbot.ParseCommandLine(self.parser, args) self.assertEqual(options.chrome_rev, constants.CHROME_REV_LOCAL) self.assertNotEqual(options.chrome_root, None)
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)
def PreParseArguments(argv): """Extract the branch name from cbuildbot command line arguments. Args: argv: The command line arguments to parse. Returns: Branch as a string ('master' if nothing is specified). """ parser = cbuildbot.CreateParser() options = cbuildbot.ParseCommandLine(parser, argv) options.Freeze() # This option isn't required for cbuildbot, but is for us. if not options.buildroot: cros_build_lib.Die('--buildroot is a required option.') return options
def Cbuildbot(buildroot, depot_tools_path, argv): """Start cbuildbot in specified directory with all arguments. Args: buildroot: Directory to be passed to cbuildbot with --buildroot. depot_tools_path: Directory for depot_tools to be used by cbuildbot. argv: Command line options passed to cbuildbot_launch. Returns: Return code of cbuildbot as an integer. """ logging.info('Bootstrap cbuildbot in: %s', buildroot) # Fixup buildroot parameter. argv = argv[:] for i, arg in enumerate(argv): if arg in ('-r', '--buildroot'): argv[i + 1] = buildroot # This filters out command line arguments not supported by older versions # of cbuildbot. parser = cbuildbot.CreateParser() options = cbuildbot.ParseCommandLine(parser, argv) cbuildbot_path = os.path.join(buildroot, 'chromite', 'bin', 'cbuildbot') cmd = sync_stages.BootstrapStage.FilterArgsForTargetCbuildbot( buildroot, cbuildbot_path, options) # We want cbuildbot to use branched depot_tools scripts from our manifest, # so that depot_tools is branched to match cbuildbot. logging.info('Adding depot_tools into PATH: %s', depot_tools_path) extra_env = {'PATH': PrependPath(depot_tools_path)} # TODO(crbug.com/845304): Remove once underlying boto issues are resolved. fix_boto = ShouldFixBotoCerts(options) with boto_compat.FixBotoCerts(activate=fix_boto): result = cros_build_lib.run(cmd, extra_env=extra_env, error_code_ok=True, cwd=buildroot) return result.returncode
def testBuildBotWithGoodChromeRevAndRootOption(self): """chrome_rev can get reset around chrome_root.""" args = [ '--buildbot', '--buildroot=/tmp', '--chrome_rev=%s' % constants.CHROME_REV_LATEST, '--chrome_rev=%s' % constants.CHROME_REV_STICKY, '--chrome_rev=%s' % constants.CHROME_REV_TOT, '--chrome_rev=%s' % constants.CHROME_REV_TOT, '--chrome_rev=%s' % constants.CHROME_REV_STICKY, '--chrome_rev=%s' % constants.CHROME_REV_LATEST, '--chrome_rev=%s' % constants.CHROME_REV_LOCAL, '--chrome_root=.', '--chrome_rev=%s' % constants.CHROME_REV_TOT, '--chrome_rev=%s' % constants.CHROME_REV_LOCAL, self._GENERIC_PREFLIGHT, ] options = cbuildbot.ParseCommandLine(self.parser, args) self.assertEqual(options.chrome_rev, constants.CHROME_REV_LOCAL) self.assertNotEqual(options.chrome_root, None)
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'
def testBuildBotOption(self): """Test that --buildbot option unsets debug flag.""" args = ['-r', self._BUILD_ROOT, '--buildbot', self._GENERIC_PREFLIGHT] options = cbuildbot.ParseCommandLine(self.parser, args) self.assertFalse(options.debug) self.assertTrue(options.buildbot)
def testCreateBranchDelete(self): """Test we don't require --version with --delete.""" args = ['-r', self._BUILD_ROOT, '--delete-branch', '--branch-name', 'refs/heads/test', constants.BRANCH_UTIL_CONFIG] cbuildbot.ParseCommandLine(self.parser, args)
def testBuildBotWithoutProfileOption(self): """Test that no --profile option gets defaulted.""" args = ['-r', self._BUILD_ROOT, '--buildbot', self._GENERIC_PREFLIGHT] options = cbuildbot.ParseCommandLine(self.parser, args) self.assertEquals(options.profile, None)