misc test cleanup

Change-Id: I21823e50af6d60bb5ee02427ddc499d700c43577
Related-Change: Ib33ff305615b2d342f0d673ded5ed8f11b663feb
Related-Change: I0855d8a549d1272d056963abed03338f80d68a53
This commit is contained in:
Tim Burke 2019-01-15 22:00:14 +00:00
parent 9aa4cafa0e
commit 1d4309dd71
2 changed files with 38 additions and 39 deletions

View File

@ -3454,8 +3454,8 @@ class TestObjectReconstructor(BaseTestObjectReconstructor):
'123': {job['frag_index']: 'hash', None: 'hash'},
'abc': {job['frag_index']: 'hash', None: 'hash'},
}
remote_index = (
job['frag_index'] - 1) % self.policy.ec_n_unique_fragments
self.assertEqual(node['index'], self.policy.object_ring.replicas - 1)
remote_index = self.policy.get_backend_index(node['index'])
remote_hashes = {
'123': {remote_index: 'hash', None: 'hash'},
'abc': {remote_index: 'hash', None: 'hash'},
@ -3518,15 +3518,15 @@ class TestObjectReconstructor(BaseTestObjectReconstructor):
'123': {frag_index: 'hash', None: 'hash'},
'abc': {frag_index: 'hash', None: 'hash'},
}
left_index = self.policy.get_backend_index(sync_to[0]['index'])
left_frag_index = self.policy.get_backend_index(sync_to[0]['index'])
left_hashes = {
'123': {left_index: 'hash', None: 'hash'},
'abc': {left_index: 'hash', None: 'hash'},
'123': {left_frag_index: 'hash', None: 'hash'},
'abc': {left_frag_index: 'hash', None: 'hash'},
}
right_index = self.policy.get_backend_index(sync_to[1]['index'])
right_frag_index = self.policy.get_backend_index(sync_to[1]['index'])
right_hashes = {
'123': {right_index: 'hash', None: 'hash'},
'abc': {right_index: 'hash', None: 'hash'},
'123': {right_frag_index: 'hash', None: 'hash'},
'abc': {right_frag_index: 'hash', None: 'hash'},
}
partition = 0
part_path = os.path.join(self.devices, self.local_dev['device'],
@ -3641,16 +3641,17 @@ class TestObjectReconstructor(BaseTestObjectReconstructor):
'abc': {frag_index: 'hash', None: 'hash'},
}
# left hand side is in sync
left_index = self.policy.get_backend_index(sync_to[0]['index'])
left_frag_index = self.policy.get_backend_index(sync_to[0]['index'])
left_hashes = {
'123': {left_index: 'hash', None: 'hash'},
'abc': {left_index: 'hash', None: 'hash'},
'123': {left_frag_index: 'hash', None: 'hash'},
'abc': {left_frag_index: 'hash', None: 'hash'},
}
# right hand side has fragment, but no durable (None key is whack)
right_index = self.policy.get_backend_index(sync_to[1]['index'])
right_frag_index = self.policy.get_backend_index(sync_to[1]['index'])
right_hashes = {
'123': {right_index: 'hash', None: 'hash'},
'abc': {right_index: 'hash', None: 'different-because-durable'},
'123': {right_frag_index: 'hash', None: 'hash'},
'abc': {right_frag_index: 'hash',
None: 'different-because-durable'},
}
part_path = os.path.join(self.devices, self.local_dev['device'],
@ -3709,14 +3710,14 @@ class TestObjectReconstructor(BaseTestObjectReconstructor):
'123': {frag_index: 'hash', None: 'hash'},
'abc': {frag_index: 'hash', None: 'hash'},
}
left_index = self.policy.get_backend_index(sync_to[0]['index'])
left_frag_index = self.policy.get_backend_index(sync_to[0]['index'])
left_hashes = {
'123': {left_index: 'hashX', None: 'hash'},
'abc': {left_index: 'hash', None: 'hash'},
'123': {left_frag_index: 'hashX', None: 'hash'},
'abc': {left_frag_index: 'hash', None: 'hash'},
}
right_index = self.policy.get_backend_index(sync_to[1]['index'])
right_frag_index = self.policy.get_backend_index(sync_to[1]['index'])
right_hashes = {
'123': {right_index: 'hash', None: 'hash'},
'123': {right_frag_index: 'hash', None: 'hash'},
}
part_path = os.path.join(self.devices, self.local_dev['device'],
diskfile.get_data_dir(self.policy),

View File

@ -2088,32 +2088,30 @@ class TestECObjController(ECObjectControllerMixin, unittest.TestCase):
# create a dummy list of putters, check no handoffs
putters = []
for index in range(self.policy.object_ring.replica_count):
putters.append(FakePutter(index))
got = controller._determine_chunk_destinations(putters, self.policy)
expected = {}
for i, p in enumerate(putters):
expected[p] = i
for index in range(self.policy.object_ring.replica_count):
p = FakePutter(index)
putters.append(p)
expected[p] = self.policy.get_backend_index(index)
got = controller._determine_chunk_destinations(putters, self.policy)
self.assertEqual(got, expected)
def _test_one_handoff(index):
with mock.patch.object(putters[index], 'node_index', None):
got = controller._determine_chunk_destinations(
putters, self.policy)
self.assertEqual(got, expected)
# Check that we don't mutate the putter
self.assertEqual([p.node_index for p in putters],
[None if i == index else i
for i, _ in enumerate(putters)])
# now lets make a handoff at the end
orig_index = putters[-1].node_index
putters[-1].node_index = None
got = controller._determine_chunk_destinations(putters, self.policy)
self.assertEqual(got, expected)
putters[-1].node_index = orig_index
_test_one_handoff(self.policy.object_ring.replica_count - 1)
# now lets make a handoff at the start
putters[0].node_index = None
got = controller._determine_chunk_destinations(putters, self.policy)
self.assertEqual(got, expected)
putters[0].node_index = 0
_test_one_handoff(0)
# now lets make a handoff in the middle
putters[2].node_index = None
got = controller._determine_chunk_destinations(putters, self.policy)
self.assertEqual(got, expected)
putters[2].node_index = 2
_test_one_handoff(2)
# now lets make all of them handoffs
for index in range(self.policy.object_ring.replica_count):