Exemple #1
0
class RunningTask(_BaseEvergreenObject):
    """Representation of a running task."""

    task_id = evg_attrib('task_id')
    name = evg_attrib('name')
    dispatch_time = evg_datetime_attrib('dispatch_time')
    version_id = evg_attrib('version_id')
    build_id = evg_attrib('build_id')

    def __init__(self, json, api):
        """
        Create an instance of a Running Task.

        :param json: json of running task.
        :param api: Evergreen API.
        """
        super(RunningTask, self).__init__(json, api)

    def get_build(self):
        """
        Get build for the running task.

        :return: build object for task.
        """
        return self._api.build_by_id(self.build_id)

    def get_version(self):
        """
        Get version for the running task.

        :return: version object for task.
        """
        return self._api.version_by_id(self.version_id)
Exemple #2
0
class RunningTask(_BaseEvergreenObject):
    """Representation of a running task."""

    task_id = evg_attrib("task_id")
    name = evg_attrib("name")
    dispatch_time = evg_datetime_attrib("dispatch_time")
    version_id = evg_attrib("version_id")
    build_id = evg_attrib("build_id")

    def __init__(self, json: Dict[str, Any], api: "EvergreenApi") -> None:
        """
        Create an instance of a Running Task.

        :param json: json of running task.
        :param api: Evergreen API.
        """
        super(RunningTask, self).__init__(json, api)

    def get_build(self) -> "Build":
        """
        Get build for the running task.

        :return: build object for task.
        """
        return self._api.build_by_id(self.build_id)

    def get_version(self) -> "Version":
        """
        Get version for the running task.

        :return: version object for task.
        """
        return self._api.version_by_id(self.version_id)
class Source(_BaseEvergreenObject):
    """Source of where an annotation was generated."""

    author = evg_attrib("author")
    time = evg_datetime_attrib("time")
    requester = evg_attrib("requester")

    def __init__(self, json: Dict[str, Any], api: "EvergreenApi") -> None:
        """Create an instance of a task annotation source."""
        super().__init__(json, api)
Exemple #4
0
class Tst(_BaseEvergreenObject):
    """Representation of a test object from evergreen."""

    task_id = evg_attrib("task_id")
    status = evg_attrib("status")
    test_file = evg_attrib("test_file")
    exit_code = evg_attrib("exit_code")
    start_time = evg_datetime_attrib("start_time")
    end_time = evg_datetime_attrib("end_time")

    def __init__(self, json: Dict[str, Any], api: "EvergreenApi") -> None:
        """Create an instance of a Test object."""
        super(Tst, self).__init__(json, api)

    @property
    def logs(self) -> Logs:
        """
        Get the log object for the given test.

        :return: log object for test.
        """
        return Logs(self.json["logs"], self._api)
class PerformanceTestBatch(_BaseEvergreenObject):
    """Representation of a batch of tests from Evergreen."""
    start = evg_datetime_attrib('start')
    end = evg_datetime_attrib('end')
    storage_engine = evg_attrib('storageEngine')
    errors = evg_attrib('errors')

    def __init__(self, json, api, parent):
        """Create an instance of a batch of tests"""
        super(PerformanceTestBatch, self).__init__(json, api)
        self.parent = parent

    @property
    def test_runs(self):
        return [
            PerformanceTestRun(item, self._api)
            for item in self.json['results']
        ]

    def test_runs_matching(self, tests):
        return [
            item for item in self.test_runs if _is_run_matching(item, tests)
        ]
Exemple #6
0
class Tst(_BaseEvergreenObject):
    """
    Representation of a test object from evergreen.
    """

    task_id = evg_attrib('task_id')
    status = evg_attrib('status')
    test_file = evg_attrib('test_file')
    exit_code = evg_attrib('exit_code')
    start_time = evg_datetime_attrib('start_time')
    end_time = evg_datetime_attrib('end_time')

    def __init__(self, json, api):
        """Create an instance of a Test object."""
        super(Tst, self).__init__(json, api)

    @property
    def logs(self):
        """
        Get the log object for the given test.

        :return: log object for test.
        """
        return Logs(self.json['logs'], self._api)
Exemple #7
0
class Patch(_BaseEvergreenObject):
    """Representation of an Evergreen patch."""

    patch_id = evg_attrib('patch_id')
    description = evg_attrib('description')
    project_id = evg_attrib('project_id')
    branch = evg_attrib('branch')
    git_hash = evg_attrib('git_hash')
    patch_number = evg_attrib('patch_number')
    author = evg_attrib('author')
    version = evg_attrib('version')
    status = evg_attrib('status')
    create_time = evg_datetime_attrib('create_time')
    start_time = evg_datetime_attrib('start_time')
    finish_time = evg_datetime_attrib('finish_time')
    builds = evg_attrib('builds')
    tasks = evg_attrib('tasks')
    activated = evg_attrib('activated')
    alias = evg_attrib('alias')

    def __init__(self, json, api):
        """
        Create an instance of an evergreen patch.

        :param json: json representing patch.
        """
        super(Patch, self).__init__(json, api)
        self._variants_tasks = None
        self._variant_task_dict = None

    @property
    def github_patch_data(self):
        """
        Retrieve the github patch data for this patch.

        :return: Github Patch Data for this patch.
        """
        return GithubPatchData(self.json['github_patch_data'], self._api)

    @property
    def variants_tasks(self):
        """
        Retrieve the variants tasks for this patch.

        :return: variants tasks for this patch.
        """
        if not self._variants_tasks:
            self._variants_tasks = [
                VariantsTasks(vt, self._api) for vt in self.json['variants_tasks']
            ]
        return self._variants_tasks

    def task_list_for_variant(self, variant):
        """
        Retrieve the list of tasks for the given variant.

        :param variant: name of variant to search for.
        :return: list of tasks belonging to the specified variant.
        """
        if not self._variant_task_dict:
            self._variant_task_dict = {vt.name: vt.tasks for vt in self.variants_tasks}
        return self._variant_task_dict[variant]

    def get_version(self):
        """
        Get version for this patch.

        :return: Version object.
        """
        return self._api.version_by_id(self.version)

    def __str__(self):
        return '{}: {}'.format(self.patch_id, self.description)
Exemple #8
0
class Task(_BaseEvergreenObject):
    """Representation of an Evergreen task."""

    activated = evg_attrib("activated")
    activated_by = evg_attrib("activated_by")
    build_id = evg_attrib("build_id")
    build_variant = evg_attrib("build_variant")
    create_time = evg_datetime_attrib("create_time")
    depends_on = evg_attrib("depends_on")
    dispatch_time = evg_datetime_attrib("dispatch_time")
    display_name = evg_attrib("display_name")
    display_only = evg_attrib("display_only")
    distro_id = evg_attrib("distro_id")
    est_wait_to_start_ms = evg_attrib("est_wait_to_start_ms")
    estimated_cost = evg_attrib("estimated_cost")
    execution = evg_attrib("execution")
    execution_tasks = evg_attrib("execution_tasks")
    expected_duration_ms = evg_attrib("expected_duration_ms")
    finish_time = evg_datetime_attrib("finish_time")
    generate_task = evg_attrib("generate_task")
    generated_by = evg_attrib("generated_by")
    host_id = evg_attrib("host_id")
    ingest_time = evg_datetime_attrib("ingest_time")
    mainline = evg_attrib("mainline")
    order = evg_attrib("order")
    project_id = evg_attrib("project_id")
    priority = evg_attrib("priority")
    restarts = evg_attrib("restarts")
    revision = evg_attrib("revision")
    scheduled_time = evg_datetime_attrib("scheduled_time")
    start_time = evg_datetime_attrib("start_time")
    status = evg_attrib("status")
    task_group = evg_attrib("task_group")
    task_group_max_hosts = evg_attrib("task_group_max_hosts")
    task_id = evg_attrib("task_id")
    time_taken_ms = evg_attrib("time_taken_ms")
    version_id = evg_attrib("version_id")

    def __init__(self, json: Dict[str, Any], api: "EvergreenApi") -> None:
        """Create an instance of an evergreen task."""
        super(Task, self).__init__(json, api)
        self._logs_map: Optional[Dict[Any, Any]] = None

    @property
    def artifacts(self) -> List[Artifact]:
        """
        Retrieve the artifacts for the given task.

        :return: List of artifacts.
        """
        if not self.json.get("artifacts"):
            return []
        return [Artifact(artifact, self._api) for artifact in self.json["artifacts"]]

    @property
    def log_map(self) -> Dict:
        """
        Retrieve a dict of all the logs.

        :return: Dictionary of the logs.
        """
        if not self._logs_map:
            self._logs_map = {key: value for key, value in self.json["logs"].items()}
        return self._logs_map

    def retrieve_log(self, log_name: str, raw: bool = False) -> str:
        """
        Retrieve the contents of the specified log.

        :param log_name: Name of log to retrieve.
        :param raw: Retrieve raw version of log.
        :return: Contents of the specified log.
        """
        return self._api.retrieve_task_log(self.log_map[log_name], raw)

    def stream_log(self, log_name: str) -> Iterable[str]:
        """
        Retrieve an iterator of a streamed log contents for the given log.

        :param log_name: Log to stream.
        :return: Iterable log contents.
        """
        return self._api.stream_log(self.log_map[log_name])

    @property
    def status_details(self) -> StatusDetails:
        """
        Retrieve the status details for the given task.

        :return: Status details.
        """
        return StatusDetails(self.json["status_details"], self._api)

    def get_status_score(self) -> StatusScore:
        """
        Retrieve the status score enum for the given task.

        :return: Status score.
        """
        return StatusScore.get_task_status_score(self)

    def get_execution(self, execution: int) -> Optional["Task"]:
        """
        Get the task info for the specified execution.

        :param execution: Index of execution.
        :return: Task info for specified execution.
        """
        if self.execution == execution:
            return self

        if "previous_executions" in self.json:
            for task in self.json["previous_executions"]:
                if task["execution"] == execution:
                    return Task(task, self._api)

        return None

    def get_execution_or_self(self, execution: int) -> "Task":
        """
        Get the specified execution if it exists.

        If the specified execution does not exist, return self.

        :param execution: Index of execution.
        :return: Task info for specified execution or self.
        """
        task_execution = self.get_execution(execution)
        if task_execution:
            return task_execution
        return self

    def wait_time(self) -> Optional[timedelta]:
        """
        Get the time taken until the task started running.

        :return: Time taken until task started running.
        """
        if self.start_time and self.ingest_time:
            return self.start_time - self.ingest_time
        return None

    def wait_time_once_unblocked(self) -> Optional[timedelta]:
        """
        Get the time taken until the task started running.

        Once it is unblocked by task dependencies.

        :return: Time taken until task started running.
        """
        if self.start_time and self.scheduled_time:
            return self.start_time - self.scheduled_time
        return None

    def is_success(self) -> bool:
        """
        Whether task was successful.

        :return: True if task was successful.
        """
        return self.status == EVG_SUCCESS_STATUS

    def is_undispatched(self) -> bool:
        """
        Whether the task was undispatched.

        :return: True is task was undispatched.
        """
        return self.status == EVG_UNDISPATCHED_STATUS

    def is_system_failure(self) -> bool:
        """
        Whether task resulted in a system failure.

        :return: True if task was a system failure.
        """
        if not self.is_success() and self.status_details and self.status_details.type:
            return self.status_details.type == EVG_SYSTEM_FAILURE_STATUS
        return False

    def is_timeout(self) -> bool:
        """
        Whether task results in a timeout.

        :return: True if task was a timeout.
        """
        if not self.is_success() and self.status_details and self.status_details.timed_out:
            return self.status_details.timed_out
        return False

    def is_active(self) -> bool:
        """
        Determine if the given task is active.

        :return: True if task is active.
        """
        return self.scheduled_time and not self.finish_time

    def get_tests(
        self, status: Optional[str] = None, execution: Optional[int] = None
    ) -> List["Tst"]:
        """
        Get the test results for this task.

        :param status: Only return tests with the given status.
        :param execution: Return results for specified execution, if specified.
        :return: List of test results for the task.
        """
        return self._api.tests_by_task(
            self.task_id,
            status=status,
            execution=self.execution if execution is None else execution,
        )

    def get_execution_tasks(
        self, filter_fn: Optional[Callable[["Task"], bool]] = None
    ) -> Optional[List["Task"]]:
        """
        Get a list of execution tasks associated with this task.

        If this is a display task, return the tasks execution tasks associated with it. 
        If this is not a display task, returns None.

        :param filter_fn: Function to filter returned results.
        :return: List of execution tasks.
        """
        if self.display_only:
            execution_tasks = [
                self._api.task_by_id(task_id, fetch_all_executions=True)
                for task_id in self.execution_tasks
            ]

            execution_tasks = [
                task.get_execution_or_self(self.execution) for task in execution_tasks
            ]

            if filter_fn:
                return [task for task in execution_tasks if filter_fn(task)]
            return execution_tasks

        return None

    def get_manifest(self) -> Manifest:
        """Get the Manifest for this task."""
        return self._api.manifest_for_task(self.task_id)

    def __repr__(self) -> str:
        """
        Get a string representation of Task for debugging purposes.

        :return: String representation of Task.
        """
        return "Task({id})".format(id=self.task_id)
Exemple #9
0
class Patch(_BaseEvergreenObject):
    """Representation of an Evergreen patch."""

    patch_id = evg_attrib("patch_id")
    description = evg_attrib("description")
    project_id = evg_attrib("project_id")
    branch = evg_attrib("branch")
    git_hash = evg_attrib("git_hash")
    patch_number = evg_attrib("patch_number")
    author = evg_attrib("author")
    version = evg_attrib("version")
    status = evg_attrib("status")
    create_time = evg_datetime_attrib("create_time")
    start_time = evg_datetime_attrib("start_time")
    finish_time = evg_datetime_attrib("finish_time")
    builds = evg_attrib("builds")
    tasks = evg_attrib("tasks")
    activated = evg_attrib("activated")
    alias = evg_attrib("alias")

    def __init__(self, json: Dict[str, Any], api: "EvergreenApi") -> None:
        """
        Create an instance of an evergreen patch.

        :param json: json representing patch.
        """
        super(Patch, self).__init__(json, api)
        self._variants_tasks: Optional[List[VariantsTasks]] = None
        self._variant_task_dict: Optional[Dict[str, Set[str]]] = None

    @property
    def github_patch_data(self) -> GithubPatchData:
        """
        Retrieve the github patch data for this patch.

        :return: Github Patch Data for this patch.
        """
        return GithubPatchData(self.json["github_patch_data"], self._api)

    @property
    def variants_tasks(self) -> List[VariantsTasks]:
        """
        Retrieve the variants tasks for this patch.

        :return: variants tasks for this patch.
        """
        if not self._variants_tasks:
            self._variants_tasks = [
                VariantsTasks(vt, self._api)
                for vt in self.json["variants_tasks"]
            ]
        return self._variants_tasks

    def task_list_for_variant(self, variant: str) -> Set[str]:
        """
        Retrieve the list of tasks for the given variant.

        :param variant: name of variant to search for.
        :return: list of tasks belonging to the specified variant.
        """
        if not self._variant_task_dict:
            self._variant_task_dict = {
                vt.name: vt.tasks
                for vt in self.variants_tasks
            }
        return self._variant_task_dict[variant]

    def get_version(self) -> "Version":
        """
        Get version for this patch.

        :return: Version object.
        """
        return self._api.version_by_id(self.version)

    def __str__(self) -> str:
        """Get a human readable string version of the patch."""
        return "{}: {}".format(self.patch_id, self.description)
Exemple #10
0
class Version(_BaseEvergreenObject):
    """Representation of a Evergreen Version."""

    version_id = evg_attrib('version_id')
    create_time = evg_datetime_attrib('create_time')
    start_time = evg_datetime_attrib('start_time')
    finish_time = evg_datetime_attrib('finish_time')
    revision = evg_attrib('revision')
    order = evg_attrib('order')
    project = evg_attrib('project')
    author = evg_attrib('author')
    author_email = evg_attrib('author_email')
    message = evg_attrib('message')
    status = evg_attrib('status')
    repo = evg_attrib('repo')
    branch = evg_attrib('branch')
    errors = evg_attrib('errors')
    warnings = evg_attrib('warnings')
    ignored = evg_attrib('ignored')

    def __init__(self, json, api):
        """
        Create an instance of an evergreen version.

        :param json: json representing version
        """
        super(Version, self).__init__(json, api)

        if 'build_variants_status' in self.json and self.json['build_variants_status']:
            self.build_variants_map = {
                bvs['build_variant']: bvs['build_id']
                for bvs in self.json['build_variants_status']
            }

    @property
    def build_variants_status(self):
        if 'build_variants_status' not in self.json or not self.json['build_variants_status']:
            return []
        build_variants_status = self.json['build_variants_status']
        return [BuildVariantStatus(bvs, self._api) for bvs in build_variants_status]

    def build_by_variant(self, build_variant):
        """
        Get a build object for the specified variant.

        :param build_variant: Build variant to get build for.
        :return: Build object for variant.
        """
        return self._api.build_by_id(self.build_variants_map[build_variant])

    def get_manifest(self):
        """
        Get the manifest for this version.

        :return: Manifest for this version.
        """
        return self._api.manifest(self.project, self.revision)

    def get_builds(self):
        """
        Get all the builds that are a part of this version.

        :return: List of build that are a part of this version.
        """
        return self._api.builds_by_version(self.version_id)

    def is_patch(self):
        """
        Determine if this version from a patch build.

        :return: True if this version is a patch build.
        """
        return not self.version_id.startswith(self.project.replace('-', '_'))

    def is_completed(self):
        """
        Determine if this version has completed running tasks.

        :return: True if version has completed.
        """
        return self.status in COMPLETED_STATES

    def get_patch(self):
        """
        Get the patch information for this version.

        :return: Patch for this version.
        """
        if self.is_patch():
            return self._api.patch_by_id(self.version_id)
        return None

    def get_metrics(self, task_filter_fn=None):
        """
        Calculate the metrics for this version.

        Metrics are only available on versions that have finished running.

        :param task_filter_fn: function to filter tasks included for metrics, should accept a task
                               argument.
        :return: Metrics for this version.
        """
        if self.status != EVG_VERSION_STATUS_CREATED:
            return VersionMetrics(self).calculate(task_filter_fn)
        return None
Exemple #11
0
class Task(_BaseEvergreenObject):
    """Representation of an Evergreen task."""

    activated = evg_attrib('activated')
    activated_by = evg_attrib('activated_by')
    build_id = evg_attrib('build_id')
    build_variant = evg_attrib('build_variant')
    create_time = evg_datetime_attrib('create_time')
    depends_on = evg_attrib('depends_on')
    dispatch_time = evg_datetime_attrib('dispatch_time')
    display_name = evg_attrib('display_name')
    display_only = evg_attrib('display_only')
    distro_id = evg_attrib('distro_id')
    est_wait_to_start_ms = evg_attrib('est_wait_to_start_ms')
    estimated_cost = evg_attrib('estimated_cost')
    execution = evg_attrib('execution')
    expected_duration_ms = evg_attrib('expected_duration_ms')
    finish_time = evg_datetime_attrib('finish_time')
    generate_task = evg_attrib('generate_task')
    generated_by = evg_attrib('generated_by')
    host_id = evg_attrib('host_id')
    ingest_time = evg_datetime_attrib('ingest_time')
    mainline = evg_attrib('mainline')
    order = evg_attrib('order')
    project_id = evg_attrib('project_id')
    priority = evg_attrib('priority')
    restarts = evg_attrib('restarts')
    revision = evg_attrib('revision')
    scheduled_time = evg_datetime_attrib('scheduled_time')
    start_time = evg_datetime_attrib('start_time')
    status = evg_attrib('status')
    task_group = evg_attrib('task_group')
    task_group_max_hosts = evg_attrib('task_group_max_hosts')
    task_id = evg_attrib('task_id')
    time_taken_ms = evg_attrib('time_taken_ms')
    version_id = evg_attrib('version_id')

    def __init__(self, json, api):
        """
        Create an instance of an evergreen task.
        """
        super(Task, self).__init__(json, api)
        self._logs_map = None

    @property
    def artifacts(self):
        """
        Retrieve the artifacts for the given task.
        :return: List of artifacts.
        """
        return [
            Artifact(artifact, self._api)
            for artifact in self.json['artifacts']
        ]

    @property
    def log_map(self):
        """
        Retrieve a dict of all the logs.
        :return: Dictionary of the logs.
        """
        if not self._logs_map:
            self._logs_map = {
                key: value
                for key, value in self.json['logs'].items()
            }
        return self._logs_map

    def retrieve_log(self, log_name, raw=False):
        """
        Retrieve the contents of the specified log.

        :param log_name: Name of log to retrieve.
        :param raw: Retrieve raw version of log.
        :return: Contents of the specified log.
        """
        return self._api.retrieve_task_log(self.log_map[log_name], raw)

    @property
    def status_details(self):
        """
        Retrieve the status details for the given task.
        :return: Status details.
        """
        return StatusDetails(self.json['status_details'], self._api)

    def get_execution(self, execution):
        """
        Get the task info for the specified execution.

        :param execution: Index of execution.
        :return: Task info for specified execution.
        """
        if self.execution == execution:
            return self

        if 'previous_executions' in self.json:
            for task in self.json['previous_executions']:
                if task['execution'] == execution:
                    return Task(task, self._api)

        return None

    def wait_time(self):
        """
        Get the time taken until the task started running.

        :return: Time taken until task started running.
        """
        if self.start_time and self.ingest_time:
            return self.start_time - self.ingest_time
        return None

    def wait_time_once_unblocked(self):
        """
        Get the time taken until the task started running
        once it is unblocked by task dependencies.

        :return: Time taken until task started running.
        """
        if self.start_time and self.scheduled_time:
            return self.start_time - self.scheduled_time
        return None

    def is_success(self):
        """
        Whether task was successful.

        :return: True if task was successful.
        """
        return self.status == EVG_SUCCESS_STATUS

    def is_undispatched(self):
        """
        Whether the task was undispatched.

        :return: True is task was undispatched.
        """
        return self.status == EVG_UNDISPATCHED_STATUS

    def is_system_failure(self):
        """
        Whether task resulted in a system failure.

        :return: True if task was a system failure.
        """
        if not self.is_success(
        ) and self.status_details and self.status_details.type:
            return self.status_details.type == EVG_SYSTEM_FAILURE_STATUS
        return False

    def is_timeout(self):
        """
        Whether task results in a timeout.

        :return: True if task was a timeout.
        """
        if not self.is_success(
        ) and self.status_details and self.status_details.timed_out:
            return self.status_details.timed_out
        return False

    def is_active(self):
        """
        Determine if the given task is active.

        :return: True if task is active.
        """
        return self.scheduled_time and not self.finish_time
Exemple #12
0
class Version(_BaseEvergreenObject):
    """Representation of an Evergreen Version."""

    version_id = evg_attrib("version_id")
    create_time = evg_datetime_attrib("create_time")
    start_time = evg_datetime_attrib("start_time")
    finish_time = evg_datetime_attrib("finish_time")
    revision = evg_attrib("revision")
    order = evg_attrib("order")
    project = evg_attrib("project")
    author = evg_attrib("author")
    author_email = evg_attrib("author_email")
    message = evg_attrib("message")
    status = evg_attrib("status")
    repo = evg_attrib("repo")
    branch = evg_attrib("branch")
    errors = evg_attrib("errors")
    warnings = evg_attrib("warnings")
    ignored = evg_attrib("ignored")

    def __init__(self, json: Dict[str, Any], api: "EvergreenApi") -> None:
        """
        Create an instance of an evergreen version.

        :param json: json representing version
        """
        super(Version, self).__init__(json, api)

        if "build_variants_status" in self.json and self.json[
                "build_variants_status"]:
            self.build_variants_map = {
                bvs["build_variant"]: bvs["build_id"]
                for bvs in self.json["build_variants_status"]
            }

    @property
    def build_variants_status(self) -> List[BuildVariantStatus]:
        """Get a list of build variant statuses."""
        if "build_variants_status" not in self.json or not self.json[
                "build_variants_status"]:
            return []
        build_variants_status = self.json["build_variants_status"]
        return [
            BuildVariantStatus(bvs, self._api) for bvs in build_variants_status
        ]

    @property
    def requester(self) -> Requester:
        """Get the requester of this version."""
        return Requester[self.json.get("requester", "UNKNOWN").upper()]

    def build_by_variant(self, build_variant: str) -> "Build":
        """
        Get a build object for the specified variant.

        :param build_variant: Build variant to get build for.
        :return: Build object for variant.
        """
        return self._api.build_by_id(self.build_variants_map[build_variant])

    def get_manifest(self) -> "Manifest":
        """
        Get the manifest for this version.

        :return: Manifest for this version.
        """
        return self._api.manifest(self.project, self.revision)

    def get_modules(self) -> Optional[Dict[str, ManifestModule]]:
        """
        Get the modules for this version.

        :return: ManifestModules for this version.
        """
        return self.get_manifest().modules

    def get_builds(self) -> List["Build"]:
        """
        Get all the builds that are a part of this version.

        :return: List of build that are a part of this version.
        """
        return self._api.builds_by_version(self.version_id)

    def is_patch(self) -> bool:
        """
        Determine if this version from a patch build.

        :return: True if this version is a patch build.
        """
        if self.requester and self.requester != Requester.UNKNOWN:
            return self.requester in PATCH_REQUESTERS
        return not self.version_id.startswith(self.project.replace("-", "_"))

    def is_completed(self) -> bool:
        """
        Determine if this version has completed running tasks.

        :return: True if version has completed.
        """
        return self.status in COMPLETED_STATES

    def get_patch(self) -> Optional["Patch"]:
        """
        Get the patch information for this version.

        :return: Patch for this version.
        """
        if self.is_patch():
            return self._api.patch_by_id(self.version_id)
        return None

    def get_metrics(
            self,
            task_filter_fn: Optional[Callable] = None
    ) -> Optional[VersionMetrics]:
        """
        Calculate the metrics for this version.

        Metrics are only available on versions that have finished running.

        :param task_filter_fn: function to filter tasks included for metrics, should accept a task
                               argument.
        :return: Metrics for this version.
        """
        if self.status != EVG_VERSION_STATUS_CREATED:
            return VersionMetrics(self).calculate(task_filter_fn)
        return None

    def __repr__(self) -> str:
        """
        Get the string representation of Version for debugging purposes.

        :return: String representation of Version.
        """
        return "Version({id})".format(id=self.version_id)
Exemple #13
0
class Build(_BaseEvergreenObject):
    """Representation of an Evergreen build."""

    id = evg_attrib('_id')
    project_id = evg_attrib('project_id')
    create_time = evg_datetime_attrib('create_time')
    start_time = evg_datetime_attrib('start_time')
    finish_time = evg_datetime_attrib('finish_time')
    version = evg_attrib('version')
    branch = evg_attrib('branch')
    git_hash = evg_attrib('git_hash')
    build_variant = evg_attrib('build_variant')
    status = evg_attrib('status')
    activated = evg_attrib('activated')
    activated_by = evg_attrib('activated_by')
    activated_time = evg_datetime_attrib('activated_time')
    order = evg_attrib('order')
    tasks = evg_attrib('tasks')
    time_taken_ms = evg_attrib('time_taken_ms')
    display_name = evg_attrib('display_name')
    predicted_makespan_ms = evg_attrib('predicted_makespan_ms')
    actual_makespan_ms = evg_attrib('actual_makespan_ms')
    origin = evg_attrib('origin')

    def __init__(self, json, api):
        """
        Create an instance of an evergreen task.
        """
        super(Build, self).__init__(json, api)

    @property
    def status_counts(self):
        return StatusCounts(self.json['status_counts'], self._api)

    def get_tasks(self, fetch_all_executions=False):
        """
        Get all tasks for this build.

        :param fetch_all_executions:  fetch all executions for tasks.
        :return: List of all tasks.
        """
        return self._api.tasks_by_build(self.id, fetch_all_executions)

    def is_completed(self):
        """
        Determine if this build has completed running tasks.

        :return: True if build has completed running tasks.
        """
        return self.status in COMPLETED_STATES

    def get_metrics(self, task_filter_fn=None):
        """
        Get metrics for the build.

        Metrics are only available on build that have finished running..

        :param task_filter_fn: function to filter tasks included for metrics, should accept a task
                               argument.
        :return: Metrics for the build.
        """
        if self.status != EVG_BUILD_STATUS_CREATED:
            return BuildMetrics(self).calculate(task_filter_fn)
        return None
Exemple #14
0
class Build(_BaseEvergreenObject):
    """Representation of an Evergreen build."""

    id = evg_attrib("_id")
    project_id = evg_attrib("project_id")
    create_time = evg_datetime_attrib("create_time")
    start_time = evg_datetime_attrib("start_time")
    finish_time = evg_datetime_attrib("finish_time")
    version = evg_attrib("version")
    branch = evg_attrib("branch")
    git_hash = evg_attrib("git_hash")
    build_variant = evg_attrib("build_variant")
    status = evg_attrib("status")
    activated = evg_attrib("activated")
    activated_by = evg_attrib("activated_by")
    activated_time = evg_datetime_attrib("activated_time")
    order = evg_attrib("order")
    tasks = evg_attrib("tasks")
    time_taken_ms = evg_attrib("time_taken_ms")
    display_name = evg_attrib("display_name")
    predicted_makespan_ms = evg_attrib("predicted_makespan_ms")
    actual_makespan_ms = evg_attrib("actual_makespan_ms")
    origin = evg_attrib("origin")

    def __init__(self, json: Dict[str, Any], api: "EvergreenApi") -> None:
        """
        Create an instance of an evergreen task.

        :param json: Json of build object.
        :param api: Evergreen API.
        """
        super(Build, self).__init__(json, api)

    @property
    def status_counts(self) -> StatusCounts:
        """Get the status counts of the build."""
        return StatusCounts(self.json["status_counts"], self._api)

    def get_tasks(self, fetch_all_executions: bool = False) -> List["Task"]:
        """
        Get all tasks for this build.

        :param fetch_all_executions:  fetch all executions for tasks.
        :return: List of all tasks.
        """
        return self._api.tasks_by_build(self.id, fetch_all_executions)

    def is_completed(self) -> bool:
        """
        Determine if this build has completed running tasks.

        :return: True if build has completed running tasks.
        """
        return self.status in COMPLETED_STATES

    def get_metrics(self,
                    task_filter_fn: Callable = None) -> Optional[BuildMetrics]:
        """
        Get metrics for the build.

        Metrics are only available on build that have finished running..

        :param task_filter_fn: function to filter tasks included for metrics, should accept a task
                               argument.
        :return: Metrics for the build.
        """
        if self.status != EVG_BUILD_STATUS_CREATED:
            return BuildMetrics(self).calculate(task_filter_fn)
        return None

    def get_version(self) -> "Version":
        """
        Get the version this build is a part of.

        :return: Version that this build is a part of.
        """
        return self._api.version_by_id(self.version)

    def __repr__(self) -> str:
        """
        Get a string representation of Task for debugging purposes.

        :return: String representation of Task.
        """
        return "Build({id})".format(id=self.id)