def test_no_long_running_tasks(self):
     evg_api = EvergreenApi()
     task_ids = ["1", "2"]
     now = datetime.now(timezone.utc).isoformat()
     task_1 = make_task_mock(evg_api, task_ids[0], now, now)
     task_2 = make_task_mock(evg_api, task_ids[1], now, now)
     evg_api.task_by_id = Mock(side_effect=(lambda task_id: {
         "1": task_1,
         "2": task_2,
     }[task_id]))
     long_running_task_ids = watch_tasks(task_ids, evg_api, 0)
     self.assertEqual([], long_running_task_ids)
示例#2
0
def validate_commit_messages(version_id: str, evg_api: EvergreenApi) -> int:
    """
    Validate the commit messages for the given build.

    :param version_id: ID of version to validate.
    :param evg_api: Evergreen API client.
    :return: True if all commit messages were valid.
    """
    found_error = False
    code_changes = evg_api.patch_by_id(version_id).module_code_changes
    for change in code_changes:
        for message in change.commit_messages:
            if any(
                    valid_pattern.match(message)
                    for valid_pattern in VALID_PATTERNS):
                continue
            elif any(
                    private_pattern.match(message)
                    for private_pattern in PRIVATE_PATTERNS):
                print(
                    ERROR_MSG.format(
                        error_msg="Reference to a private project",
                        branch=change.branch_name,
                        commit_message=message))
                found_error = True
            else:
                print(
                    ERROR_MSG.format(error_msg="Commit without a ticket",
                                     branch=change.branch_name,
                                     commit_message=message))
                found_error = True

    return STATUS_ERROR if found_error else STATUS_OK
 def test_found_long_running_tasks(self):
     evg_api = EvergreenApi()
     task_ids = ["1", "2"]
     exec_timeout_seconds_ago = (
         datetime.now(timezone.utc) -
         timedelta(hours=POWERCYCLE_TASK_EXEC_TIMEOUT_SECS)).isoformat()
     now = datetime.now(timezone.utc).isoformat()
     task_1 = make_task_mock(evg_api, task_ids[0], exec_timeout_seconds_ago,
                             now)
     task_2 = make_task_mock(evg_api, task_ids[1], exec_timeout_seconds_ago,
                             None)
     evg_api.task_by_id = Mock(side_effect=(lambda task_id: {
         "1": task_1,
         "2": task_2,
     }[task_id]))
     long_running_task_ids = watch_tasks(task_ids, evg_api, 0)
     self.assertEqual([task_2.task_id], long_running_task_ids)
示例#4
0
def generate_revision_map_from_manifest(repos: List[Repo], task_id: str,
                                        evg_api: EvergreenApi) -> RevisionMap:
    """
    Generate a revision map for the given repositories using the revisions from the manifest.

    :param repos: Repositories to generate map for.
    :param task_id: Id of evergreen task running.
    :param evg_api: Evergreen API object.
    :return: Map of repositories to revisions
    """
    manifest = evg_api.manifest_for_task(task_id)
    revisions_data = {
        module_name: module.revision
        for module_name, module in manifest.modules.items()
    }
    revisions_data["mongo"] = manifest.revision

    return generate_revision_map(repos, revisions_data)
示例#5
0
    def from_evg(cls, evg_api: EvergreenApi, project: str, start_date: datetime, end_date: datetime,
                 task: str, variant: str) -> "HistoricTaskData":
        """
        Retrieve test stats from evergreen for a given task.

        :param evg_api: Evergreen API client.
        :param project: Project to query.
        :param start_date: Start date to query.
        :param end_date: End date to query.
        :param task: Task to query.
        :param variant: Build variant to query.
        :return: Test stats for the specified task.
        """
        days = (end_date - start_date).days
        return cls(
            evg_api.test_stats_by_project(project, after_date=start_date, before_date=end_date,
                                          tasks=[task], variants=[variant], group_by="test",
                                          group_num_days=days))
示例#6
0
def watch_tasks(task_ids: List[str], evg_api: EvergreenApi, watch_interval_secs: int) -> List[str]:
    """Watch tasks if they run longer than exec timeout."""
    watch_task_ids = task_ids[:]
    long_running_task_ids = []

    while watch_task_ids:
        LOGGER.info("Looking if powercycle tasks are still running on the current buildvariant.")
        powercycle_tasks = [evg_api.task_by_id(task_id) for task_id in watch_task_ids]
        for task in powercycle_tasks:
            if task.finish_time:
                watch_task_ids.remove(task.task_id)
            elif task.start_time and (datetime.now(timezone.utc) - task.start_time
                                      ).total_seconds() > POWERCYCLE_TASK_EXEC_TIMEOUT_SECS:
                long_running_task_ids.append(task.task_id)
                watch_task_ids.remove(task.task_id)
        if watch_task_ids:
            time.sleep(watch_interval_secs)

    return long_running_task_ids
示例#7
0
def cli(ctx, display_format):
    """Create common CLI options."""
    ctx.ensure_object(dict)
    ctx.obj["api"] = EvergreenApi.get_api(use_config_file=True)
    ctx.obj["format"] = display_format