Revision e4f485cc

b/qa/qa_job.py
23 23

  
24 24
"""
25 25

  
26
from ganeti.utils import retry
26 27
from ganeti import constants
27 28
from ganeti import query
28 29

  
30
import functools
29 31
import re
30 32

  
31 33
import qa_config
......
60 62
  return dict(map(lambda s: s.split(), list_output.splitlines()))
61 63

  
62 64

  
65
def _GetJobStatus(job_id):
66
  """ Retrieves the status of a job.
67

  
68
  @type job_id: string
69
  @param job_id: The job id, represented as a string.
70
  @rtype: string or None
71

  
72
  @return: The job status, or None if not present.
73

  
74
  """
75
  return _GetJobStatuses().get(job_id, None)
76

  
77

  
78
def _RetryingFetchJobStatus(retry_status, job_id):
79
  """ Used with C{retry.Retry}, waits for a status other than the one given.
80

  
81
  @type retry_status: string
82
  @param retry_status: The old job status, expected to change.
83
  @type job_id: string
84
  @param job_id: The job id, represented as a string.
85

  
86
  @rtype: string or None
87
  @return: The new job status, or None if none could be retrieved.
88

  
89
  """
90
  status = _GetJobStatus(job_id)
91
  if status == retry_status:
92
    raise retry.RetryAgain()
93
  return status
94

  
95

  
63 96
def TestJobCancellation():
64 97
  """gnt-job cancel"""
65 98
  # The delay used for the first command should be large enough for the next
......
90 123
  AssertCommand(["gnt-job", "watch", job_id], fail=True)
91 124

  
92 125
  # Then check for job cancellation
93
  status_dict = _GetJobStatuses()
94
  if status_dict.get(job_id, None) != constants.JOB_STATUS_CANCELED:
95
    raise qa_error.Error("Job was not successfully cancelled!")
126
  job_status = _GetJobStatus(job_id)
127
  if job_status != constants.JOB_STATUS_CANCELED:
128
    # Try and see if the job is being cancelled, and wait until the status
129
    # changes or we hit a timeout
130
    if job_status == constants.JOB_STATUS_CANCELING:
131
      retry_fn = functools.partial(_RetryingFetchJobStatus,
132
                                   constants.JOB_STATUS_CANCELING, job_id)
133
      try:
134
        job_status = retry.Retry(retry_fn, 2.0, 2 * FIRST_COMMAND_DELAY)
135
      except retry.RetryTimeout:
136
        # The job status remains the same
137
        pass
138

  
139
    if job_status != constants.JOB_STATUS_CANCELED:
140
      raise qa_error.Error("Job was not successfully cancelled, status "
141
                           "found: %s" % job_status)

Also available in: Unified diff