Expose allow-failover option to RAPI client
authorYiannis Tsiouris <tsiou@grnet.gr>
Mon, 6 Feb 2017 14:17:11 +0000 (16:17 +0200)
committerViktor Bachraty <vbachraty@google.com>
Mon, 6 Feb 2017 20:56:24 +0000 (20:56 +0000)
'gnt-instance migrate' supports performing a failover on an instance
that is not possible to migrate (e.g. if the instance is down). This
patch exposes this option ('--allow-failover') to the RAPI client.

Signed-off-by: Yiannis Tsiouris <tsiou@grnet.gr>
Signed-off-by: Alex Kiousis <alexk@noc.grnet.gr>
Reviewed-by: Viktor Bachraty <vbachraty@google.com>

lib/rapi/client.py
test/py/ganeti.rapi.client_unittest.py

index 4f6c8b6..5128936 100644 (file)
@@ -1342,7 +1342,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904
                               (GANETI_RAPI_VERSION, instance)), query, body)
 
   def MigrateInstance(self, instance, mode=None, cleanup=None,
-                      target_node=None, reason=None):
+                      target_node=None, reason=None, allow_failover=None):
     """Migrates an instance.
 
     @type instance: string
@@ -1355,6 +1355,9 @@ class GanetiRapiClient(object): # pylint: disable=R0904
     @param target_node: Target Node for externally mirrored instances
     @type reason: string
     @param reason: the reason for executing this operation
+    @type allow_failover: bool
+    @param allow_failover: Whether to fallback to failover if migration is not
+      possible
     @rtype: string
     @return: job id
 
@@ -1363,6 +1366,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904
     _SetItemIf(body, mode is not None, "mode", mode)
     _SetItemIf(body, cleanup is not None, "cleanup", cleanup)
     _SetItemIf(body, target_node is not None, "target_node", target_node)
+    _SetItemIf(body, allow_failover is not None, "allow_failover", allow_failover)
 
     query = []
     _AppendReason(query, reason)
index 9c534e5..0ddfdb4 100755 (executable)
@@ -781,17 +781,20 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
   def testMigrateInstance(self):
     for mode in constants.HT_MIGRATION_MODES:
       for cleanup in [False, True]:
-        self.rapi.AddResponse("31910")
-        job_id = self.client.MigrateInstance("inst289", mode=mode,
-                                             cleanup=cleanup)
-        self.assertEqual(job_id, 31910)
-        self.assertHandler(rlib2.R_2_instances_name_migrate)
-        self.assertItems(["inst289"])
+        for allow_failover in [False, True]:
+          self.rapi.AddResponse("31910")
+          job_id = self.client.MigrateInstance("inst289", mode=mode,
+                                               cleanup=cleanup,
+                                               allow_failover=allow_failover)
+          self.assertEqual(job_id, 31910)
+          self.assertHandler(rlib2.R_2_instances_name_migrate)
+          self.assertItems(["inst289"])
 
-        data = serializer.LoadJson(self.rapi.GetLastRequestData())
-        self.assertEqual(len(data), 2)
-        self.assertEqual(data["mode"], mode)
-        self.assertEqual(data["cleanup"], cleanup)
+          data = serializer.LoadJson(self.rapi.GetLastRequestData())
+          self.assertEqual(len(data), 3)
+          self.assertEqual(data["mode"], mode)
+          self.assertEqual(data["cleanup"], cleanup)
+          self.assertEqual(data["allow_failover"], allow_failover)
 
   def testFailoverInstanceDefaults(self):
     self.rapi.AddResponse("7639")