From 054a86962eb4f9e04030fde8751fbdeb4385b7d8 Mon Sep 17 00:00:00 2001
From: Manuel Franceschini <manuel.franceschini@gmail.com>
Date: Wed, 23 Apr 2008 12:27:48 +0000
Subject: [PATCH] Add instance rename to burnin

This patch adds the possibility to execute instance renaming when
doing a cluster burnin. The optional parameter --rename takes
one 'spare' instance name.
Given this option it renames all given instances to the spare one
and back to their original name.

Reviewed-by: iustinp
---
 tools/burnin | 46 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/tools/burnin b/tools/burnin
index 82c851149..c8e40b063 100755
--- a/tools/burnin
+++ b/tools/burnin
@@ -130,6 +130,10 @@ class Burner(object):
     parser.add_option("--no-startstop", dest="do_startstop",
                       help="Skip instance stop/start", action="store_false",
                       default=True)
+    parser.add_option("--rename", dest="rename", default=None,
+                      help="Give one unused instance name which is taken"
+                           " to start the renaming sequence",
+                      metavar="<instance_name>")
     parser.add_option("-t", "--disk-template", dest="disk_template",
                       choices=("diskless", "file", "plain", "drbd"),
                       default="drbd",
@@ -306,15 +310,30 @@ class Burner(object):
       self.ExecOp(imp_op)
       self.to_rem.append(instance)
 
+  def StopInstance(self, instance):
+    """Stop given instance."""
+    op = opcodes.OpShutdownInstance(instance_name=instance)
+    Log("- Shutdown instance %s" % instance)
+    self.ExecOp(op)
+
+  def StartInstance(self, instance):
+    """Start given instance."""
+    op = opcodes.OpStartupInstance(instance_name=instance, force=False)
+    Log("- Start instance %s" % instance)
+    self.ExecOp(op)
+
+  def RenameInstance(self, instance, instance_new):
+    """Rename instance."""
+    op = opcodes.OpRenameInstance(instance_name=instance,
+                                  new_name=instance_new)
+    Log("- Rename instance %s to %s" % (instance, instance_new))
+    self.ExecOp(op)
+
   def StopStart(self):
     """Stop/start the instances."""
     for instance in self.instances:
-      op = opcodes.OpShutdownInstance(instance_name=instance)
-      Log("- Shutdown instance %s" % instance)
-      self.ExecOp(op)
-      op = opcodes.OpStartupInstance(instance_name=instance, force=False)
-      Log("- Start instance %s" % instance)
-      self.ExecOp(op)
+      self.StopInstance(instance)
+      self.StartInstance(instance)
 
   def Remove(self):
     """Remove the instances."""
@@ -323,6 +342,18 @@ class Burner(object):
       Log("- Remove instance %s" % instance)
       self.ExecOp(op)
 
+
+  def Rename(self):
+    """Rename the instances."""
+    rename = self.opts.rename
+    for instance in self.instances:
+      self.StopInstance(instance)
+      self.RenameInstance(instance, rename)
+      self.StartInstance(rename)
+      self.StopInstance(rename)
+      self.RenameInstance(rename, instance)
+      self.StartInstance(instance)
+
   def BurninCluster(self):
     """Test a cluster intensively.
 
@@ -360,6 +391,9 @@ class Burner(object):
       if opts.do_startstop:
         self.StopStart()
 
+      if opts.rename:
+        self.Rename()
+
       has_err = False
     finally:
       if has_err:
-- 
GitLab