Add a simple walk trhough the intended use case of
gnt-instance modify --new-primary for the disk template
file. The tested scenario is shuting down an instance,
manually moving the disk to the new node, setting the
new primary, and starting up the instance on the new
node. It is also verified that the operation is rejected
while the instance is still running on the old node.

Signed-off-by: Klaus Aehlig <aeh...@google.com>
---
 qa/ganeti-qa.py   |  5 +++++
 qa/qa-sample.json |  1 +
 qa/qa_instance.py | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+)

diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py
index 6bdb690..88571aa 100755
--- a/qa/ganeti-qa.py
+++ b/qa/ganeti-qa.py
@@ -601,6 +601,11 @@ def RunInstanceTests():
                     instance, inodes)
             RunTest(qa_instance.TestInstanceStartup, instance)
           RunCommonInstanceTests(instance)
+          if qa_config.TestEnabled("instance-modify-primary"):
+            othernode = qa_config.AcquireNode()
+            RunTest(qa_instance.TestInstanceModifyPrimaryAndBack,
+                    instance, inodes[0], othernode)
+            othernode.Release()
           RunGroupListTests()
           RunExportImportTests(instance, inodes)
           RunHardwareFailureTests(instance, inodes)
diff --git a/qa/qa-sample.json b/qa/qa-sample.json
index 0eb3b35..c072b1f 100644
--- a/qa/qa-sample.json
+++ b/qa/qa-sample.json
@@ -184,6 +184,7 @@
     "instance-list": true,
     "instance-migrate": true,
     "instance-modify": true,
+    "instance-modify-primary": true,
     "instance-reboot": true,
     "instance-reinstall": true,
     "instance-rename": true,
diff --git a/qa/qa_instance.py b/qa/qa_instance.py
index 5692d93..062e7e3 100644
--- a/qa/qa_instance.py
+++ b/qa/qa_instance.py
@@ -24,6 +24,7 @@
 """
 
 import operator
+import os
 import re
 
 from ganeti import utils
@@ -570,6 +571,38 @@ def TestInstanceModify(instance):
   AssertCommand(["gnt-instance", "modify", "--online", instance.name])
 
 
+@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
+def TestInstanceModifyPrimaryAndBack(instance, currentnode, othernode):
+  """gnt-instance modify --new-primary
+
+  This will leave the instance on its original primary node, not other node.
+
+  """
+  if instance.disk_template != constants.DT_FILE:
+    print qa_utils.FormatInfo("Test only supported for the file disk template")
+    return
+
+  name = instance.name
+  current = currentnode.primary
+  other = othernode.primary
+
+  filestorage = qa_config.get("file-storage-dir")
+  disk = os.path.join(filestorage, name)
+
+  AssertCommand(["gnt-instance", "modify", "--new-primary=%s" % other, name],
+                fail=True)
+  AssertCommand(["gnt-instance", "shutdown", name])
+  AssertCommand(["scp", "-r", disk, "%s:%s" % (other, filestorage)])
+  AssertCommand(["gnt-instance", "modify", "--new-primary=%s" % other, name])
+  AssertCommand(["gnt-instance", "startup", name])
+
+  # and back
+  AssertCommand(["gnt-instance", "shutdown", name])
+  AssertCommand(["rm", "-rf", disk], node=other)
+  AssertCommand(["gnt-instance", "modify", "--new-primary=%s" % current, name])
+  AssertCommand(["gnt-instance", "startup", name])
+
+
 @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
 def TestInstanceStoppedModify(instance):
   """gnt-instance modify (stopped instance)"""
-- 
1.8.1.3

Reply via email to