Document DRBD dynamic resync params in man pages
[ganeti-local] / test / ganeti.rapi.rlib2_unittest.py
index fb168d5..cde68ce 100755 (executable)
@@ -272,6 +272,26 @@ class TestNodeEvacuate(unittest.TestCase):
     self.assertRaises(IndexError, cl.GetNextSubmittedJob)
 
 
+class TestNodePowercycle(unittest.TestCase):
+  def test(self):
+    clfactory = _FakeClientFactory(_FakeClient)
+    handler = _CreateHandler(rlib2.R_2_nodes_name_powercycle, ["node20744"], {
+      "force": ["1"],
+      }, None, 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.OpNodePowercycle))
+    self.assertEqual(op.node_name, "node20744")
+    self.assertTrue(op.force)
+
+    self.assertRaises(IndexError, cl.GetNextSubmittedJob)
+
+
 class TestGroupAssignNodes(unittest.TestCase):
   def test(self):
     clfactory = _FakeClientFactory(_FakeClient)
@@ -446,6 +466,26 @@ class TestInstanceDeactivateDisks(unittest.TestCase):
     self.assertRaises(IndexError, cl.GetNextSubmittedJob)
 
 
+class TestInstanceRecreateDisks(unittest.TestCase):
+  def test(self):
+    clfactory = _FakeClientFactory(_FakeClient)
+    handler = _CreateHandler(rlib2.R_2_instances_name_recreate_disks,
+                             ["inst22357"], {}, {}, 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.OpInstanceRecreateDisks))
+    self.assertEqual(op.instance_name, "inst22357")
+    self.assertFalse(hasattr(op, "dry_run"))
+    self.assertFalse(hasattr(op, "force"))
+
+    self.assertRaises(IndexError, cl.GetNextSubmittedJob)
+
+
 class TestInstanceFailover(unittest.TestCase):
   def test(self):
     clfactory = _FakeClientFactory(_FakeClient)
@@ -778,10 +818,13 @@ class TestInstanceCreation(testutils.GanetiTestCase):
       None,
       {},
       { constants.BE_VCPUS: 2, },
-      { constants.BE_MEMORY: 123, },
+      { constants.BE_MAXMEM: 200, },
+      { constants.BE_MEMORY: 256, },
       { constants.BE_VCPUS: 2,
-        constants.BE_MEMORY: 1024,
-        constants.BE_AUTO_BALANCE: True, }
+        constants.BE_MAXMEM: 1024,
+        constants.BE_MINMEM: 1024,
+        constants.BE_AUTO_BALANCE: True,
+        constants.BE_ALWAYS_FAILOVER: True, }
       ]
 
     hvparam_variants = [
@@ -1208,7 +1251,7 @@ class TestParseModifyInstanceRequest(unittest.TestCase):
 
     for osparams in [{}, { "some": "value", "other": "Hello World", }]:
       for hvparams in [{}, { constants.HV_KERNEL_PATH: "/some/kernel", }]:
-        for beparams in [{}, { constants.BE_MEMORY: 128, }]:
+        for beparams in [{}, { constants.BE_MAXMEM: 128, }]:
           for force in [False, True]:
             for nics in [[], [(0, { constants.INIC_IP: "192.0.2.1", })]]:
               for disks in test_disks:
@@ -1321,7 +1364,8 @@ class TestParseInstanceReinstallRequest(testutils.GanetiTestCase):
     self.assertFalse(ops[1].osparams)
 
   def testErrors(self):
-    self.assertRaises(http.HttpBadRequest, self.Parse, "foo", "not a dictionary")
+    self.assertRaises(http.HttpBadRequest, self.Parse,
+                      "foo", "not a dictionary")
 
 
 class TestGroupRename(unittest.TestCase):
@@ -1430,6 +1474,20 @@ class TestInstanceReplaceDisks(unittest.TestCase):
     self.assertFalse(hasattr(op, "disks"))
     self.assertRaises(IndexError, cl.GetNextSubmittedJob)
 
+  def testNoDisks(self):
+    clfactory = _FakeClientFactory(_FakeClient)
+
+    handler = _CreateHandler(rlib2.R_2_instances_name_replace_disks,
+                             ["inst20661"], {}, {}, clfactory)
+    self.assertRaises(http.HttpBadRequest, handler.POST)
+
+    for disks in [None, "", {}]:
+      handler = _CreateHandler(rlib2.R_2_instances_name_replace_disks,
+                               ["inst20661"], {}, {
+        "disks": disks,
+        }, clfactory)
+      self.assertRaises(http.HttpBadRequest, handler.POST)
+
   def testWrong(self):
     clfactory = _FakeClientFactory(_FakeClient)
 
@@ -1644,9 +1702,10 @@ class TestSimpleResources(unittest.TestCase):
     handler = _CreateHandler(rlib2.R_2_features, [], {}, None, self.clfactory)
     self.assertEqual(set(handler.GET()), rlib2.ALL_FEATURES)
 
-  def testRoot(self):
-    handler = _CreateHandler(rlib2.R_root, [], {}, None, self.clfactory)
-    self.assertTrue(handler.GET() is None)
+  def testEmpty(self):
+    for cls in [rlib2.R_root, rlib2.R_2]:
+      handler = _CreateHandler(cls, [], {}, None, self.clfactory)
+      self.assertTrue(handler.GET() is None)
 
   def testVersion(self):
     handler = _CreateHandler(rlib2.R_version, [], {}, None, self.clfactory)