Commit 3f8e1896 authored by Thomas Thrainer's avatar Thomas Thrainer

Extract GetJobStatuses and use an unified version

Unify two very similar functions which query the ganeti cluster for job
statuses during QA.
Signed-off-by: default avatarThomas Thrainer <thomasth@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 552633e1
......@@ -23,17 +23,16 @@
"""
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
......@@ -48,20 +47,6 @@ def TestJobListFields():
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.
......@@ -72,7 +57,7 @@ def _GetJobStatus(job_id):
@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):
......
......@@ -82,6 +82,24 @@ def ExecuteJobProducingCommand(cmd):
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.
......
......@@ -96,15 +96,11 @@ class _JobQueueDriver(object):
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
......
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