Beispiel #1
0
    def setUp(self):

        self.cl1 = clactions.GerritChangeTuple(11111, True)
        self.cl1_patch1 = clactions.GerritPatchTuple(self.cl1.gerrit_number, 1,
                                                     self.cl1.internal)
        self.cl1_patch2 = clactions.GerritPatchTuple(self.cl1.gerrit_number, 2,
                                                     self.cl1.internal)

        self.cl2 = clactions.GerritChangeTuple(22222, True)
        self.cl2_patch1 = clactions.GerritPatchTuple(self.cl2.gerrit_number, 1,
                                                     self.cl2.internal)
        self.cl2_patch2 = clactions.GerritPatchTuple(self.cl2.gerrit_number, 2,
                                                     self.cl2.internal)

        self.cl3 = clactions.GerritChangeTuple(33333, True)
        self.cl3_patch1 = clactions.GerritPatchTuple(self.cl3.gerrit_number, 2,
                                                     self.cl3.internal)

        # Expected actions in chronological order, most recent first.
        self.action1 = clactions.CLAction.FromGerritPatchAndAction(
            self.cl1_patch2,
            constants.CL_ACTION_SUBMITTED,
            timestamp=self._NDaysAgo(1))
        self.action2 = clactions.CLAction.FromGerritPatchAndAction(
            self.cl1_patch2,
            constants.CL_ACTION_KICKED_OUT,
            timestamp=self._NDaysAgo(2))
        self.action3 = clactions.CLAction.FromGerritPatchAndAction(
            self.cl2_patch2,
            constants.CL_ACTION_SUBMITTED,
            timestamp=self._NDaysAgo(3))
        self.action4 = clactions.CLAction.FromGerritPatchAndAction(
            self.cl1_patch1,
            constants.CL_ACTION_SUBMIT_FAILED,
            timestamp=self._NDaysAgo(4))
        self.action5 = clactions.CLAction.FromGerritPatchAndAction(
            self.cl1_patch1,
            constants.CL_ACTION_KICKED_OUT,
            timestamp=self._NDaysAgo(5))
        self.action6 = clactions.CLAction.FromGerritPatchAndAction(
            self.cl3_patch1,
            constants.CL_ACTION_SUBMITTED,
            reason=constants.STRATEGY_NONMANIFEST,
            timestamp=self._NDaysAgo(6))

        # CLActionHistory does not require the history to be given in chronological
        # order, so we provide them in reverse order, and expect them to be sorted
        # as appropriate.
        self.cl_action_stats = clactions.CLActionHistory([
            self.action1, self.action2, self.action3, self.action4,
            self.action5, self.action6
        ])
Beispiel #2
0
    def setUp(self):
        self._days_forward = 1
        self._build_id = 1
        self.action_history = []
        self.cl_action_stats = None

        self.cl1 = clactions.GerritChangeTuple(11111, True)
        self.cl1_patch1 = clactions.GerritPatchTuple(self.cl1.gerrit_number, 1,
                                                     self.cl1.internal)
        self.cl1_patch2 = clactions.GerritPatchTuple(self.cl1.gerrit_number, 2,
                                                     self.cl1.internal)

        self.cl2 = clactions.GerritChangeTuple(22222, True)
        self.cl2_patch1 = clactions.GerritPatchTuple(self.cl2.gerrit_number, 1,
                                                     self.cl2.internal)
        self.cl2_patch2 = clactions.GerritPatchTuple(self.cl2.gerrit_number, 2,
                                                     self.cl2.internal)
Beispiel #3
0
    def GetPreviouslyPassedSlavesForChanges(
            cls,
            master_build_id,
            db,
            changes,
            change_relevant_slaves_dict,
            history_lookback_limit=CQ_HISTORY_LOOKBACK_LIMIT_HOUR):
        """Get slaves passed in history (not from current run) for changes.

    If a previous slave build:
    1) inserted constants.CL_ACTION_RELEVANT_TO_SLAVE cl action for a change;
    2) is a passed build;
    3) is a relevant slave of the change
    this slave is considered as a previously passed slave.

    Args:
      master_build_id: The build id of current master to get current slaves.
      db: An instance of cidb.CIDBConnection.
      changes: A list of cros_patch.GerritPatch instance to check.
      change_relevant_slaves_dict: A dict mapping changes to their relevant
        slaves in current run.
      history_lookback_limit: Limit (hours) for looking back cl actions in the
        histor. If it's None, do not force the limit.
        Default to CQ_HISTORY_LOOKBACK_LIMIT_HOUR.

    Returns:
      A dict mapping changes (cros_patch.GerritPatch instances) to sets of
      of build config name (strings) of their relevant slaves which passed in
      history.
    """
        assert db, 'No database connection to use.'
        current_slaves = db.GetSlaveStatuses(master_build_id)
        current_slave_build_ids = [x['id'] for x in current_slaves]

        valid_configs = set()
        for relevant_slaves in change_relevant_slaves_dict.values():
            valid_configs.update(relevant_slaves)

        changes_dict = {
            clactions.GerritPatchTuple(int(change.gerrit_number),
                                       int(change.patch_number),
                                       change.internal): change
            for change in changes
        }

        start_time = None
        if history_lookback_limit is not None:
            start_time = (datetime.datetime.now() -
                          datetime.timedelta(hours=history_lookback_limit))

        actions = db.GetActionsForChanges(
            changes,
            ignore_patch_number=False,
            status=constants.BUILDER_STATUS_PASSED,
            action=constants.CL_ACTION_RELEVANT_TO_SLAVE,
            start_time=start_time)

        change_passed_slaves_dict = {}
        for action in actions:
            if (action.build_config in valid_configs
                    and action.build_id not in current_slave_build_ids):
                change = changes_dict.get(action.patch)
                if change:
                    change_passed_slaves_dict.setdefault(change, set()).add(
                        action.build_config)

        return change_passed_slaves_dict