Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.12.z] poll for task intended to fail #926

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,7 @@ def path(self, which=None):
return f'{super().path(which="base")}/{which}'
return super().path(which)

def poll(self, poll_rate=None, timeout=None):
def poll(self, poll_rate=None, timeout=None, must_succeed=True):
"""Return the status of a task or timeout.

There are several API calls that trigger asynchronous tasks, such as
Expand All @@ -3109,6 +3109,8 @@ def poll(self, poll_rate=None, timeout=None):
``nailgun.entity_mixins.TASK_POLL_RATE``.
:param timeout: Maximum number of seconds to wait until timing out.
Defaults to ``nailgun.entity_mixins.TASK_TIMEOUT``.
:param must_succeed: Raise error when task finishes with other then success
result.
:returns: Information about the asynchronous task.
:raises: ``nailgun.entity_mixins.TaskTimedOutError`` if the task
completes with any result other than "success".
Expand All @@ -3120,7 +3122,7 @@ def poll(self, poll_rate=None, timeout=None):
"""
# See nailgun.entity_mixins._poll_task for an explanation of why a
# private method is called.
return _poll_task(self.id, self._server_config, poll_rate, timeout)
return _poll_task(self.id, self._server_config, poll_rate, timeout, must_succeed)

def summary(self, synchronous=True, timeout=None, **kwargs):
"""Helper to view a summary of tasks.
Expand Down
4 changes: 2 additions & 2 deletions nailgun/entity_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, message, task_id):
self.task_id = task_id


def _poll_task(task_id, server_config, poll_rate=None, timeout=None):
def _poll_task(task_id, server_config, poll_rate=None, timeout=None, must_succeed=True):
"""Implement :meth:`nailgun.entities.ForemanTask.poll`.

See :meth:`nailgun.entities.ForemanTask.poll` for a full description of how
Expand Down Expand Up @@ -130,7 +130,7 @@ def raise_task_timeout(): # pragma: no cover
timer.cancel()

# Check for task success or failure.
if task_info['result'] != 'success':
if must_succeed and task_info['result'] != 'success':
raise TaskFailedError(
f"Task {task_id} did not succeed. Task information: {task_info}", task_id
)
Expand Down