From e5c2accd7ea5c87fdba3d1a3d753bf668db96498 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Thu, 9 Dec 2010 11:38:50 +0100
Subject: [PATCH] Simplify instance rename qa test

The current instance rename qa testing function can only perform
back-and-forth renames, both for command line and rapi. In order to be
able to perform same-name rename tests we change it to be able to
perform simple renames, and then we change qa to call it to perform both
sides of the renaming.

The same change is applied both to the local and the rapi test.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 qa/ganeti-qa.py   |  7 +++++--
 qa/qa_instance.py | 12 ++++--------
 qa/qa_rapi.py     |  8 ++------
 3 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py
index 56aa418bb..1c2f74635 100755
--- a/qa/ganeti-qa.py
+++ b/qa/ganeti-qa.py
@@ -199,14 +199,17 @@ def RunCommonInstanceTests(instance):
   RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
 
   if qa_config.TestEnabled('instance-rename'):
+    rename_source = instance["name"]
     rename_target = qa_config.get("rename", None)
     if rename_target is None:
       print qa_utils.FormatError("Can rename instance, 'rename' entry is"
                                  " missing from configuration")
     else:
       RunTest(qa_instance.TestInstanceShutdown, instance)
-      RunTest(qa_instance.TestInstanceRename, instance, rename_target)
-      RunTestIf("rapi", qa_rapi.TestRapiInstanceRename, instance, rename_target)
+      RunTest(qa_instance.TestInstanceRename, rename_source, rename_target)
+      RunTest(qa_instance.TestInstanceRename, rename_target, rename_source)
+      RunTestIf("rapi", qa_rapi.TestRapiInstanceRename, rename_source, rename_target)
+      RunTestIf("rapi", qa_rapi.TestRapiInstanceRename, rename_target, rename_source)
       RunTest(qa_instance.TestInstanceStartup, instance)
 
   RunTestIf("tags", qa_tags.TestInstanceTags, instance)
diff --git a/qa/qa_instance.py b/qa/qa_instance.py
index a8bea2fb4..4a3d6bd05 100644
--- a/qa/qa_instance.py
+++ b/qa/qa_instance.py
@@ -133,15 +133,11 @@ def _CheckSsconfInstanceList(instance):
            _ReadSsconfInstanceList())
 
 
-def TestInstanceRename(instance, rename_target):
+def TestInstanceRename(rename_source, rename_target):
   """gnt-instance rename"""
-  rename_source = instance['name']
-
-  for name1, name2 in [(rename_source, rename_target),
-                       (rename_target, rename_source)]:
-    _CheckSsconfInstanceList(name1)
-    AssertCommand(["gnt-instance", "rename", name1, name2])
-    _CheckSsconfInstanceList(name2)
+  _CheckSsconfInstanceList(rename_source)
+  AssertCommand(["gnt-instance", "rename", rename_source, rename_target])
+  _CheckSsconfInstanceList(rename_target)
 
 
 def TestInstanceFailover(instance):
diff --git a/qa/qa_rapi.py b/qa/qa_rapi.py
index 4976defee..86374e573 100644
--- a/qa/qa_rapi.py
+++ b/qa/qa_rapi.py
@@ -402,13 +402,9 @@ def TestRapiInstanceMigrate(instance):
   _WaitForRapiJob(_rapi_client.MigrateInstance(instance["name"]))
 
 
-def TestRapiInstanceRename(instance, rename_target):
+def TestRapiInstanceRename(rename_source, rename_target):
   """Test renaming instance via RAPI"""
-  rename_source = instance["name"]
-
-  for name1, name2 in [(rename_source, rename_target),
-                       (rename_target, rename_source)]:
-    _WaitForRapiJob(_rapi_client.RenameInstance(name1, name2))
+  _WaitForRapiJob(_rapi_client.RenameInstance(rename_source, rename_target))
 
 
 def TestRapiInstanceModify(instance):
-- 
GitLab