From a5b9d725d14dc5df8c6f1848c4eec6f7b18a63fe Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 5 Feb 2009 09:47:09 +0000
Subject: [PATCH] Revive RAPI QA tests for 2.0-style RAPI
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch fixes the RAPI QA tests to work with today's RAPI code and
also does some other minor improvements:
  - QA: only create the cluster if so configured (β€˜create-cluster’ key),
    this allows running parts of the QA suite against existing clusters
  - export the β€œhvparams” for instances in RAPI

Reviewed-by: imsnah
---
 lib/rapi/rlib2.py |  2 +-
 qa/ganeti-qa.py   |  8 +++++---
 qa/qa-sample.json |  1 +
 qa/qa_rapi.py     | 45 +++++++++++++++++++++++----------------------
 4 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py
index 35aee518d..91fc0202c 100644
--- a/lib/rapi/rlib2.py
+++ b/lib/rapi/rlib2.py
@@ -35,7 +35,7 @@ I_FIELDS = ["name", "admin_state", "os",
             "disk_template",
             "nic.ips", "nic.macs", "nic.bridges",
             "disk.sizes",
-            "beparams",
+            "beparams", "hvparams",
             "oper_state", "oper_ram", "status",
             "tags"]
 
diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py
index 1bd4d5cdb..4c2a2fcff 100755
--- a/qa/ganeti-qa.py
+++ b/qa/ganeti-qa.py
@@ -74,8 +74,9 @@ def SetupCluster():
   """Initializes the cluster.
 
   """
-  RunTest(qa_cluster.TestClusterInit)
-  RunTest(qa_node.TestNodeAddAll)
+  if qa_config.TestEnabled('create-cluster'):
+    RunTest(qa_cluster.TestClusterInit)
+    RunTest(qa_node.TestNodeAddAll)
   if qa_config.TestEnabled('node-info'):
     RunTest(qa_node.TestNodeInfo)
 
@@ -308,7 +309,8 @@ def main():
   finally:
     qa_config.ReleaseNode(pnode)
 
-  RunTest(qa_node.TestNodeRemoveAll)
+  if qa_config.TestEnabled('create-cluster'):
+    RunTest(qa_node.TestNodeRemoveAll)
 
   if qa_config.TestEnabled('cluster-destroy'):
     RunTest(qa_cluster.TestClusterDestroy)
diff --git a/qa/qa-sample.json b/qa/qa-sample.json
index 7c5027f11..3c3a6641c 100644
--- a/qa/qa-sample.json
+++ b/qa/qa-sample.json
@@ -38,6 +38,7 @@
     "tags": true,
     "rapi": true,
 
+    "create-cluster": true,
     "cluster-verify": true,
     "cluster-info": true,
     "cluster-burnin": true,
diff --git a/qa/qa_rapi.py b/qa/qa_rapi.py
index f2f68f957..f4db02112 100644
--- a/qa/qa_rapi.py
+++ b/qa/qa_rapi.py
@@ -41,10 +41,11 @@ NoProxyOpener = urllib2.build_opener(urllib2.ProxyHandler({}))
 
 
 INSTANCE_FIELDS = ("name", "os", "pnode", "snodes",
-                   "admin_state", "admin_ram",
-                   "disk_template", "ip", "mac", "bridge",
-                   "sda_size", "sdb_size", "vcpus",
-                   "oper_state", "status", "tags")
+                   "admin_state",
+                   "disk_template", "disk.sizes",
+                   "nic.ips", "nic.macs", "nic.bridges",
+                   "beparams", "hvparams",
+                   "oper_state", "oper_ram", "status", "tags")
 
 NODE_FIELDS = ("name", "dtotal", "dfree",
                "mtotal", "mnode", "mfree",
@@ -119,8 +120,8 @@ def TestEmptyCluster():
 
   def _VerifyNodes(data):
     master_entry = {
-      "name": master_name,
-      "uri": "/nodes/%s" % master_name,
+      "id": master_name,
+      "uri": "/2/nodes/%s" % master_name,
       }
     AssertIn(master_entry, data)
 
@@ -131,13 +132,13 @@ def TestEmptyCluster():
 
   _DoTests([
     ("/", None),
-    ("/info", _VerifyInfo),
-    ("/tags", None),
-    ("/nodes", _VerifyNodes),
-    ("/nodes?bulk=1", _VerifyNodesBulk),
-    ("/instances", []),
-    ("/instances?bulk=1", []),
-    ("/os", None),
+    ("/2/info", _VerifyInfo),
+    ("/2/tags", None),
+    ("/2/nodes", _VerifyNodes),
+    ("/2/nodes?bulk=1", _VerifyNodesBulk),
+    ("/2/instances", []),
+    ("/2/instances?bulk=1", []),
+    ("/2/os", None),
     ])
 
 
@@ -159,9 +160,9 @@ def TestInstance(instance):
       _VerifyInstance(instance_data)
 
   _DoTests([
-    ("/instances/%s" % instance["name"], _VerifyInstance),
-    ("/instances", _VerifyInstancesList),
-    ("/instances?bulk=1", _VerifyInstancesBulk),
+    ("/2/instances/%s" % instance["name"], _VerifyInstance),
+    ("/2/instances", _VerifyInstancesList),
+    ("/2/instances?bulk=1", _VerifyInstancesBulk),
     ])
 
 
@@ -183,9 +184,9 @@ def TestNode(node):
       _VerifyNode(node_data)
 
   _DoTests([
-    ("/nodes/%s" % node["primary"], _VerifyNode),
-    ("/nodes", _VerifyNodesList),
-    ("/nodes?bulk=1", _VerifyNodesBulk),
+    ("/2/nodes/%s" % node["primary"], _VerifyNode),
+    ("/2/nodes", _VerifyNodesList),
+    ("/2/nodes?bulk=1", _VerifyNodesBulk),
     ])
 
 
@@ -194,11 +195,11 @@ def TestTags(kind, name, tags):
 
   """
   if kind == constants.TAG_CLUSTER:
-    uri = "/tags"
+    uri = "/2/tags"
   elif kind == constants.TAG_NODE:
-    uri = "/nodes/%s/tags" % name
+    uri = "/2/nodes/%s/tags" % name
   elif kind == constants.TAG_INSTANCE:
-    uri = "/instances/%s/tags" % name
+    uri = "/2/instances/%s/tags" % name
   else:
     raise errors.ProgrammerError("Unknown tag kind")
 
-- 
GitLab