Commit cd577680 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

RAPI client: Always return job ID



Even removing tags returns a job ID.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarDavid Knowles <dknowles@google.com>
parent a60e3cb0
...@@ -490,7 +490,7 @@ class GanetiRapiClient(object): ...@@ -490,7 +490,7 @@ class GanetiRapiClient(object):
if dry_run: if dry_run:
query.append(("dry-run", 1)) query.append(("dry-run", 1))
self._SendRequest(HTTP_DELETE, "/2/tags", query) return self._SendRequest(HTTP_DELETE, "/2/tags", query)
def GetInstances(self, bulk=False): def GetInstances(self, bulk=False):
"""Gets information about instances on the cluster. """Gets information about instances on the cluster.
...@@ -512,7 +512,6 @@ class GanetiRapiClient(object): ...@@ -512,7 +512,6 @@ class GanetiRapiClient(object):
else: else:
return [i["id"] for i in instances] return [i["id"] for i in instances]
def GetInstanceInfo(self, instance): def GetInstanceInfo(self, instance):
"""Gets information about an instance. """Gets information about an instance.
...@@ -605,7 +604,8 @@ class GanetiRapiClient(object): ...@@ -605,7 +604,8 @@ class GanetiRapiClient(object):
if dry_run: if dry_run:
query.append(("dry-run", 1)) query.append(("dry-run", 1))
self._SendRequest(HTTP_DELETE, "/2/instances/%s/tags" % instance, query) return self._SendRequest(HTTP_DELETE, "/2/instances/%s/tags" % instance,
query)
def RebootInstance(self, instance, reboot_type=None, ignore_secondaries=None, def RebootInstance(self, instance, reboot_type=None, ignore_secondaries=None,
dry_run=False): dry_run=False):
...@@ -630,7 +630,8 @@ class GanetiRapiClient(object): ...@@ -630,7 +630,8 @@ class GanetiRapiClient(object):
if dry_run: if dry_run:
query.append(("dry-run", 1)) query.append(("dry-run", 1))
self._SendRequest(HTTP_POST, "/2/instances/%s/reboot" % instance, query) return self._SendRequest(HTTP_POST, "/2/instances/%s/reboot" % instance,
query)
def ShutdownInstance(self, instance, dry_run=False): def ShutdownInstance(self, instance, dry_run=False):
"""Shuts down an instance. """Shuts down an instance.
...@@ -645,7 +646,8 @@ class GanetiRapiClient(object): ...@@ -645,7 +646,8 @@ class GanetiRapiClient(object):
if dry_run: if dry_run:
query.append(("dry-run", 1)) query.append(("dry-run", 1))
self._SendRequest(HTTP_PUT, "/2/instances/%s/shutdown" % instance, query) return self._SendRequest(HTTP_PUT, "/2/instances/%s/shutdown" % instance,
query)
def StartupInstance(self, instance, dry_run=False): def StartupInstance(self, instance, dry_run=False):
"""Starts up an instance. """Starts up an instance.
...@@ -660,7 +662,8 @@ class GanetiRapiClient(object): ...@@ -660,7 +662,8 @@ class GanetiRapiClient(object):
if dry_run: if dry_run:
query.append(("dry-run", 1)) query.append(("dry-run", 1))
self._SendRequest(HTTP_PUT, "/2/instances/%s/startup" % instance, query) return self._SendRequest(HTTP_PUT, "/2/instances/%s/startup" % instance,
query)
def ReinstallInstance(self, instance, os, no_startup=False): def ReinstallInstance(self, instance, os, no_startup=False):
"""Reinstalls an instance. """Reinstalls an instance.
...@@ -676,7 +679,8 @@ class GanetiRapiClient(object): ...@@ -676,7 +679,8 @@ class GanetiRapiClient(object):
query = [("os", os)] query = [("os", os)]
if no_startup: if no_startup:
query.append(("nostartup", 1)) query.append(("nostartup", 1))
self._SendRequest(HTTP_POST, "/2/instances/%s/reinstall" % instance, query) return self._SendRequest(HTTP_POST, "/2/instances/%s/reinstall" % instance,
query)
def ReplaceInstanceDisks(self, instance, disks, mode="replace_auto", def ReplaceInstanceDisks(self, instance, disks, mode="replace_auto",
remote_node=None, iallocator="hail", dry_run=False): remote_node=None, iallocator="hail", dry_run=False):
...@@ -758,7 +762,7 @@ class GanetiRapiClient(object): ...@@ -758,7 +762,7 @@ class GanetiRapiClient(object):
if dry_run: if dry_run:
query.append(("dry-run", 1)) query.append(("dry-run", 1))
self._SendRequest(HTTP_DELETE, "/2/jobs/%d" % job_id, query) return self._SendRequest(HTTP_DELETE, "/2/jobs/%d" % job_id, query)
def GetNodes(self, bulk=False): def GetNodes(self, bulk=False):
"""Gets all nodes in the cluster. """Gets all nodes in the cluster.
......
...@@ -186,7 +186,9 @@ class GanetiRapiClientTests(unittest.TestCase): ...@@ -186,7 +186,9 @@ class GanetiRapiClientTests(unittest.TestCase):
self.assertQuery("tag", ["awesome"]) self.assertQuery("tag", ["awesome"])
def testDeleteClusterTags(self): def testDeleteClusterTags(self):
self.client.DeleteClusterTags(["awesome"], dry_run=True) self.rapi.AddResponse("5107")
self.assertEqual(5107, self.client.DeleteClusterTags(["awesome"],
dry_run=True))
self.assertHandler(rlib2.R_2_tags) self.assertHandler(rlib2.R_2_tags)
self.assertDryRun() self.assertDryRun()
self.assertQuery("tag", ["awesome"]) self.assertQuery("tag", ["awesome"])
...@@ -237,15 +239,19 @@ class GanetiRapiClientTests(unittest.TestCase): ...@@ -237,15 +239,19 @@ class GanetiRapiClientTests(unittest.TestCase):
self.assertQuery("tag", ["awesome"]) self.assertQuery("tag", ["awesome"])
def testDeleteInstanceTags(self): def testDeleteInstanceTags(self):
self.client.DeleteInstanceTags("foo", ["awesome"], dry_run=True) self.rapi.AddResponse("25826")
self.assertEqual(25826, self.client.DeleteInstanceTags("foo", ["awesome"],
dry_run=True))
self.assertHandler(rlib2.R_2_instances_name_tags) self.assertHandler(rlib2.R_2_instances_name_tags)
self.assertItems(["foo"]) self.assertItems(["foo"])
self.assertDryRun() self.assertDryRun()
self.assertQuery("tag", ["awesome"]) self.assertQuery("tag", ["awesome"])
def testRebootInstance(self): def testRebootInstance(self):
self.client.RebootInstance("i-bar", reboot_type="hard", self.rapi.AddResponse("6146")
ignore_secondaries=True, dry_run=True) job_id = self.client.RebootInstance("i-bar", reboot_type="hard",
ignore_secondaries=True, dry_run=True)
self.assertEqual(6146, job_id)
self.assertHandler(rlib2.R_2_instances_name_reboot) self.assertHandler(rlib2.R_2_instances_name_reboot)
self.assertItems(["i-bar"]) self.assertItems(["i-bar"])
self.assertDryRun() self.assertDryRun()
...@@ -253,19 +259,25 @@ class GanetiRapiClientTests(unittest.TestCase): ...@@ -253,19 +259,25 @@ class GanetiRapiClientTests(unittest.TestCase):
self.assertQuery("ignore_secondaries", ["True"]) self.assertQuery("ignore_secondaries", ["True"])
def testShutdownInstance(self): def testShutdownInstance(self):
self.client.ShutdownInstance("foo-instance", dry_run=True) self.rapi.AddResponse("1487")
self.assertEqual(1487, self.client.ShutdownInstance("foo-instance",
dry_run=True))
self.assertHandler(rlib2.R_2_instances_name_shutdown) self.assertHandler(rlib2.R_2_instances_name_shutdown)
self.assertItems(["foo-instance"]) self.assertItems(["foo-instance"])
self.assertDryRun() self.assertDryRun()
def testStartupInstance(self): def testStartupInstance(self):
self.client.StartupInstance("bar-instance", dry_run=True) self.rapi.AddResponse("27149")
self.assertEqual(27149, self.client.StartupInstance("bar-instance",
dry_run=True))
self.assertHandler(rlib2.R_2_instances_name_startup) self.assertHandler(rlib2.R_2_instances_name_startup)
self.assertItems(["bar-instance"]) self.assertItems(["bar-instance"])
self.assertDryRun() self.assertDryRun()
def testReinstallInstance(self): def testReinstallInstance(self):
self.client.ReinstallInstance("baz-instance", "DOS", no_startup=True) self.rapi.AddResponse("19119")
self.assertEqual(19119, self.client.ReinstallInstance("baz-instance", "DOS",
no_startup=True))
self.assertHandler(rlib2.R_2_instances_name_reinstall) self.assertHandler(rlib2.R_2_instances_name_reinstall)
self.assertItems(["baz-instance"]) self.assertItems(["baz-instance"])
self.assertQuery("os", ["DOS"]) self.assertQuery("os", ["DOS"])
...@@ -313,7 +325,9 @@ class GanetiRapiClientTests(unittest.TestCase): ...@@ -313,7 +325,9 @@ class GanetiRapiClientTests(unittest.TestCase):
self.assertItems(["1234"]) self.assertItems(["1234"])
def testDeleteJob(self): def testDeleteJob(self):
self.client.DeleteJob(999, dry_run=True) self.rapi.AddResponse("[true, \"Job 123 will be canceled\"]")
self.assertEqual([True, "Job 123 will be canceled"],
self.client.DeleteJob(999, dry_run=True))
self.assertHandler(rlib2.R_2_jobs_id) self.assertHandler(rlib2.R_2_jobs_id)
self.assertItems(["999"]) self.assertItems(["999"])
self.assertDryRun() self.assertDryRun()
...@@ -425,7 +439,9 @@ class GanetiRapiClientTests(unittest.TestCase): ...@@ -425,7 +439,9 @@ class GanetiRapiClientTests(unittest.TestCase):
self.assertQuery("tag", ["awesome"]) self.assertQuery("tag", ["awesome"])
def testDeleteNodeTags(self): def testDeleteNodeTags(self):
self.client.DeleteNodeTags("node-w", ["awesome"], dry_run=True) self.rapi.AddResponse("16861")
self.assertEqual(16861, self.client.DeleteNodeTags("node-w", ["awesome"],
dry_run=True))
self.assertHandler(rlib2.R_2_nodes_name_tags) self.assertHandler(rlib2.R_2_nodes_name_tags)
self.assertItems(["node-w"]) self.assertItems(["node-w"])
self.assertDryRun() self.assertDryRun()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment