From 7910e7a55004a75a909de7dd9a1b657ab09a6875 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Fri, 6 Jun 2008 09:31:07 +0000
Subject: [PATCH] =?UTF-8?q?Forward-port:=20Add=20QA=20test=20for=20?=
 =?UTF-8?q?=E2=80=9Cgnt-instance=20replace-disks=E2=80=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reviewed-by: iustinp
---
 qa/ganeti-qa.py   |  8 ++++++++
 qa/qa-sample.yaml |  3 +++
 qa/qa_instance.py | 29 +++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py
index 4d0ac6b32..469a18673 100755
--- a/qa/ganeti-qa.py
+++ b/qa/ganeti-qa.py
@@ -207,6 +207,14 @@ def RunHardwareFailureTests(instance, pnode, snode):
   if qa_config.TestEnabled('instance-failover'):
     RunTest(qa_instance.TestInstanceFailover, instance)
 
+  if qa_config.TestEnabled('instance-replace-disks'):
+    othernode = qa_config.AcquireNode(exclude=pnode)
+    try:
+      RunTest(qa_instance.TestReplaceDisks,
+              instance, pnode, snode, othernode)
+    finally:
+      qa_config.ReleaseNode(othernode)
+
   if qa_config.TestEnabled('node-evacuate'):
     RunTest(qa_node.TestNodeEvacuate, pnode, snode)
 
diff --git a/qa/qa-sample.yaml b/qa/qa-sample.yaml
index 4138ea242..223854109 100644
--- a/qa/qa-sample.yaml
+++ b/qa/qa-sample.yaml
@@ -69,6 +69,9 @@ tests:
   # they support the `gnt-instance console' command.
   instance-console: False
 
+  # Disabled by default because it takes rather long
+  instance-replace-disks: False
+
   # Make sure not to include the disk(s) required for Dom0 to be included in
   # the volume group used for instances. Otherwise the whole system may stop
   # working until restarted.
diff --git a/qa/qa_instance.py b/qa/qa_instance.py
index d6de305cd..e9ea78853 100644
--- a/qa/qa_instance.py
+++ b/qa/qa_instance.py
@@ -194,6 +194,35 @@ def TestInstanceConsole(instance):
                        utils.ShellQuoteArgs(cmd)).wait(), 0)
 
 
+@qa_utils.DefineHook('instance-replace-disks')
+def TestReplaceDisks(instance, pnode, snode, othernode):
+  """gnt-instance replace-disks"""
+  master = qa_config.GetMasterNode()
+
+  def buildcmd(args):
+    cmd = ['gnt-instance', 'replace-disks']
+    cmd.extend(args)
+    cmd.append(instance["name"])
+    return cmd
+
+  cmd = buildcmd(["-p"])
+  AssertEqual(StartSSH(master['primary'],
+                       utils.ShellQuoteArgs(cmd)).wait(), 0)
+
+  cmd = buildcmd(["-s"])
+  AssertEqual(StartSSH(master['primary'],
+                       utils.ShellQuoteArgs(cmd)).wait(), 0)
+
+  cmd = buildcmd(["--new-secondary=%s" % othernode["primary"]])
+  AssertEqual(StartSSH(master['primary'],
+                       utils.ShellQuoteArgs(cmd)).wait(), 0)
+
+  # Restore
+  cmd = buildcmd(["--new-secondary=%s" % snode["primary"]])
+  AssertEqual(StartSSH(master['primary'],
+                       utils.ShellQuoteArgs(cmd)).wait(), 0)
+
+
 @qa_utils.DefineHook('backup-export')
 def TestInstanceExport(instance, node):
   """gnt-backup export"""
-- 
GitLab