Commit 3b53dd6e authored by Niklas Hambuechen's avatar Niklas Hambuechen

QA: Move `GetJobStatus`/`RetryingWhileJobStatus` to utils

We would like to use them from other QAs involving jobs.
Signed-off-by: default avatarNiklas Hambuechen <niklash@google.com>
Reviewed-by: default avatarHrvoje Ribicic <riba@google.com>
parent 2538bb61
......@@ -56,37 +56,6 @@ def TestJobListFields():
qa_utils.GenericQueryFieldsTest("gnt-job", query.JOB_FIELDS.keys())
def _GetJobStatus(job_id):
""" Retrieves the status of a job.
@type job_id: string
@param job_id: The job id, represented as a string.
@rtype: string or None
@return: The job status, or None if not present.
"""
return qa_job_utils.GetJobStatuses([job_id]).get(job_id, None)
def _RetryingFetchJobStatus(retry_status, job_id):
""" Used with C{retry.Retry}, waits for a status other than the one given.
@type retry_status: string
@param retry_status: The old job status, expected to change.
@type job_id: string
@param job_id: The job id, represented as a string.
@rtype: string or None
@return: The new job status, or None if none could be retrieved.
"""
status = _GetJobStatus(job_id)
if status == retry_status:
raise retry.RetryAgain()
return status
def TestJobCancellation():
"""gnt-job cancel"""
# The delay used for the first command should be large enough for the next
......@@ -117,12 +86,12 @@ def TestJobCancellation():
AssertCommand(["gnt-job", "watch", job_id], fail=True)
# Then check for job cancellation
job_status = _GetJobStatus(job_id)
job_status = qa_job_utils.GetJobStatus(job_id)
if job_status != constants.JOB_STATUS_CANCELED:
# Try and see if the job is being cancelled, and wait until the status
# changes or we hit a timeout
if job_status == constants.JOB_STATUS_CANCELING:
retry_fn = functools.partial(_RetryingFetchJobStatus,
retry_fn = functools.partial(qa_job_utils.RetryingWhileJobStatus,
constants.JOB_STATUS_CANCELING, job_id)
try:
# The multiplier to use is arbitrary, setting it higher could prevent
......
......@@ -396,3 +396,34 @@ def RunWithLocks(fn, locks, timeout, block, *args, **kwargs):
# Revive the watcher
AssertCommand(["gnt-cluster", "watcher", "continue"])
def GetJobStatus(job_id):
""" Retrieves the status of a job.
@type job_id: string
@param job_id: The job id, represented as a string.
@rtype: string or None
@return: The job status, or None if not present.
"""
return GetJobStatuses([job_id]).get(job_id, None)
def RetryingWhileJobStatus(retry_status, job_id):
""" Used with C{retry.Retry}, waits for a status other than the one given.
@type retry_status: string
@param retry_status: The old job status, expected to change.
@type job_id: string
@param job_id: The job id, represented as a string.
@rtype: string or None
@return: The new job status, or None if none could be retrieved.
"""
status = GetJobStatus(job_id)
if status == retry_status:
raise retry.RetryAgain()
return status
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment