Ejemplo n.º 1
0
def GenericOpCodes(opts, args):
  """Send any opcode to the master.

  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the path of
      the file with the opcode definition
  @rtype: int
  @return: the desired exit code

  """
  cl = cli.GetClient()
  jex = cli.JobExecutor(cl=cl, verbose=opts.verbose, opts=opts)

  job_cnt = 0
  op_cnt = 0
  if opts.timing_stats:
    ToStdout("Loading...")
  for job_idx in range(opts.rep_job):
    for fname in args:
      # pylint: disable=W0142
      op_data = simplejson.loads(utils.ReadFile(fname))
      op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data]
      op_list = op_list * opts.rep_op
      jex.QueueJob("file %s/%d" % (fname, job_idx), *op_list)
      op_cnt += len(op_list)
      job_cnt += 1

  if opts.timing_stats:
    t1 = time.time()
    ToStdout("Submitting...")

  jex.SubmitPending(each=opts.each)

  if opts.timing_stats:
    t2 = time.time()
    ToStdout("Executing...")

  jex.GetResults()
  if opts.timing_stats:
    t3 = time.time()
    ToStdout("C:op     %4d" % op_cnt)
    ToStdout("C:job    %4d" % job_cnt)
    ToStdout("T:submit %4.4f" % (t2 - t1))
    ToStdout("T:exec   %4.4f" % (t3 - t2))
    ToStdout("T:total  %4.4f" % (t3 - t1))
  return 0
Ejemplo n.º 2
0
    def ExecJobSet(self, jobs):
        """Execute a set of jobs and return once all are done.

    The method will return the list of results, if all jobs are
    successful. Otherwise, OpExecError will be raised from within
    cli.py.

    """
        self.ClearFeedbackBuf()
        jex = cli.JobExecutor(cl=self.cl, feedback_fn=self.Feedback)
        for ops, name, _ in jobs:
            jex.QueueJob(name, *ops)  # pylint: disable=W0142
        try:
            results = jex.GetResults()
        except Exception, err:  # pylint: disable=W0703
            Log("Jobs failed: %s", err)
            raise BurninFailure()
Ejemplo n.º 3
0
def GetResult(cl, opts, result):
    """Waits for jobs and returns whether they have succeeded

  Some OpCodes return of list of jobs.  This function can be used
  after issueing a given OpCode to look at the OpCode's result and, if
  it is of type L{ht.TJobIdListOnly}, then it will wait for the jobs
  to complete, otherwise just return L{constants.EXIT_SUCCESS}.

  @type cl: L{ganeti.luxi.Client}
  @param cl: client that was used to submit the OpCode, which will
             also be used to poll the jobs

  @param opts: CLI options

  @param result: result of the opcode which might contain job
         information, in which case the jobs will be polled, or simply
         the result of the opcode

  @rtype: int
  @return: L{constants.EXIT_SUCCESS} if all jobs completed
           successfully, L{constants.EXIT_FAILURE} otherwise

  """
    if not ht.TJobIdListOnly(result):
        return constants.EXIT_SUCCESS

    jex = cli.JobExecutor(cl=cl, opts=opts)

    for (status, job_id) in result[constants.JOB_IDS_KEY]:
        jex.AddJobId(None, status, job_id)

    bad_jobs = [
        job_result for success, job_result in jex.GetResults() if not success
    ]

    if len(bad_jobs) > 0:
        for job in bad_jobs:
            cli.ToStdout("Job failed, result is '%s'.", job)
        cli.ToStdout("%s job(s) failed.", bad_jobs)
        return constants.EXIT_FAILURE
    else:
        return constants.EXIT_SUCCESS