"""
-from ganeti.utils import retry
-from ganeti import constants
-from ganeti import query
-
import functools
import re
+from ganeti.utils import retry
+from ganeti import constants
+from ganeti import query
import qa_config
import qa_error
+import qa_job_utils
import qa_utils
-
from qa_utils import AssertCommand, GetCommandOutput
qa_utils.GenericQueryFieldsTest("gnt-job", query.JOB_FIELDS.keys())
-def _GetJobStatuses():
- """ Invokes gnt-job list and extracts an id to status dictionary.
-
- @rtype: dict of string to string
- @return: A dictionary mapping job ids to matching statuses
-
- """
- master = qa_config.GetMasterNode()
- list_output = GetCommandOutput(
- master.primary, "gnt-job list --no-headers --output=id,status"
- )
- return dict(map(lambda s: s.split(), list_output.splitlines()))
-
-
def _GetJobStatus(job_id):
""" Retrieves the status of a job.
@return: The job status, or None if not present.
"""
- return _GetJobStatuses().get(job_id, None)
+ return qa_job_utils.GetJobStatuses([job_id]).get(job_id, None)
def _RetryingFetchJobStatus(retry_status, job_id):
return int(possible_job_ids[0])
+def GetJobStatuses(job_ids=None):
+ """ Invokes gnt-job list and extracts an id to status dictionary.
+
+ @type job_ids: list
+ @param job_ids: list of job ids to query the status for; if C{None}, the
+ status of all current jobs is returned
+ @rtype: dict of string to string
+ @return: A dictionary mapping job ids to matching statuses
+
+ """
+ cmd = ["gnt-job", "list", "--no-headers", "--output=id,status"]
+ if job_ids is not None:
+ cmd.extend(map(str, job_ids))
+
+ list_output = GetOutputFromMaster(cmd)
+ return dict(map(lambda s: s.split(), list_output.splitlines()))
+
+
def _RetrieveTerminationInfo(job_id):
""" Retrieves the termination info from a job caused by gnt-debug delay.
def _FetchJobStatuses(self):
"""Retrieves status information of the given jobs.
- @rtype: dict of string to list of L{_JobEntry)
-
"""
- cmd = (["gnt-job", "list", "--no-headers", "-o", "id,status"])
- cmd.extend(map(str, self._GetJobIds()))
- job_statuses = [line.split() for line in
- qa_job_utils.GetOutputFromMaster(cmd).splitlines()]
+ job_statuses = qa_job_utils.GetJobStatuses(self._GetJobIds())
+
new_statuses = {}
- for job_id, status in job_statuses:
+ for job_id, status in job_statuses.items():
new_statuses.setdefault(status, []).append(self._jobs[int(job_id)])
self._jobs_per_status = new_statuses