self.assertEqual(2, self.client.GetVersion())
self.assertHandler(rlib2.R_version)
+ def testGetFeatures(self):
+ for features in [[], ["foo", "bar", "baz"]]:
+ self.rapi.AddResponse(serializer.DumpJson(features))
+ self.assertEqual(features, self.client.GetFeatures())
+ self.assertHandler(rlib2.R_2_features)
+
def testGetOperatingSystems(self):
self.rapi.AddResponse("[\"beos\"]")
self.assertEqual(["beos"], self.client.GetOperatingSystems())
self.assertHandler(rlib2.R_2_instances)
self.assertBulk()
- def testGetInstanceInfo(self):
+ def testGetInstance(self):
self.rapi.AddResponse("[]")
- self.assertEqual([], self.client.GetInstanceInfo("instance"))
+ self.assertEqual([], self.client.GetInstance("instance"))
self.assertHandler(rlib2.R_2_instances_name)
self.assertItems(["instance"])
+ def testGetInstanceInfo(self):
+ self.rapi.AddResponse("21291")
+ self.assertEqual(21291, self.client.GetInstanceInfo("inst3"))
+ self.assertHandler(rlib2.R_2_instances_name_info)
+ self.assertItems(["inst3"])
+ self.assertQuery("static", None)
+
+ self.rapi.AddResponse("3428")
+ self.assertEqual(3428, self.client.GetInstanceInfo("inst31", static=False))
+ self.assertHandler(rlib2.R_2_instances_name_info)
+ self.assertItems(["inst31"])
+ self.assertQuery("static", ["0"])
+
+ self.rapi.AddResponse("15665")
+ self.assertEqual(15665, self.client.GetInstanceInfo("inst32", static=True))
+ self.assertHandler(rlib2.R_2_instances_name_info)
+ self.assertItems(["inst32"])
+ self.assertQuery("static", ["1"])
+
+ def testCreateInstanceOldVersion(self):
+ self.rapi.AddResponse(serializer.DumpJson([]))
+ self.assertRaises(NotImplementedError, self.client.CreateInstance,
+ "create", "inst1.example.com", "plain", [], [],
+ dry_run=True)
+
def testCreateInstance(self):
- self.rapi.AddResponse("1234")
- self.assertEqual(1234, self.client.CreateInstance(dry_run=True))
+ self.rapi.AddResponse(serializer.DumpJson([rlib2._INST_CREATE_REQV1]))
+ self.rapi.AddResponse("23030")
+ job_id = self.client.CreateInstance("create", "inst1.example.com",
+ "plain", [], [], dry_run=True)
+ self.assertEqual(job_id, 23030)
self.assertHandler(rlib2.R_2_instances)
self.assertDryRun()
+ data = serializer.LoadJson(self.http.last_request.data)
+
+ for field in ["dry_run", "beparams", "hvparams", "start"]:
+ self.assertFalse(field in data)
+
+ self.assertEqual(data["name"], "inst1.example.com")
+ self.assertEqual(data["disk_template"], "plain")
+
+ def testCreateInstance2(self):
+ self.rapi.AddResponse(serializer.DumpJson([rlib2._INST_CREATE_REQV1]))
+ self.rapi.AddResponse("24740")
+ job_id = self.client.CreateInstance("import", "inst2.example.com",
+ "drbd8", [{"size": 100,}],
+ [{}, {"bridge": "br1", }],
+ dry_run=False, start=True,
+ pnode="node1", snode="node9",
+ ip_check=False)
+ self.assertEqual(job_id, 24740)
+ self.assertHandler(rlib2.R_2_instances)
+
+ data = serializer.LoadJson(self.http.last_request.data)
+ self.assertEqual(data[rlib2._REQ_DATA_VERSION], 1)
+ self.assertEqual(data["name"], "inst2.example.com")
+ self.assertEqual(data["disk_template"], "drbd8")
+ self.assertEqual(data["start"], True)
+ self.assertEqual(data["ip_check"], False)
+ self.assertEqualValues(data["disks"], [{"size": 100,}])
+ self.assertEqualValues(data["nics"], [{}, {"bridge": "br1", }])
+
def testDeleteInstance(self):
self.rapi.AddResponse("1234")
self.assertEqual(1234, self.client.DeleteInstance("instance", dry_run=True))
def testReplaceInstanceDisks(self):
self.rapi.AddResponse("999")
job_id = self.client.ReplaceInstanceDisks("instance-name",
- ["hda", "hdc"], dry_run=True, iallocator="hail")
+ disks=[0, 1], dry_run=True, iallocator="hail")
self.assertEqual(999, job_id)
self.assertHandler(rlib2.R_2_instances_name_replace_disks)
self.assertItems(["instance-name"])
- self.assertQuery("disks", ["hda,hdc"])
+ self.assertQuery("disks", ["0,1"])
self.assertQuery("mode", ["replace_auto"])
self.assertQuery("iallocator", ["hail"])
self.assertDryRun()
- self.assertRaises(client.InvalidReplacementMode,
- self.client.ReplaceInstanceDisks,
- "instance_a", ["hda"], mode="invalid_mode")
- self.assertRaises(client.GanetiApiError,
- self.client.ReplaceInstanceDisks,
- "instance-foo", ["hda"], mode="replace_on_secondary")
-
self.rapi.AddResponse("1000")
job_id = self.client.ReplaceInstanceDisks("instance-bar",
- ["hda"], mode="replace_on_secondary", remote_node="foo-node",
+ disks=[1], mode="replace_on_secondary", remote_node="foo-node",
dry_run=True)
self.assertEqual(1000, job_id)
self.assertItems(["instance-bar"])
- self.assertQuery("disks", ["hda"])
+ self.assertQuery("disks", ["1"])
self.assertQuery("remote_node", ["foo-node"])
self.assertDryRun()
+ self.rapi.AddResponse("5175")
+ self.assertEqual(5175, self.client.ReplaceInstanceDisks("instance-moo"))
+ self.assertItems(["instance-moo"])
+ self.assertQuery("disks", None)
+
+ def testPrepareExport(self):
+ self.rapi.AddResponse("8326")
+ self.assertEqual(8326, self.client.PrepareExport("inst1", "local"))
+ self.assertHandler(rlib2.R_2_instances_name_prepare_export)
+ self.assertItems(["inst1"])
+ self.assertQuery("mode", ["local"])
+
+ def testExportInstance(self):
+ self.rapi.AddResponse("19695")
+ job_id = self.client.ExportInstance("inst2", "local", "nodeX",
+ shutdown=True)
+ self.assertEqual(job_id, 19695)
+ self.assertHandler(rlib2.R_2_instances_name_export)
+ self.assertItems(["inst2"])
+
+ data = serializer.LoadJson(self.http.last_request.data)
+ self.assertEqual(data["mode"], "local")
+ self.assertEqual(data["destination"], "nodeX")
+ self.assertEqual(data["shutdown"], True)
+
def testGetJobs(self):
self.rapi.AddResponse('[ { "id": "123", "uri": "\\/2\\/jobs\\/123" },'
' { "id": "124", "uri": "\\/2\\/jobs\\/124" } ]')
self.assertHandler(rlib2.R_2_nodes)
self.assertBulk()
- def testGetNodeInfo(self):
+ def testGetNode(self):
self.rapi.AddResponse("{}")
- self.assertEqual({}, self.client.GetNodeInfo("node-foo"))
+ self.assertEqual({}, self.client.GetNode("node-foo"))
self.assertHandler(rlib2.R_2_nodes_name)
self.assertItems(["node-foo"])
self.assertQuery("force", ["1"])
self.assertEqual("\"master-candidate\"", self.http.last_request.data)
- self.assertRaises(client.InvalidNodeRole,
- self.client.SetNodeRole, "node-bar", "fake-role")
-
def testGetNodeStorageUnits(self):
self.rapi.AddResponse("42")
self.assertEqual(42,
self.assertItems(["node-z"])
self.assertQuery("storage_type", ["lvm-pv"])
self.assertQuery("name", ["hda"])
+ self.assertQuery("allocatable", None)
+
+ for allocatable, query_allocatable in [(True, "1"), (False, "0")]:
+ self.rapi.AddResponse("7205")
+ job_id = self.client.ModifyNodeStorageUnits("node-z", "lvm-pv", "hda",
+ allocatable=allocatable)
+ self.assertEqual(7205, job_id)
+ self.assertHandler(rlib2.R_2_nodes_name_storage_modify)
+ self.assertItems(["node-z"])
+ self.assertQuery("storage_type", ["lvm-pv"])
+ self.assertQuery("name", ["hda"])
+ self.assertQuery("allocatable", [query_allocatable])
def testRepairNodeStorageUnits(self):
self.rapi.AddResponse("99")