From 66787da54471e2cdd2594f82a3ddf7ae64645e44 Mon Sep 17 00:00:00 2001
From: Adeodato Simo <dato@google.com>
Date: Mon, 6 Dec 2010 16:46:01 +0000
Subject: [PATCH] Group operations: add QA tests for add/remove/rename

This is a single function that tests all of of the following:

  - creating groups
  - creating groups that exist fails
  - renaming an empty group
  - renaming a group with nodes
  - renaming to a name that already exists fails
  - removing an empty group works
  - removing a group with nodes fails

The "default" group is only used for the "rename group with nodes"
test.

Signed-off-by: Adeodato Simo <dato@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 qa/ganeti-qa.py   |  7 +++++++
 qa/qa-sample.json | 10 ++++++++++
 qa/qa_group.py    | 28 ++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)

diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py
index 6d1309ac6..56aa418bb 100755
--- a/qa/ganeti-qa.py
+++ b/qa/ganeti-qa.py
@@ -230,6 +230,12 @@ def RunGroupListTests():
   RunTestIf("group-list", qa_group.TestGroupListAllFields)
 
 
+def RunGroupRwTests():
+  """Run tests for adding/removing/renaming groups.
+
+  """
+  RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
+
 def RunExportImportTests(instance, pnode, snode):
   """Tries to export and import the instance.
 
@@ -358,6 +364,7 @@ def main():
 
   RunCommonNodeTests()
   RunGroupListTests()
+  RunGroupRwTests()
 
   pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
   try:
diff --git a/qa/qa-sample.json b/qa/qa-sample.json
index b1a9e4b1f..fa8cc8f30 100644
--- a/qa/qa-sample.json
+++ b/qa/qa-sample.json
@@ -33,6 +33,15 @@
     }
   ],
 
+  "groups": {
+    "group-with-nodes": "default",
+    "inexistent-groups": [
+      "group1",
+      "group2",
+      "group3"
+    ]
+  }
+
   "tests": {
     "env": true,
     "os": true,
@@ -54,6 +63,7 @@
     "cluster-modify": true,
 
     "group-list": true,
+    "group-rwops": true,
 
     "node-info": true,
     "node-volumes": true,
diff --git a/qa/qa_group.py b/qa/qa_group.py
index 9671b02ac..e0e4cc7fa 100644
--- a/qa/qa_group.py
+++ b/qa/qa_group.py
@@ -19,9 +19,37 @@
 # 02110-1301, USA.
 
 
+import qa_config
 from qa_utils import AssertCommand
 
 
+def TestGroupAddRemoveRename():
+  """gnt-group add/remove/rename"""
+  groups = qa_config.get("groups", {})
+
+  existing_group_with_nodes = groups.get("group-with-nodes", "default")
+  group1, group2, group3 = groups.get("inexistent-groups",
+                                      ["group1", "group2", "group3"])[:3]
+
+  AssertCommand(["gnt-group", "add", group1])
+  AssertCommand(["gnt-group", "add", group2])
+  AssertCommand(["gnt-group", "add", group2], fail=True)
+  AssertCommand(["gnt-group", "add", existing_group_with_nodes], fail=True)
+
+  AssertCommand(["gnt-group", "rename", group1, group2], fail=True)
+  AssertCommand(["gnt-group", "rename", group1, group3])
+
+  try:
+    AssertCommand(["gnt-group", "rename", existing_group_with_nodes, group1])
+
+    AssertCommand(["gnt-group", "remove", group2])
+    AssertCommand(["gnt-group", "remove", group3])
+    AssertCommand(["gnt-group", "remove", group1], fail=True)
+  finally:
+    # Try to ensure idempotency re groups that already existed.
+    AssertCommand(["gnt-group", "rename", group1, existing_group_with_nodes])
+
+
 def TestGroupListDefaultFields():
   """gnt-group list"""
   AssertCommand(["gnt-group", "list"])
-- 
GitLab