def testGetBoardsComplexConfig(self): site_config = MockSiteConfig() site_config.Add('build_a', config_lib.BuildConfig(), boards=['foo_board']) site_config.Add('build_b', config_lib.BuildConfig(), boards=['bar_board']) site_config.Add('build_c', config_lib.BuildConfig(), boards=['foo_board', 'car_board']) self.assertEqual( site_config.GetBoards(), set(['x86-generic', 'foo_board', 'bar_board', 'car_board']))
def setUp(self): self.fooConfig = config_lib.BuildConfig(name='foo', value=1) self.barConfig = config_lib.BuildConfig(name='bar', value=2) self.deepConfig = config_lib.BuildConfig( name='deep', nested=[1, 2, 3], value=3, child_configs=[self.fooConfig, self.barConfig]) self.config = { 'foo': self.fooConfig, 'bar': self.barConfig, 'deep': self.deepConfig, }
def testCallableOverrides(self): append_foo = lambda x: x + 'foo' if x else 'foo' base_config = config_lib.BuildConfig() inherited_config_1 = base_config.derive(foo=append_foo) inherited_config_2 = inherited_config_1.derive(foo=append_foo) self.assertEqual(inherited_config_1, {'foo': 'foo'}) self.assertEqual(inherited_config_2, {'foo': 'foofoo'})
def testAppendUseflags(self): base_config = config_lib.BuildConfig() inherited_config_1 = base_config.derive( useflags=chromeos_config.append_useflags(['foo', 'bar', '-baz'])) inherited_config_2 = inherited_config_1.derive( useflags=chromeos_config.append_useflags(['-bar', 'baz'])) self.assertEqual(inherited_config_1.useflags, ['-baz', 'bar', 'foo']) self.assertEqual(inherited_config_2.useflags, ['-bar', 'baz', 'foo'])
def testAddErrors(self): """Test the SiteConfig.Add behavior.""" site_config = MockSiteConfig() site_config.Add('foo') # TODO(kevcheng): Disabled test for now until I figure out where configs # are repeatedly added in chromeos_config_unittest. # Test we can't add the 'foo' config again. # with self.assertRaises(AssertionError): # site_config.Add('foo') # Create a template without using AddTemplate so the site config doesn't # know about it. fake_template = config_lib.BuildConfig(name='fake_template', _template='fake_template') with self.assertRaises(AssertionError): site_config.Add('bar', fake_template)
def VerifyStage(self, failing, inflight, handle_failure=True, handle_timeout=False, sane_tot=True, submit_partial=False, alert=False, stage=None, all_slaves=None, slave_stages=None, do_submit_partial=True, build_passed=False): """Runs and Verifies PerformStage. Args: failing: The names of the builders that failed. inflight: The names of the buiders that timed out. handle_failure: If True, calls HandleValidationFailure. handle_timeout: If True, calls HandleValidationTimeout. sane_tot: If not true, assumes TOT is not sane. submit_partial: If True, submit partial pool will submit some changes. alert: If True, sends out an alert email for infra failures. stage: If set, use this constructed stage, otherwise create own. all_slaves: Optional set of all slave configs. slave_stages: Optional list of slave stages. do_submit_partial: If True, assert that there was no call to SubmitPartialPool. build_passed: Whether the build passed or failed. """ if not stage: stage = self.ConstructStage() # Setup the stage to look at the specified configs. all_slaves = list(all_slaves or set(failing + inflight)) configs = [config_lib.BuildConfig(name=x) for x in all_slaves] self.PatchObject(stage, '_GetSlaveConfigs', return_value=configs) # Setup builder statuses. stage._run.attrs.manifest_manager = mock.MagicMock() statuses = {} for x in failing: statuses[x] = manifest_version.BuilderStatus( constants.BUILDER_STATUS_FAILED, message=None) for x in inflight: statuses[x] = manifest_version.BuilderStatus( constants.BUILDER_STATUS_INFLIGHT, message=None) if self._run.config.master: self.PatchObject(stage._run.attrs.manifest_manager, 'GetBuildersStatus', return_value=statuses) else: self.PatchObject(stage, '_GetLocalBuildStatus', return_value=statuses) # Setup DB and provide list of slave stages. mock_cidb = mock.MagicMock() cidb.CIDBConnectionFactory.SetupMockCidb(mock_cidb) if slave_stages is None: slave_stages = [] critical_stages = ( completion_stages.CommitQueueCompletionStage._CRITICAL_STAGES) for stage_name, slave in itertools.product(critical_stages, all_slaves): slave_stages.append({'name': stage_name, 'build_config': slave, 'status': constants.BUILDER_STATUS_PASSED}) self.PatchObject(mock_cidb, 'GetSlaveStages', return_value=slave_stages) # Set up SubmitPartialPool to provide a list of changes to look at. if submit_partial: spmock = self.PatchObject(stage.sync_stage.pool, 'SubmitPartialPool', return_value=self.other_changes) handlefailure_changes = self.other_changes else: spmock = self.PatchObject(stage.sync_stage.pool, 'SubmitPartialPool', return_value=self.changes) handlefailure_changes = self.changes # Track whether 'HandleSuccess' is called. success_mock = self.PatchObject(stage, 'HandleSuccess') # Actually run the stage. if build_passed: stage.PerformStage() else: with self.assertRaises(completion_stages.ImportantBuilderFailedException): stage.PerformStage() # Verify the calls. self.assertEqual(success_mock.called, build_passed) if not build_passed and self._run.config.master: self.tot_sanity_mock.assert_called_once_with(mock.ANY, mock.ANY) if alert: self.alert_email_mock.called_once_with( mock.ANY, mock.ANY, mock.ANY, mock.ANY) self.assertEqual(do_submit_partial, spmock.called) if handle_failure: stage.sync_stage.pool.handle_failure_mock.assert_called_once_with( mock.ANY, no_stat=set([]), sanity=sane_tot, changes=handlefailure_changes) if handle_timeout: stage.sync_stage.pool.handle_timeout_mock.assert_called_once_with( sanity=mock.ANY, changes=self.changes)
def _GetTestConfig(self): test_config = config_lib.SiteConfig() test_config.Add( 'master', config_lib.BuildConfig(), boards=[], build_type=self.build_type, master=True, manifest_version=True, ) test_config.Add( 'test1', config_lib.BuildConfig(), boards=['x86-generic'], manifest_version=True, build_type=constants.PFQ_TYPE, overlays='public', important=False, chrome_rev=None, branch=False, internal=False, master=False, ) test_config.Add( 'test2', config_lib.BuildConfig(), boards=['x86-generic'], manifest_version=False, build_type=constants.PFQ_TYPE, overlays='public', important=True, chrome_rev=None, branch=False, internal=False, master=False, ) test_config.Add( 'test3', config_lib.BuildConfig(), boards=['x86-generic'], manifest_version=True, build_type=constants.PFQ_TYPE, overlays='both', important=True, chrome_rev=None, branch=False, internal=True, master=False, ) test_config.Add( 'test4', config_lib.BuildConfig(), boards=['x86-generic'], manifest_version=True, build_type=constants.PFQ_TYPE, overlays='both', important=True, chrome_rev=None, branch=True, internal=True, master=False, ) test_config.Add( 'test5', config_lib.BuildConfig(), boards=['x86-generic'], manifest_version=True, build_type=constants.PFQ_TYPE, overlays='public', important=True, chrome_rev=None, branch=False, internal=False, master=False, ) return test_config
def _ExtendDefaultConfig(**kwargs): """Extend DEFAULT_CONFIG with keys/values in kwargs.""" config_kwargs = DEFAULT_CONFIG.copy() config_kwargs.update(kwargs) return config_lib.BuildConfig(**config_kwargs)
# pylint: disable=W0212 DEFAULT_OPTIONS = cros_test_lib.EasyAttr( archive_base=DEFAULT_ARCHIVE_BASE, buildroot=DEFAULT_BUILDROOT, buildnumber=DEFAULT_BUILDNUMBER, buildbot=True, branch=DEFAULT_BRANCH, remote_trybot=False, debug=False, ) DEFAULT_CONFIG = config_lib.BuildConfig( name=DEFAULT_BOT_NAME, master=True, boards=[DEFAULT_BOARD], child_configs=[ config_lib.BuildConfig(name='foo'), config_lib.BuildConfig(name='bar'), ], ) def _ExtendDefaultOptions(**kwargs): """Extend DEFAULT_OPTIONS with keys/values in kwargs.""" options_kwargs = DEFAULT_OPTIONS.copy() options_kwargs.update(kwargs) return cros_test_lib.EasyAttr(**options_kwargs) def _ExtendDefaultConfig(**kwargs): """Extend DEFAULT_CONFIG with keys/values in kwargs."""
DEFAULT_OPTIONS = cros_test_lib.EasyAttr( archive_base=DEFAULT_ARCHIVE_BASE, buildroot=DEFAULT_BUILDROOT, buildnumber=DEFAULT_BUILDNUMBER, buildbot=True, branch=DEFAULT_BRANCH, remote_trybot=False, debug=False, postsync_patch=True, ) DEFAULT_CONFIG = config_lib.BuildConfig( name=DEFAULT_BOT_NAME, master=True, boards=[DEFAULT_BOARD], postsync_patch=True, child_configs=[ config_lib.BuildConfig(name='foo', postsync_patch=False, boards=[]), config_lib.BuildConfig(name='bar', postsync_patch=False, boards=[]), ], ) DEFAULT_VERSION = '6543.2.1' def _ExtendDefaultOptions(**kwargs): """Extend DEFAULT_OPTIONS with keys/values in kwargs.""" options_kwargs = DEFAULT_OPTIONS.copy() options_kwargs.update(kwargs) return cros_test_lib.EasyAttr(**options_kwargs)
def testAdd(self): """Test the SiteConfig.Add behavior.""" minimal_defaults = { 'name': None, '_template': None, 'value': 'default', } site_config = config_lib.SiteConfig(defaults=minimal_defaults) template = site_config.AddTemplate('template', value='template') mixin = config_lib.BuildConfig(value='mixin') site_config.Add('default') site_config.Add('default_with_override', value='override') site_config.Add('default_with_mixin', mixin) site_config.Add('mixin_with_override', mixin, value='override') site_config.Add('default_with_template', template) site_config.Add('template_with_override', template, value='override') site_config.Add('template_with_mixin', template, mixin) site_config.Add('template_with_mixin_override', template, mixin, value='override') expected = { 'default': { '_template': None, 'name': 'default', 'value': 'default', }, 'default_with_override': { '_template': None, 'name': 'default_with_override', 'value': 'override', }, 'default_with_mixin': { '_template': None, 'name': 'default_with_mixin', 'value': 'mixin', }, 'mixin_with_override': { '_template': None, 'name': 'mixin_with_override', 'value': 'override', }, 'default_with_template': { '_template': 'template', 'name': 'default_with_template', 'value': 'template', }, 'template_with_override': { '_template': 'template', 'name': 'template_with_override', 'value': 'override' }, 'template_with_mixin': { '_template': 'template', 'name': 'template_with_mixin', 'value': 'mixin', }, 'template_with_mixin_override': { '_template': 'template', 'name': 'template_with_mixin_override', 'value': 'override' }, } self.maxDiff = None self.assertDictEqual(site_config, expected)
def testDeleteKeys(self): base_config = config_lib.BuildConfig(foo='bar', baz='bak') inherited_config_1 = base_config.derive(qzr='flp') inherited_config_2 = inherited_config_1.derive( config_lib.BuildConfig.delete_keys(base_config)) self.assertEqual(inherited_config_2, {'qzr': 'flp'})
def testDeleteKey(self): base_config = config_lib.BuildConfig(foo='bar') inherited_config = base_config.derive( foo=config_lib.BuildConfig.delete_key()) self.assertTrue('foo' in base_config) self.assertFalse('foo' in inherited_config)