Skip to content

Commit

Permalink
poll for task intended to fail (SatelliteQE#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
pondrejk committed May 24, 2023
1 parent a5a2031 commit b88218a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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

0 comments on commit b88218a

Please sign in to comment.