Commit 4717e6eb authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

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


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent ac4888c1
......@@ -823,28 +823,27 @@ class R_2_instances_name_reboot(baserlib.OpcodeResource):
})
class R_2_instances_name_startup(baserlib.ResourceBase):
class R_2_instances_name_startup(baserlib.OpcodeResource):
"""/2/instances/[instance_name]/startup resource.
Implements an instance startup.
"""
def PUT(self):
PUT_OPCODE = opcodes.OpInstanceStartup
def GetPutOpInput(self):
"""Startup an instance.
The URI takes force=[False|True] parameter to start the instance
if even if secondary disks are failing.
"""
instance_name = self.items[0]
force_startup = bool(self._checkIntVariable("force"))
no_remember = bool(self._checkIntVariable("no_remember"))
op = opcodes.OpInstanceStartup(instance_name=instance_name,
force=force_startup,
dry_run=bool(self.dryRun()),
no_remember=no_remember)
return self.SubmitJob([op])
return ({}, {
"instance_name": self.items[0],
"force": self.useForce(),
"dry_run": self.dryRun(),
"no_remember": bool(self._checkIntVariable("no_remember")),
})
def _ParseShutdownInstanceRequest(name, data, dry_run, no_remember):
......
......@@ -361,6 +361,29 @@ class TestInstanceReboot(unittest.TestCase):
self.assertRaises(IndexError, cl.GetNextSubmittedJob)
class TestInstanceStartup(unittest.TestCase):
def test(self):
clfactory = _FakeClientFactory(_FakeClient)
handler = _CreateHandler(rlib2.R_2_instances_name_startup, ["inst31083"], {
"force": ["1"],
"no_remember": ["1"],
}, {}, clfactory)
job_id = handler.PUT()
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.OpInstanceStartup))
self.assertEqual(op.instance_name, "inst31083")
self.assertTrue(op.no_remember)
self.assertTrue(op.force)
self.assertFalse(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