Add RST version of ganeti-rapi man page
[ganeti-local] / qa / qa_rapi.py
index 10c4033..a1b371e 100644 (file)
@@ -1,6 +1,6 @@
 #
 
-# Copyright (C) 2007, 2008 Google Inc.
+# Copyright (C) 2007, 2008, 2009, 2010 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -116,6 +116,7 @@ def _DoTests(uris):
   for uri, verify, method, body in uris:
     assert uri.startswith("/")
 
+    print "%s %s" % (method, uri)
     data = _rapi_client._SendRequest(method, uri, None, body)
 
     if verify is not None:
@@ -124,7 +125,7 @@ def _DoTests(uris):
       else:
         AssertEqual(data, verify)
 
-      results.append(data)
+    results.append(data)
 
   return results
 
@@ -177,6 +178,24 @@ def TestEmptyCluster():
     ("/2/os", None, 'GET', None),
     ])
 
+  # Test HTTP Not Found
+  for method in ["GET", "PUT", "POST", "DELETE"]:
+    try:
+      _DoTests([("/99/resource/not/here/99", None, method, None)])
+    except rapi.client.GanetiApiError, err:
+      AssertEqual(err.code, 404)
+    else:
+      raise qa_error.Error("Non-existent resource didn't return HTTP 404")
+
+  # Test HTTP Not Implemented
+  for method in ["PUT", "POST", "DELETE"]:
+    try:
+      _DoTests([("/version", None, method, None)])
+    except rapi.client.GanetiApiError, err:
+      AssertEqual(err.code, 501)
+    else:
+      raise qa_error.Error("Non-implemented method didn't fail")
+
 
 def TestInstance(instance):
   """Testing getting instance(s) info via remote API.
@@ -259,10 +278,25 @@ def TestTags(kind, name, tags):
   def _VerifyTags(data):
     AssertEqual(sorted(tags), sorted(data))
 
+  query = "&".join("tag=%s" % i for i in tags)
+
+  # Add tags
+  (job_id, ) = _DoTests([
+    ("%s?%s" % (uri, query), _VerifyReturnsJob, "PUT", None),
+    ])
+  _WaitForRapiJob(job_id)
+
+  # Retrieve tags
   _DoTests([
     (uri, _VerifyTags, 'GET', None),
     ])
 
+  # Remove tags
+  (job_id, ) = _DoTests([
+    ("%s?%s" % (uri, query), _VerifyReturnsJob, "DELETE", None),
+    ])
+  _WaitForRapiJob(job_id)
+
 
 def _WaitForRapiJob(job_id):
   """Waits for a job to finish.
@@ -358,7 +392,30 @@ def TestRapiInstanceRename(instance, rename_target):
     _WaitForRapiJob(_rapi_client.RenameInstance(name1, name2))
 
 
-def TestInterClusterInstanceMove(src_instance, dest_instance, pnode, snode):
+def TestRapiInstanceModify(instance):
+  """Test modifying instance via RAPI"""
+  def _ModifyInstance(**kwargs):
+    _WaitForRapiJob(_rapi_client.ModifyInstance(instance["name"], **kwargs))
+
+  _ModifyInstance(hvparams={
+    constants.HV_KERNEL_ARGS: "single",
+    })
+
+  _ModifyInstance(beparams={
+    constants.BE_VCPUS: 3,
+    })
+
+  _ModifyInstance(beparams={
+    constants.BE_VCPUS: constants.VALUE_DEFAULT,
+    })
+
+  _ModifyInstance(hvparams={
+    constants.HV_KERNEL_ARGS: constants.VALUE_DEFAULT,
+    })
+
+
+def TestInterClusterInstanceMove(src_instance, dest_instance,
+                                 pnode, snode, tnode):
   """Test tools/move-instance"""
   master = qa_config.GetMasterNode()
 
@@ -367,21 +424,32 @@ def TestInterClusterInstanceMove(src_instance, dest_instance, pnode, snode):
   rapi_pw_file.flush()
 
   # TODO: Run some instance tests before moving back
-  for srcname, destname in [(src_instance["name"], dest_instance["name"]),
-                            (dest_instance["name"], src_instance["name"])]:
+
+  if snode is None:
+    # instance is not redundant, but we still need to pass a node
+    # (which will be ignored)
+    fsec = tnode
+  else:
+    fsec = snode
+  # note: pnode:snode are the *current* nodes, so we move it first to
+  # tnode:pnode, then back to pnode:snode
+  for si, di, pn, sn in [(src_instance["name"], dest_instance["name"],
+                          tnode["primary"], pnode["primary"]),
+                         (dest_instance["name"], src_instance["name"],
+                          pnode["primary"], fsec["primary"])]:
     cmd = [
       "../tools/move-instance",
       "--verbose",
       "--src-ca-file=%s" % _rapi_ca.name,
       "--src-username=%s" % _rapi_username,
       "--src-password-file=%s" % rapi_pw_file.name,
-      "--dest-instance-name=%s" % destname,
-      "--dest-primary-node=%s" % pnode["primary"],
-      "--dest-secondary-node=%s" % snode["primary"],
-
+      "--dest-instance-name=%s" % di,
+      "--dest-primary-node=%s" % pn,
+      "--dest-secondary-node=%s" % sn,
+      "--net=0:mac=%s" % constants.VALUE_GENERATE,
       master["primary"],
       master["primary"],
-      srcname,
+      si,
       ]
 
     AssertEqual(StartLocalCommand(cmd).wait(), 0)