Revision 8d232068 test/ganeti.rapi.rlib2_unittest.py

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