Commit 52a988f2 authored by Michele Tartara's avatar Michele Tartara
Browse files

Fix testEncodeInstance test input



The input of the testEncodeInstance test was not adherent to the actual format
of the Ganeti configuration file: kvm has no HV_BLOCKDEV_PREFIX, and "hvparams"
inside an instance should only contain the values of the hypervisor parameters,
not the hypervisor name, which is already declared in the "hypervisor" field,
and which was not correctly aligned with the parameters in the "hvparams"
section.

All these problems are now fixed, and the assertions are changed accordingly.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 3eaa6e1d
......@@ -774,7 +774,7 @@ class TestRpcRunner(unittest.TestCase):
def testEncodeInstance(self):
cluster = objects.Cluster(hvparams={
constants.HT_KVM: {
constants.HV_BLOCKDEV_PREFIX: "foo",
constants.HV_CDROM_IMAGE_PATH: "foo",
},
},
beparams={
......@@ -791,13 +791,11 @@ class TestRpcRunner(unittest.TestCase):
cluster.UpgradeConfig()
inst = objects.Instance(name="inst1.example.com",
hypervisor=constants.HT_FAKE,
hypervisor=constants.HT_KVM,
os="linux",
hvparams={
constants.HT_KVM: {
constants.HV_BLOCKDEV_PREFIX: "bar",
constants.HV_ROOT_PATH: "/tmp",
},
constants.HV_CDROM_IMAGE_PATH: "bar",
constants.HV_ROOT_PATH: "/tmp",
},
beparams={
constants.BE_MINMEM: 128,
......@@ -826,7 +824,6 @@ class TestRpcRunner(unittest.TestCase):
self.assertEqual(result["name"], "inst1.example.com")
self.assertEqual(result["os"], "linux")
self.assertEqual(result["beparams"][constants.BE_MINMEM], 128)
self.assertEqual(len(result["hvparams"]), 1)
self.assertEqual(len(result["nics"]), 1)
self.assertEqual(result["nics"][0]["nicparams"][constants.NIC_MODE],
"mymode")
......@@ -834,21 +831,23 @@ class TestRpcRunner(unittest.TestCase):
# Generic object serialization
result = runner._encoder((rpc_defs.ED_OBJECT_DICT, inst))
_CheckBasics(result)
self.assertEqual(len(result["hvparams"]), 2)
result = runner._encoder((rpc_defs.ED_OBJECT_DICT_LIST, 5 * [inst]))
map(_CheckBasics, result)
map(lambda r: self.assertEqual(len(r["hvparams"]), 2), result)
# Just an instance
result = runner._encoder((rpc_defs.ED_INST_DICT, inst))
_CheckBasics(result)
self.assertEqual(result["beparams"][constants.BE_MAXMEM], 256)
self.assertEqual(result["hvparams"][constants.HT_KVM], {
constants.HV_BLOCKDEV_PREFIX: "bar",
constants.HV_ROOT_PATH: "/tmp",
})
self.assertEqual(result["hvparams"][constants.HV_CDROM_IMAGE_PATH], "bar")
self.assertEqual(result["hvparams"][constants.HV_ROOT_PATH], "/tmp")
self.assertEqual(result["osparams"], {
"role": "unknown",
})
self.assertEqual(len(result["hvparams"]),
len(constants.HVC_DEFAULTS[constants.HT_KVM]))
# Instance with OS parameters
result = runner._encoder((rpc_defs.ED_INST_DICT_OSP_DP, (inst, {
......@@ -857,10 +856,8 @@ class TestRpcRunner(unittest.TestCase):
})))
_CheckBasics(result)
self.assertEqual(result["beparams"][constants.BE_MAXMEM], 256)
self.assertEqual(result["hvparams"][constants.HT_KVM], {
constants.HV_BLOCKDEV_PREFIX: "bar",
constants.HV_ROOT_PATH: "/tmp",
})
self.assertEqual(result["hvparams"][constants.HV_CDROM_IMAGE_PATH], "bar")
self.assertEqual(result["hvparams"][constants.HV_ROOT_PATH], "/tmp")
self.assertEqual(result["osparams"], {
"role": "webserver",
"other": "field",
......@@ -868,9 +865,7 @@ class TestRpcRunner(unittest.TestCase):
# Instance with hypervisor and backend parameters
result = runner._encoder((rpc_defs.ED_INST_DICT_HVP_BEP_DP, (inst, {
constants.HT_KVM: {
constants.HV_BOOT_ORDER: "xyz",
},
constants.HV_BOOT_ORDER: "xyz",
}, {
constants.BE_VCPUS: 100,
constants.BE_MAXMEM: 4096,
......@@ -878,9 +873,7 @@ class TestRpcRunner(unittest.TestCase):
_CheckBasics(result)
self.assertEqual(result["beparams"][constants.BE_MAXMEM], 4096)
self.assertEqual(result["beparams"][constants.BE_VCPUS], 100)
self.assertEqual(result["hvparams"][constants.HT_KVM], {
constants.HV_BOOT_ORDER: "xyz",
})
self.assertEqual(result["hvparams"][constants.HV_BOOT_ORDER], "xyz")
self.assertEqual(result["disks"], [{
"dev_type": constants.DT_PLAIN,
"size": 4096,
......
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