Revision 8d232068
b/lib/rapi/rlib2.py | ||
---|---|---|
518 | 518 |
}) |
519 | 519 |
|
520 | 520 |
|
521 |
class R_2_nodes_name_storage_modify(baserlib.ResourceBase):
|
|
521 |
class R_2_nodes_name_storage_modify(baserlib.OpcodeResource):
|
|
522 | 522 |
"""/2/nodes/[node_name]/storage/modify resource. |
523 | 523 |
|
524 | 524 |
""" |
525 |
def PUT(self): |
|
526 |
node_name = self.items[0] |
|
525 |
PUT_OPCODE = opcodes.OpNodeModifyStorage |
|
527 | 526 |
|
528 |
storage_type = self._checkStringVariable("storage_type", None) |
|
529 |
if not storage_type: |
|
530 |
raise http.HttpBadRequest("Missing the required 'storage_type'" |
|
531 |
" parameter") |
|
527 |
def GetPutOpInput(self): |
|
528 |
"""Modifies a storage volume on a node. |
|
532 | 529 |
|
530 |
""" |
|
531 |
storage_type = self._checkStringVariable("storage_type", None) |
|
533 | 532 |
name = self._checkStringVariable("name", None) |
533 |
|
|
534 | 534 |
if not name: |
535 | 535 |
raise http.HttpBadRequest("Missing the required 'name'" |
536 | 536 |
" parameter") |
... | ... | |
541 | 541 |
changes[constants.SF_ALLOCATABLE] = \ |
542 | 542 |
bool(self._checkIntVariable("allocatable", default=1)) |
543 | 543 |
|
544 |
op = opcodes.OpNodeModifyStorage(node_name=node_name, |
|
545 |
storage_type=storage_type, |
|
546 |
name=name, |
|
547 |
changes=changes) |
|
548 |
return self.SubmitJob([op]) |
|
544 |
return ({}, { |
|
545 |
"node_name": self.items[0], |
|
546 |
"storage_type": storage_type, |
|
547 |
"name": name, |
|
548 |
"changes": changes, |
|
549 |
}) |
|
549 | 550 |
|
550 | 551 |
|
551 | 552 |
class R_2_nodes_name_storage_repair(baserlib.ResourceBase): |
b/test/ganeti.rapi.rlib2_unittest.py | ||
---|---|---|
586 | 586 |
self.assertRaises(http.HttpBadRequest, handler.GET) |
587 | 587 |
|
588 | 588 |
|
589 |
class TestStorageModify(unittest.TestCase): |
|
590 |
def test(self): |
|
591 |
clfactory = _FakeClientFactory(_FakeClient) |
|
592 |
|
|
593 |
for allocatable in [None, "1", "0"]: |
|
594 |
queryargs = { |
|
595 |
"storage_type": constants.ST_LVM_VG, |
|
596 |
"name": "pv-a", |
|
597 |
} |
|
598 |
|
|
599 |
if allocatable is not None: |
|
600 |
queryargs["allocatable"] = allocatable |
|
601 |
|
|
602 |
handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify, |
|
603 |
["node9292"], queryargs, {}, clfactory) |
|
604 |
job_id = handler.PUT() |
|
605 |
|
|
606 |
cl = clfactory.GetNextClient() |
|
607 |
self.assertRaises(IndexError, clfactory.GetNextClient) |
|
608 |
|
|
609 |
(exp_job_id, (op, )) = cl.GetNextSubmittedJob() |
|
610 |
self.assertEqual(job_id, exp_job_id) |
|
611 |
self.assertTrue(isinstance(op, opcodes.OpNodeModifyStorage)) |
|
612 |
self.assertEqual(op.node_name, "node9292") |
|
613 |
self.assertEqual(op.storage_type, constants.ST_LVM_VG) |
|
614 |
self.assertEqual(op.name, "pv-a") |
|
615 |
if allocatable is None: |
|
616 |
self.assertFalse(op.changes) |
|
617 |
else: |
|
618 |
assert allocatable in ("0", "1") |
|
619 |
self.assertEqual(op.changes, { |
|
620 |
constants.SF_ALLOCATABLE: (allocatable == "1"), |
|
621 |
}) |
|
622 |
self.assertFalse(hasattr(op, "dry_run")) |
|
623 |
self.assertFalse(hasattr(op, "force")) |
|
624 |
|
|
625 |
self.assertRaises(IndexError, cl.GetNextSubmittedJob) |
|
626 |
|
|
627 |
def testErrors(self): |
|
628 |
clfactory = _FakeClientFactory(_FakeClient) |
|
629 |
|
|
630 |
# No storage type |
|
631 |
queryargs = { |
|
632 |
"name": "xyz", |
|
633 |
} |
|
634 |
handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify, |
|
635 |
["node26016"], queryargs, {}, clfactory) |
|
636 |
self.assertRaises(http.HttpBadRequest, handler.PUT) |
|
637 |
|
|
638 |
# No name |
|
639 |
queryargs = { |
|
640 |
"storage_type": constants.ST_LVM_VG, |
|
641 |
} |
|
642 |
handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify, |
|
643 |
["node21218"], queryargs, {}, clfactory) |
|
644 |
self.assertRaises(http.HttpBadRequest, handler.PUT) |
|
645 |
|
|
646 |
# Invalid value |
|
647 |
queryargs = { |
|
648 |
"storage_type": constants.ST_LVM_VG, |
|
649 |
"name": "pv-b", |
|
650 |
"allocatable": "noint", |
|
651 |
} |
|
652 |
handler = _CreateHandler(rlib2.R_2_nodes_name_storage_modify, |
|
653 |
["node30685"], queryargs, {}, clfactory) |
|
654 |
self.assertRaises(http.HttpBadRequest, handler.PUT) |
|
655 |
|
|
656 |
|
|
589 | 657 |
class TestParseInstanceCreateRequestVersion1(testutils.GanetiTestCase): |
590 | 658 |
def setUp(self): |
591 | 659 |
testutils.GanetiTestCase.setUp(self) |
Also available in: Unified diff