Revision 8cb70e56 qa/qa_rapi.py

b/qa/qa_rapi.py
288 288
  _DoTests([
289 289
    (uri, _VerifyTags, 'GET', None),
290 290
    ])
291

  
292

  
293
def _WaitForRapiJob(job_id):
294
  """Waits for a job to finish.
295

  
296
  """
297
  master = qa_config.GetMasterNode()
298

  
299
  def _VerifyJob(data):
300
    AssertEqual(data["id"], job_id)
301
    for field in JOB_FIELDS:
302
      AssertIn(field, data)
303

  
304
  _DoTests([
305
    ("/2/jobs/%s" % job_id, _VerifyJob, "GET", None),
306
    ])
307

  
308
  # FIXME: Use "gnt-job watch" until RAPI supports waiting for job
309
  cmd = ["gnt-job", "watch", str(job_id)]
310
  AssertEqual(StartSSH(master["primary"],
311
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
312

  
313

  
314
def TestRapiInstanceAdd(node):
315
  """Test adding a new instance via RAPI"""
316
  instance = qa_config.AcquireInstance()
317
  try:
318
    body = {
319
      "name": instance["name"],
320
      "os": qa_config.get("os"),
321
      "disk_template": constants.DT_PLAIN,
322
      "pnode": node["primary"],
323
      "memory": utils.ParseUnit(qa_config.get("mem")),
324
      "disks": [utils.ParseUnit(size) for size in qa_config.get("disk")],
325
      }
326

  
327
    (job_id, ) = _DoTests([
328
      ("/2/instances", _VerifyReturnsJob, "POST", body),
329
      ])
330

  
331
    _WaitForRapiJob(job_id)
332

  
333
    return instance
334
  except:
335
    qa_config.ReleaseInstance(instance)
336
    raise
337

  
338

  
339
def TestRapiInstanceRemove(instance):
340
  """Test removing instance via RAPI"""
341
  (job_id, ) = _DoTests([
342
    ("/2/instances/%s" % instance["name"], _VerifyReturnsJob, "DELETE", None),
343
    ])
344

  
345
  _WaitForRapiJob(job_id)
346

  
347
  qa_config.ReleaseInstance(instance)

Also available in: Unified diff