Commit 3d835d1b authored by Thomas Thrainer's avatar Thomas Thrainer
Browse files

Fix tests related to the physical_id field



Remove all references to the physical_id field of disk objects in tests.
Signed-off-by: default avatarThomas Thrainer <thomasth@google.com>
Reviewed-by: default avatarJose A. Lopes <jabolopes@google.com>
parent a57e502a
......@@ -1249,10 +1249,6 @@ class _ConfigForDiskWipe:
def __init__(self, exp_node_uuid):
self._exp_node_uuid = exp_node_uuid
def SetDiskID(self, device, node_uuid):
assert isinstance(device, objects.Disk)
assert node_uuid == self._exp_node_uuid
def GetNodeName(self, node_uuid):
assert node_uuid == self._exp_node_uuid
return "name.of.expected.node"
......
......@@ -303,16 +303,16 @@ class TestGetConfigFileDiskData(unittest.TestCase):
def testFileDisks(self):
disks = [
(objects.Disk(dev_type=constants.DT_FILE, mode=constants.DISK_RDWR,
physical_id=[constants.FD_LOOP]),
logical_id=[constants.FD_LOOP]),
"/tmp/diskFirst"),
(objects.Disk(dev_type=constants.DT_FILE, mode=constants.DISK_RDONLY,
physical_id=[constants.FD_BLKTAP]),
logical_id=[constants.FD_BLKTAP]),
"/tmp/diskTwo"),
(objects.Disk(dev_type=constants.DT_FILE, mode=constants.DISK_RDWR,
physical_id=[constants.FD_LOOP]),
logical_id=[constants.FD_LOOP]),
"/tmp/diskThree"),
(objects.Disk(dev_type=constants.DT_FILE, mode=constants.DISK_RDWR,
physical_id=[constants.FD_BLKTAP]),
logical_id=[constants.FD_BLKTAP]),
"/tmp/diskLast"),
]
......@@ -327,7 +327,7 @@ class TestGetConfigFileDiskData(unittest.TestCase):
def testInvalidFileDisk(self):
disks = [
(objects.Disk(dev_type=constants.DT_FILE, mode=constants.DISK_RDWR,
physical_id=["#unknown#"]),
logical_id=["#unknown#"]),
"/tmp/diskinvalid"),
]
......
......@@ -481,11 +481,11 @@ class TestNodeConfigResolver(unittest.TestCase):
class TestCompress(unittest.TestCase):
def test(self):
for data in ["", "Hello", "Hello World!\nnew\nlines"]:
self.assertEqual(rpc._Compress(data),
self.assertEqual(rpc._Compress(NotImplemented, data),
(constants.RPC_ENCODING_NONE, data))
for data in [512 * " ", 5242 * "Hello World!\n"]:
compressed = rpc._Compress(data)
compressed = rpc._Compress(NotImplemented, data)
self.assertEqual(len(compressed), 2)
self.assertEqual(backend._Decompress(compressed), data)
......@@ -566,8 +566,8 @@ class TestRpcClientBase(unittest.TestCase):
]
encoders = {
AT1: hex,
AT2: hash,
AT1: lambda _, value: hex(value),
AT2: lambda _, value: hash(value),
}
cdef = ("test_call", NotImplemented, None, constants.RPC_TMO_NORMAL, [
......@@ -720,6 +720,9 @@ class _FakeConfigForRpcRunner:
def GetNodeInfo(self, name):
return objects.Node(name=name)
def GetMultiNodeInfo(self, names):
return [(name, self.GetNodeInfo(name)) for name in names]
def GetClusterInfo(self):
return self._cluster
......@@ -736,11 +739,15 @@ class TestRpcRunner(unittest.TestCase):
tmpfile.flush()
st = os.stat(tmpfile.name)
nodes = [
"node1.example.com",
]
def _VerifyRequest(req):
(uldata, ) = serializer.LoadJson(req.post_data)
self.assertEqual(len(uldata), 7)
self.assertEqual(uldata[0], tmpfile.name)
self.assertEqual(list(uldata[1]), list(rpc._Compress(data)))
self.assertEqual(list(uldata[1]), list(rpc._Compress(nodes[0], data)))
self.assertEqual(uldata[2], st.st_mode)
self.assertEqual(uldata[3], "user%s" % os.getuid())
self.assertEqual(uldata[4], "group%s" % os.getgid())
......@@ -761,10 +768,6 @@ class TestRpcRunner(unittest.TestCase):
_req_process_fn=http_proc,
_getents=mocks.FakeGetentResolver)
nodes = [
"node1.example.com",
]
for runner in [std_runner, cfg_runner]:
result = runner.call_upload_file(nodes, tmpfile.name)
self.assertEqual(len(result), len(nodes))
......@@ -832,14 +835,15 @@ class TestRpcRunner(unittest.TestCase):
"mymode")
# Generic object serialization
result = runner._encoder((rpc_defs.ED_OBJECT_DICT, inst))
result = runner._encoder(NotImplemented, (rpc_defs.ED_OBJECT_DICT, inst))
_CheckBasics(result)
result = runner._encoder((rpc_defs.ED_OBJECT_DICT_LIST, 5 * [inst]))
result = runner._encoder(NotImplemented,
(rpc_defs.ED_OBJECT_DICT_LIST, 5 * [inst]))
map(_CheckBasics, result)
# Just an instance
result = runner._encoder((rpc_defs.ED_INST_DICT, inst))
result = runner._encoder(NotImplemented, (rpc_defs.ED_INST_DICT, inst))
_CheckBasics(result)
self.assertEqual(result["beparams"][constants.BE_MAXMEM], 256)
self.assertEqual(result["hvparams"][constants.HT_KVM], {
......@@ -851,10 +855,11 @@ class TestRpcRunner(unittest.TestCase):
})
# Instance with OS parameters
result = runner._encoder((rpc_defs.ED_INST_DICT_OSP_DP, (inst, {
"role": "webserver",
"other": "field",
})))
result = runner._encoder(NotImplemented,
(rpc_defs.ED_INST_DICT_OSP_DP, (inst, {
"role": "webserver",
"other": "field",
})))
_CheckBasics(result)
self.assertEqual(result["beparams"][constants.BE_MAXMEM], 256)
self.assertEqual(result["hvparams"][constants.HT_KVM], {
......@@ -867,7 +872,8 @@ class TestRpcRunner(unittest.TestCase):
})
# Instance with hypervisor and backend parameters
result = runner._encoder((rpc_defs.ED_INST_DICT_HVP_BEP_DP, (inst, {
result = runner._encoder(NotImplemented,
(rpc_defs.ED_INST_DICT_HVP_BEP_DP, (inst, {
constants.HT_KVM: {
constants.HV_BOOT_ORDER: "xyz",
},
......@@ -883,11 +889,13 @@ class TestRpcRunner(unittest.TestCase):
})
self.assertEqual(result["disks"], [{
"dev_type": constants.DT_PLAIN,
"dynamic_params": {},
"size": 4096,
"logical_id": ("vg", "disk6120"),
"params": constants.DISK_DT_DEFAULTS[inst.disk_template],
}, {
"dev_type": constants.DT_PLAIN,
"dynamic_params": {},
"size": 1024,
"logical_id": ("vg", "disk8508"),
"params": constants.DISK_DT_DEFAULTS[inst.disk_template],
......
......@@ -419,12 +419,18 @@ class TestDRBD8Construction(testutils.GanetiTestCase):
filename=testutils.TestDataFilename("proc_drbd84.txt"))
self.test_unique_id = ("hosta.com", 123, "host2.com", 123, 0, "secret")
self.test_dyn_params = {
constants.DDP_LOCAL_IP: "192.0.2.1",
constants.DDP_LOCAL_MINOR: 0,
constants.DDP_REMOTE_IP: "192.0.2.2",
constants.DDP_REMOTE_MINOR: 0,
}
@testutils.patch_object(drbd.DRBD8, "GetProcInfo")
def testConstructionWith80Data(self, mock_create_from_file):
mock_create_from_file.return_value = self.proc80_info
inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {})
inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {}, self.test_dyn_params)
self.assertEqual(inst._show_info_cls, drbd_info.DRBD83ShowInfo)
self.assertTrue(isinstance(inst._cmd_gen, drbd_cmdgen.DRBD83CmdGenerator))
......@@ -432,7 +438,7 @@ class TestDRBD8Construction(testutils.GanetiTestCase):
def testConstructionWith83Data(self, mock_create_from_file):
mock_create_from_file.return_value = self.proc83_info
inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {})
inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {}, self.test_dyn_params)
self.assertEqual(inst._show_info_cls, drbd_info.DRBD83ShowInfo)
self.assertTrue(isinstance(inst._cmd_gen, drbd_cmdgen.DRBD83CmdGenerator))
......@@ -440,7 +446,7 @@ class TestDRBD8Construction(testutils.GanetiTestCase):
def testConstructionWith84Data(self, mock_create_from_file):
mock_create_from_file.return_value = self.proc84_info
inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {})
inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {}, self.test_dyn_params)
self.assertEqual(inst._show_info_cls, drbd_info.DRBD84ShowInfo)
self.assertTrue(isinstance(inst._cmd_gen, drbd_cmdgen.DRBD84CmdGenerator))
......
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