From 4b10fb65a69049a0d032dab7f5db130423a79b6e Mon Sep 17 00:00:00 2001
From: Adeodato Simo <dato@google.com>
Date: Thu, 9 Dec 2010 16:15:58 +0000
Subject: [PATCH] More QA tests for group operations

This adds QA tests for the SetGroupParams operation, both for CLI and
RAPI. Additionally, it adds tests for add/rename/remove groups via RAPI,
which had not been included in a previous patch series. Finally, it also
tests setting "alloc_policy" (and, for the CLI, "ndparams") at group
creation time.

Signed-off-by: Adeodato Simo <dato@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 qa/ganeti-qa.py |  4 ++++
 qa/qa_group.py  | 30 ++++++++++++++++++++++++
 qa/qa_rapi.py   | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+)

diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py
index 41dc3f9b6..f94746cfa 100755
--- a/qa/ganeti-qa.py
+++ b/qa/ganeti-qa.py
@@ -249,6 +249,10 @@ def RunGroupRwTests():
 
   """
   RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
+  RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
+  RunTestIf("group-rwops", qa_group.TestGroupModify)
+  RunTestIf("rapi", qa_rapi.TestRapiNodeGroups)
+
 
 def RunExportImportTests(instance, pnode, snode):
   """Tries to export and import the instance.
diff --git a/qa/qa_group.py b/qa/qa_group.py
index eda710fc2..428329162 100644
--- a/qa/qa_group.py
+++ b/qa/qa_group.py
@@ -53,6 +53,36 @@ def TestGroupAddRemoveRename():
     AssertCommand(["gnt-group", "rename", group1, existing_group_with_nodes])
 
 
+def TestGroupAddWithOptions():
+  """gnt-group add with options"""
+  groups = qa_config.get("groups", {})
+  group1 = groups.get("inexistent-groups", ["group1"])[0]
+
+  AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
+                fail=True)
+
+  AssertCommand(["gnt-group", "add", "--alloc-policy", "last_resort",
+                 "--node-parameters", "oob_program=/bin/true", group1])
+
+  AssertCommand(["gnt-group", "remove", group1])
+
+
+def TestGroupModify():
+  """gnt-group modify"""
+  groups = qa_config.get("groups", {})
+  group1 = groups.get("inexistent-groups", ["group1"])[0]
+
+  AssertCommand(["gnt-group", "add", group1])
+
+  try:
+    AssertCommand(["gnt-group", "modify", "--alloc-policy", "unallocable",
+                   "--node-parameters", "oob_program=/bin/false", group1])
+    AssertCommand(["gnt-group", "modify",
+                   "--alloc-policy", "notvalid", group1], fail=True)
+  finally:
+    AssertCommand(["gnt-group", "remove", group1])
+
+
 def TestGroupListDefaultFields():
   """gnt-group list"""
   AssertCommand(["gnt-group", "list"])
diff --git a/qa/qa_rapi.py b/qa/qa_rapi.py
index ea74bb5f8..2e19bf513 100644
--- a/qa/qa_rapi.py
+++ b/qa/qa_rapi.py
@@ -337,6 +337,68 @@ def _WaitForRapiJob(job_id):
                                    cli.StdioJobPollReportCb())
 
 
+def TestRapiNodeGroups():
+  """Test several node group operations using RAPI.
+
+  """
+  groups = qa_config.get("groups", {})
+  group1, group2, group3 = groups.get("inexistent-groups",
+                                      ["group1", "group2", "group3"])[:3]
+
+  # Create a group with no attributes
+  body = {
+    "name": group1,
+    }
+
+  (job_id, ) = _DoTests([
+    ("/2/groups", _VerifyReturnsJob, "POST", body),
+    ])
+
+  _WaitForRapiJob(job_id)
+
+  # Create a group specifying alloc_policy
+  body = {
+    "name": group2,
+    "alloc_policy": constants.ALLOC_POLICY_UNALLOCABLE,
+    }
+
+  (job_id, ) = _DoTests([
+    ("/2/groups", _VerifyReturnsJob, "POST", body),
+    ])
+
+  _WaitForRapiJob(job_id)
+
+  # Modify alloc_policy
+  body = {
+    "alloc_policy": constants.ALLOC_POLICY_UNALLOCABLE,
+    }
+
+  (job_id, ) = _DoTests([
+    ("/2/groups/%s/modify" % group1, _VerifyReturnsJob, "PUT", body),
+    ])
+
+  _WaitForRapiJob(job_id)
+
+  # Rename a group
+  body = {
+    "new_name": group3,
+    }
+
+  (job_id, ) = _DoTests([
+    ("/2/groups/%s/rename" % group2, _VerifyReturnsJob, "PUT", body),
+    ])
+
+  _WaitForRapiJob(job_id)
+
+  # Delete groups
+  for group in [group1, group3]:
+    (job_id, ) = _DoTests([
+      ("/2/groups/%s" % group, _VerifyReturnsJob, "DELETE", None),
+      ])
+
+    _WaitForRapiJob(job_id)
+
+
 def TestRapiInstanceAdd(node, use_client):
   """Test adding a new instance via RAPI"""
   instance = qa_config.AcquireInstance()
-- 
GitLab