diff options
author | Aviv Keshet <akeshet@chromium.org> | 2015-06-04 10:39:07 -0700 |
---|---|---|
committer | Aviv Keshet <akeshet@chromium.org> | 2015-06-04 20:29:51 +0000 |
commit | 6f3ccd986224ef9533c4e74cd322bf28d2abedfa (patch) | |
tree | 75f9d01f7ecb2e38bf50413b9690c68871231f22 /cbuildbot/stages | |
parent | b17d753bfbbfe4e82e6cf44af26d6bd8ed206757 (diff) | |
download | chromite-6f3ccd986224ef9533c4e74cd322bf28d2abedfa.tar.gz |
report_stages: surface a link from slave build to its master
BUG=chromium:496752
TEST=Unit tests enhanced to use fake_cidb, and use a master_build_id.
Verified that unit tests are exercising new code path.
Change-Id: I89497e449e29cc2c52474e37688891a086e29c48
Reviewed-on: https://chromium-review.googlesource.com/275314
Trybot-Ready: Aviv Keshet <akeshet@chromium.org>
Tested-by: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Commit-Queue: Aviv Keshet <akeshet@chromium.org>
Diffstat (limited to 'cbuildbot/stages')
-rw-r--r-- | cbuildbot/stages/generic_stages_unittest.py | 7 | ||||
-rw-r--r-- | cbuildbot/stages/report_stages.py | 9 | ||||
-rw-r--r-- | cbuildbot/stages/report_stages_unittest.py | 30 |
3 files changed, 29 insertions, 17 deletions
diff --git a/cbuildbot/stages/generic_stages_unittest.py b/cbuildbot/stages/generic_stages_unittest.py index 42eafd359..435bd3442 100644 --- a/cbuildbot/stages/generic_stages_unittest.py +++ b/cbuildbot/stages/generic_stages_unittest.py @@ -73,7 +73,8 @@ class StageTestCase(cros_test_lib.MockOutputTestCase, 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=constants.WATERFALL_INTERNAL, + master_build_id=None): """Prepare a BuilderRun at self._run for this test. This method must allow being called more than once. Subclasses can @@ -99,6 +100,7 @@ class StageTestCase(cros_test_lib.MockOutputTestCase, self._run.options.branch_name to be set to 'some-branch-name'. build_id: mock build id waterfall: One of constants.CIDB_KNOWN_WATERFALLS. + master_build_id: mock build id of master build. """ # Use cbuildbot parser to create options object and populate default values. parser = cbuildbot._CreateParser() @@ -151,6 +153,9 @@ class StageTestCase(cros_test_lib.MockOutputTestCase, 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}) if self.RELEASE_TAG is not None: diff --git a/cbuildbot/stages/report_stages.py b/cbuildbot/stages/report_stages.py index ecd96d7c7..1d57d3ac6 100644 --- a/cbuildbot/stages/report_stages.py +++ b/cbuildbot/stages/report_stages.py @@ -163,6 +163,15 @@ class BuildStartStage(generic_stages.BuilderStage): logging.info('Inserted build_id %s into cidb database type %s.', build_id, db_type) + master_build_id = d['master_build_id'] + if master_build_id is not None: + master_build_status = db.GetBuildStatus(master_build_id) + master_url = tree_status.ConstructDashboardURL( + master_build_status['waterfall'], + master_build_status['builder_name'], + master_build_status['build_number']) + cros_build_lib.PrintBuildbotLink('Link to master build', + master_url) def HandleSkip(self): """Ensure that re-executions use the same db instance as initial db.""" diff --git a/cbuildbot/stages/report_stages_unittest.py b/cbuildbot/stages/report_stages_unittest.py index 9729559b8..200d9a45b 100644 --- a/cbuildbot/stages/report_stages_unittest.py +++ b/cbuildbot/stages/report_stages_unittest.py @@ -66,7 +66,8 @@ class BuildReexecutionStageTest(generic_stages_unittest.AbstractStageTestCase): """Test that master/slave version mismatch causes failure.""" master_release_tag = '9999.0.0-rc1' master_build_id = self.fake_db.InsertBuild( - 'master', 'waterfall', 2, 'master config', 'master hostname') + 'master', constants.WATERFALL_INTERNAL, 2, 'master config', + 'master hostname') master_metadata = metadata_lib.CBuildbotMetadata() master_metadata.UpdateKeyDictWithDict( 'version', {'full' : 'R39-9999.0.0-rc1', @@ -87,11 +88,16 @@ class BuildStartStageTest(generic_stages_unittest.AbstractStageTestCase): """Tests that BuildStartStage behaves as expected.""" def setUp(self): - self.mock_cidb = mock.MagicMock() - cidb.CIDBConnectionFactory.SetupMockCidb(self.mock_cidb) + self.db = fake_cidb.FakeCIDBConnection() + cidb.CIDBConnectionFactory.SetupMockCidb(self.db) retry_stats.SetupStats() - os.environ['BUILDBOT_MASTERNAME'] = 'chromiumos' - self._Prepare(build_id=None) + os.environ['BUILDBOT_MASTERNAME'] = constants.WATERFALL_EXTERNAL + + master_build_id = self.db.InsertBuild( + 'master_build', constants.WATERFALL_EXTERNAL, 1, + 'master_build_config', 'bot_hostname') + + self._Prepare(build_id=None, master_build_id=master_build_id) def testUnknownWaterfall(self): """Test that an assertion is thrown if master name is not valid.""" @@ -100,18 +106,10 @@ class BuildStartStageTest(generic_stages_unittest.AbstractStageTestCase): def testPerformStage(self): """Test that a normal run of the stage does a database insert.""" - self.PatchObject(self.mock_cidb, 'InsertBuild', return_value=31337) - self.RunStage() - self.mock_cidb.InsertBuild.assert_called_once_with( - bot_hostname=mock.ANY, - build_config='x86-generic-paladin', - build_number=1234321, - builder_name=mock.ANY, - master_build_id=None, - waterfall='chromiumos', - timeout_seconds=mock.ANY) - self.assertEqual(self._run.attrs.metadata.GetValue('build_id'), 31337) + + build_id = self._run.attrs.metadata.GetValue('build_id') + self.assertGreater(build_id, 0) self.assertEqual(self._run.attrs.metadata.GetValue('db_type'), cidb.CONNECTION_TYPE_MOCK) |