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

rlib2: Convert /2/instances/[inst]/reboot to OpcodeResource


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 7b3df961
......@@ -799,29 +799,28 @@ class R_2_instances_name_info(baserlib.OpcodeResource):
})
class R_2_instances_name_reboot(baserlib.ResourceBase):
class R_2_instances_name_reboot(baserlib.OpcodeResource):
"""/2/instances/[instance_name]/reboot resource.
Implements an instance reboot.
"""
def POST(self):
POST_OPCODE = opcodes.OpInstanceReboot
def GetPostOpInput(self):
"""Reboot an instance.
The URI takes type=[hard|soft|full] and
ignore_secondaries=[False|True] parameters.
"""
instance_name = self.items[0]
reboot_type = self.queryargs.get("type",
[constants.INSTANCE_REBOOT_HARD])[0]
ignore_secondaries = bool(self._checkIntVariable("ignore_secondaries"))
op = opcodes.OpInstanceReboot(instance_name=instance_name,
reboot_type=reboot_type,
ignore_secondaries=ignore_secondaries,
dry_run=bool(self.dryRun()))
return self.SubmitJob([op])
return ({}, {
"instance_name": self.items[0],
"reboot_type":
self.queryargs.get("type", [constants.INSTANCE_REBOOT_HARD])[0],
"ignore_secondaries": bool(self._checkIntVariable("ignore_secondaries")),
"dry_run": self.dryRun(),
})
class R_2_instances_name_startup(baserlib.ResourceBase):
......
......@@ -338,6 +338,29 @@ class TestInstanceInfo(unittest.TestCase):
self.assertRaises(IndexError, cl.GetNextSubmittedJob)
class TestInstanceReboot(unittest.TestCase):
def test(self):
clfactory = _FakeClientFactory(_FakeClient)
handler = _CreateHandler(rlib2.R_2_instances_name_reboot, ["inst847"], {
"dry-run": ["1"],
"ignore_secondaries": ["1"],
}, {}, clfactory)
job_id = handler.POST()
cl = clfactory.GetNextClient()
self.assertRaises(IndexError, clfactory.GetNextClient)
(exp_job_id, (op, )) = cl.GetNextSubmittedJob()
self.assertEqual(job_id, exp_job_id)
self.assertTrue(isinstance(op, opcodes.OpInstanceReboot))
self.assertEqual(op.instance_name, "inst847")
self.assertEqual(op.reboot_type, constants.INSTANCE_REBOOT_HARD)
self.assertTrue(op.ignore_secondaries)
self.assertTrue(op.dry_run)
self.assertRaises(IndexError, cl.GetNextSubmittedJob)
class TestParseInstanceCreateRequestVersion1(testutils.GanetiTestCase):
def setUp(self):
testutils.GanetiTestCase.setUp(self)
......
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