def testGetBuilderClassConfig(self): """Check behavior when requesting config builders. This can't be done with live classes since the site config may or may not be there. """ # Setup mock_module = mock.Mock() mock_module.MyBuilder = 'fake_class' mock_import = self.PatchObject(importlib, 'import_module', return_value=mock_module) # Test result = builders.GetBuilderClass('config.my_builders.MyBuilder') # Verify mock_import.assert_called_once_with('chromite.config.my_builders') self.assertEqual(result, 'fake_class') # Test again with a nested builder class name. mock_import.reset_mock() # Test result = builders.GetBuilderClass( 'config.nested.my_builders.MyBuilder') # Verify mock_import.assert_called_once_with( 'chromite.config.nested.my_builders') self.assertEqual(result, 'fake_class')
def testCheckBuilderClass(self): """Verify builder_class_name is a valid value.""" for build_name, config in self.site_config.items(): builder_class_name = config['builder_class_name'] if builder_class_name is None: continue cls = builders.GetBuilderClass(builder_class_name) self.assertTrue(issubclass(cls, generic_builders.Builder), msg=('config %s has a broken builder_class_name' % build_name))
def testGetBuilderClass(self): """Check behavior when requesting a valid builder.""" result = builders.GetBuilderClass('simple_builders.SimpleBuilder') self.assertEqual(result, simple_builders.SimpleBuilder)
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)