Commit 60452edf authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

cli.JobExecutor: Use counter for indexing jobs



If “SubmitPending” were mixed with calls to “QueueJob”, jobs in the
internal structures will get duplicate indices. With this change each
queued job is assigned a unique index, which will be used for sorting
the results.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent f8fa4175
......@@ -28,6 +28,7 @@ import os.path
import time
import logging
import errno
import itertools
from cStringIO import StringIO
from ganeti import utils
......@@ -2947,6 +2948,7 @@ class JobExecutor(object):
self.jobs = []
self.opts = opts
self.feedback_fn = feedback_fn
self._counter = itertools.count()
def QueueJob(self, name, *ops):
"""Record a job for later submit.
......@@ -2955,7 +2957,7 @@ class JobExecutor(object):
@param name: a description of the job, will be used in WaitJobSet
"""
SetGenericOpcodeOpts(ops, self.opts)
self.queue.append((name, ops))
self.queue.append((self._counter.next(), name, ops))
def SubmitPending(self, each=False):
"""Submit all pending jobs.
......@@ -2963,14 +2965,13 @@ class JobExecutor(object):
"""
if each:
results = []
for row in self.queue:
for (_, _, ops) in self.queue:
# SubmitJob will remove the success status, but raise an exception if
# the submission fails, so we'll notice that anyway.
results.append([True, self.cl.SubmitJob(row[1])])
results.append([True, self.cl.SubmitJob(ops)])
else:
results = self.cl.SubmitManyJobs([row[1] for row in self.queue])
for (idx, ((status, data), (name, _))) in enumerate(zip(results,
self.queue)):
results = self.cl.SubmitManyJobs([ops for (_, _, ops) in self.queue])
for ((status, data), (idx, name, _)) in zip(results, self.queue):
self.jobs.append((idx, status, data, name))
def _ChooseJob(self):
......
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