Revision bdfd7802

b/lib/ht.py
307 307
  TAnd(TFloat, WithDesc("EqualGreaterZero")(lambda v: v >= 0.0))
308 308

  
309 309
#: Job ID
310
TJobId = TOr(TPositiveInt,
311
             TRegex(re.compile("^%s$" % constants.JOB_ID_TEMPLATE)))
310
TJobId = WithDesc("JobId")(TOr(TPositiveInt,
311
                               TRegex(re.compile("^%s$" %
312
                                                 constants.JOB_ID_TEMPLATE))))
312 313

  
313 314
#: Number
314 315
TNumber = TOr(TInt, TFloat)
b/lib/opcodes.py
429 429
TNoRelativeJobDependencies = _BuildJobDepCheck(False)
430 430

  
431 431
#: List of submission status and job ID as returned by C{SubmitManyJobs}
432
TJobIdList = ht.TListOf(ht.TItems([ht.TBool, ht.TOr(ht.TString, ht.TJobId)]))
432
TJobIdList = \
433
  ht.TListOf(ht.TAnd(ht.TIsLength(2),
434
                     ht.TItems([ht.TBool, ht.TOr(ht.TString, ht.TJobId)])))
433 435

  
434 436
#: Result containing only list of submitted jobs
435 437
TJobIdListOnly = ht.TStrictDict(True, True, {
b/test/ganeti.opcodes_unittest.py
306 306
      self.assertFalse(check_norelative(i))
307 307

  
308 308

  
309
class TestResultChecks(unittest.TestCase):
310
  def testJobIdList(self):
311
    for i in [[], [(False, "error")], [(False, "")],
312
              [(True, 123), (True, "999")]]:
313
      self.assertTrue(opcodes.TJobIdList(i))
314

  
315
    for i in ["", [("x", 1)], [[], []], [[False, "", None], [True, 123]]]:
316
      self.assertFalse(opcodes.TJobIdList(i))
317

  
318
  def testJobIdListOnly(self):
319
    self.assertTrue(opcodes.TJobIdListOnly({
320
      constants.JOB_IDS_KEY: [],
321
      }))
322
    self.assertTrue(opcodes.TJobIdListOnly({
323
      constants.JOB_IDS_KEY: [(True, "9282")],
324
      }))
325

  
326
    self.assertFalse(opcodes.TJobIdListOnly({
327
      "x": None,
328
      }))
329
    self.assertFalse(opcodes.TJobIdListOnly({
330
      constants.JOB_IDS_KEY: [],
331
      "x": None,
332
      }))
333
    self.assertFalse(opcodes.TJobIdListOnly({
334
      constants.JOB_IDS_KEY: [("foo", "bar")],
335
      }))
336
    self.assertFalse(opcodes.TJobIdListOnly({
337
      constants.JOB_IDS_KEY: [("one", "two", "three")],
338
      }))
339

  
340

  
309 341
if __name__ == "__main__":
310 342
  testutils.GanetiTestProgram()

Also available in: Unified diff