Add cleanup parameter to instance failover
authorMichele Tartara <mtartara@google.com>
Tue, 30 Jul 2013 11:59:52 +0000 (11:59 +0000)
committerMichele Tartara <mtartara@google.com>
Tue, 30 Jul 2013 13:12:43 +0000 (13:12 +0000)
Most of the code is shared with instance migrate, so we actually only need
to add the parameter and pass its value along the the common code.

Also, tests and harep are updated to support the right set of options to
the "failover" opcode.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

lib/cli.py
lib/client/gnt_instance.py
lib/cmdlib/instance_migration.py
lib/opcodes.py
src/Ganeti/HTools/Program/Harep.hs
src/Ganeti/OpCodes.hs
test/hs/Test/Ganeti/OpCodes.hs

index d72b7d4..aec722c 100644 (file)
@@ -1088,12 +1088,12 @@ SHOWCMD_OPT = cli_option("--show-cmd", dest="show_command",
 
 CLEANUP_OPT = cli_option("--cleanup", dest="cleanup",
                          default=False, action="store_true",
-                         help="Instead of performing the migration, try to"
-                         " recover from a failed cleanup. This is safe"
+                         help="Instead of performing the migration/failover,"
+                         " try to recover from a failed cleanup. This is safe"
                          " to run even if the instance is healthy, but it"
                          " will create extra replication traffic and "
                          " disrupt briefly the replication (like during the"
-                         " migration")
+                         " migration/failover")
 
 STATIC_OPT = cli_option("-s", "--static", dest="static",
                         action="store_true", default=False,
index 07db3a6..8ee9ca9 100644 (file)
@@ -1467,7 +1467,7 @@ commands = {
     FailoverInstance, ARGS_ONE_INSTANCE,
     [FORCE_OPT, IGNORE_CONSIST_OPT, SUBMIT_OPT, SHUTDOWN_TIMEOUT_OPT,
      DRY_RUN_OPT, PRIORITY_OPT, DST_NODE_OPT, IALLOCATOR_OPT,
-     IGNORE_IPOLICY_OPT],
+     IGNORE_IPOLICY_OPT, CLEANUP_OPT],
     "[-f] <instance>", "Stops the instance, changes its primary node and"
     " (if it was originally running) starts it on the new node"
     " (the secondary for mirrored instances or any node"
index 9b715ae..b8dc510 100644 (file)
@@ -117,8 +117,8 @@ class LUInstanceFailover(LogicalUnit):
     _ExpandNamesForMigration(self)
 
     self._migrater = \
-      TLMigrateInstance(self, self.op.instance_name, False, True, False,
-                        self.op.ignore_consistency, True,
+      TLMigrateInstance(self, self.op.instance_name, self.op.cleanup, True,
+                        False, self.op.ignore_consistency, True,
                         self.op.shutdown_timeout, self.op.ignore_ipolicy)
 
     self.tasklets = [self._migrater]
@@ -140,6 +140,7 @@ class LUInstanceFailover(LogicalUnit):
       "SHUTDOWN_TIMEOUT": self.op.shutdown_timeout,
       "OLD_PRIMARY": source_node,
       "NEW_PRIMARY": target_node,
+      "FAILOVER_CLEANUP": self.op.cleanup,
       }
 
     if instance.disk_template in constants.DTS_INT_MIRROR:
index 113f9b0..8ba0f78 100644 (file)
@@ -1520,6 +1520,8 @@ class OpInstanceFailover(OpCode):
     _PIgnoreIpolicy,
     _PIAllocFromDesc("Iallocator for deciding the target node for"
                      " shared-storage instances"),
+    ("cleanup", False, ht.TBool,
+     "Whether a previously failed failover should be cleaned up"),
     ]
   OP_RESULT = ht.TNone
 
index 520deeb..ee24ed9 100644 (file)
@@ -318,6 +318,7 @@ detectBroken nl inst =
                                 , opTargetNode = Nothing
                                 , opIgnoreIpolicy = False
                                 , opIallocator = Nothing
+                                , opMigrationCleanup = False
                                 }
            ])
        | offSec ->
index c31465b..edcdcd1 100644 (file)
@@ -84,6 +84,7 @@ $(genOpCode "OpCode"
      , pMigrationTargetNode
      , pIgnoreIpolicy
      , pIallocator
+     , pMigrationCleanup
      ])
   , ("OpInstanceMigrate",
      [ pInstanceName
index 2968173..494563f 100644 (file)
@@ -116,7 +116,8 @@ instance Arbitrary OpCodes.OpCode where
           genMaybe genNodeNameNE <*> genMaybe genNameNE
       "OP_INSTANCE_FAILOVER" ->
         OpCodes.OpInstanceFailover <$> genFQDN <*> arbitrary <*> arbitrary <*>
-          genMaybe genNodeNameNE <*> arbitrary <*> genMaybe genNameNE
+          genMaybe genNodeNameNE <*> arbitrary <*> genMaybe genNameNE <*>
+          arbitrary
       "OP_INSTANCE_MIGRATE" ->
         OpCodes.OpInstanceMigrate <$> genFQDN <*> arbitrary <*> arbitrary <*>
           genMaybe genNodeNameNE <*> arbitrary <*>