def setUp(self):
     """Common set up method for all tests."""
     self.committer = cros_best_revision.ChromeCommitter(
         self.tempdir, False)
     self.lkgm_file = os.path.join(self.tempdir,
                                   constants.PATH_TO_CHROME_LKGM)
     self.pass_status = manifest_version.BuilderStatus(
         constants.BUILDER_STATUS_PASSED, None)
     self.fail_status = manifest_version.BuilderStatus(
         constants.BUILDER_STATUS_FAILED, None)
    def _GetBuildersStatusWithBuildbucket(self, builders, status_runs,
                                          buildbucket_id_dict):
        """Test a call to BuildSpecsManager.GetBuildersStatus.

    Args:
      builders: List of builders to get status for.
      status_runs: List of dictionaries of expected build and status.
      buildbucket_id_dict: A dict mapping build names to buildbucket_ids.
    """
        result_dict = {'SUCCESS': 'pass', 'FAILURE': 'fail'}
        self.PatchObject(manifest_version.BuildSpecsManager,
                         'GetSlaveStatusesFromBuildbucket',
                         side_effect=status_runs)

        final_status_dict = status_runs[-1]
        build_statuses = [
            manifest_version.BuilderStatus(
                result_dict.get(final_status_dict.get(x).get('result')), None)
            for x in builders
        ]
        self.PatchObject(manifest_version.BuildSpecsManager,
                         'GetBuildStatus',
                         side_effect=build_statuses)

        return self.manager.GetBuildersStatus(
            'builderid', builders, buildbucket_id_dict=buildbucket_id_dict)
Exemplo n.º 3
0
    def testUnpickleBuildStatus(self):
        """Tests that _UnpickleBuildStatus returns the correct values."""
        failed_msg = failures_lib.BuildFailureMessage('you failed',
                                                      ['traceback'], True,
                                                      'taco', 'bot')
        failed_input_status = manifest_version.BuilderStatus(
            constants.BUILDER_STATUS_FAILED, failed_msg)
        passed_input_status = manifest_version.BuilderStatus(
            constants.BUILDER_STATUS_PASSED, None)

        failed_output_status = self.manager._UnpickleBuildStatus(
            failed_input_status.AsPickledDict())
        passed_output_status = self.manager._UnpickleBuildStatus(
            passed_input_status.AsPickledDict())
        empty_string_status = self.manager._UnpickleBuildStatus('')

        self.assertEqual(failed_input_status.AsFlatDict(),
                         failed_output_status.AsFlatDict())
        self.assertEqual(passed_input_status.AsFlatDict(),
                         passed_output_status.AsFlatDict())
        self.assertTrue(empty_string_status.Failed())
  def testAnnotateFailingBuilders(self):
    """Tests that _AnnotateFailingBuilders is free of syntax errors."""
    stage = self.ConstructStage()

    failing = {'a'}
    inflight = {}
    failed_msg = failures_lib.BuildFailureMessage(
        'message', [], True, 'reason', 'bot')
    status = manifest_version.BuilderStatus('failed', failed_msg, 'url')

    statuses = {'a' : status}
    no_stat = set()
    stage._AnnotateFailingBuilders(failing, inflight, no_stat, statuses)
    def _GetBuildersStatus(self, builders, status_runs):
        """Test a call to BuildSpecsManager.GetBuildersStatus.

    Args:
      builders: List of builders to get status for.
      status_runs: List of dictionaries of expected build and status.
    """
        self.PatchObject(manifest_version.BuildSpecsManager,
                         'GetSlaveStatusesFromCIDB',
                         side_effect=status_runs)

        final_status_dict = status_runs[-1]
        build_statuses = [
            manifest_version.BuilderStatus(final_status_dict.get(x), None)
            for x in builders
        ]
        self.PatchObject(manifest_version.BuildSpecsManager,
                         'GetBuildStatus',
                         side_effect=build_statuses)

        return self.manager.GetBuildersStatus('builderid', builders)
    def testLoadSpecs(self):
        """Tests whether we can load specs correctly."""
        self.manager = self.BuildManager()
        info = manifest_version.VersionInfo(FAKE_VERSION_STRING,
                                            CHROME_BRANCH,
                                            incr_type='branch')
        mpath = os.path.join(self.manager.manifest_dir, 'buildspecs',
                             CHROME_BRANCH)
        m1, m2, m3, m4 = [
            os.path.join(mpath, '1.2.%d.xml' % x) for x in [2, 3, 4, 5]
        ]
        for_build = os.path.join(self.manager.manifest_dir, 'build-name',
                                 self.build_names[0])

        # Create fake buildspecs.
        osutils.SafeMakedirs(os.path.join(mpath))
        for m in [m1, m2, m3, m4]:
            osutils.Touch(m)

        # Fake BuilderStatus with status MISSING.
        missing = manifest_version.BuilderStatus(
            constants.BUILDER_STATUS_MISSING, None)

        # Fail 1, pass 2, leave 3,4 unprocessed.
        manifest_version.CreateSymlink(
            m1,
            os.path.join(for_build, 'fail', CHROME_BRANCH,
                         os.path.basename(m1)))
        manifest_version.CreateSymlink(
            m1,
            os.path.join(for_build, 'pass', CHROME_BRANCH,
                         os.path.basename(m2)))
        m = self.PatchObject(self.manager,
                             'GetBuildStatus',
                             return_value=missing)
        self.manager.InitializeManifestVariables(info)
        self.assertEqual(self.manager.latest_unprocessed, '1.2.5')
        m.assert_called_once_with(self.build_names[0], '1.2.5')
Exemplo n.º 7
0
 def _GetLocalBuildStatus(self):
     """Return the status for this build as a dictionary."""
     status = manifest_version.BuilderStatus.GetCompletedStatus(
         self.success)
     status_obj = manifest_version.BuilderStatus(status, self.message)
     return {self._bot_id: status_obj}
  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)