Spot check more hashes for increase_part_power

Just a touch of cleanup to the unittest to demonstrate the stability of the
guarantee that objects will hash to the same nodes but have different parts.

Change-Id: I4a24187755455366a6435816a138f6175ae713a4
This commit is contained in:
Clay Gerrard
2016-03-08 12:32:39 -08:00
parent 3ff94cb785
commit dc6db66d5e

View File

@@ -26,6 +26,7 @@ from math import ceil
from tempfile import mkdtemp from tempfile import mkdtemp
from shutil import rmtree from shutil import rmtree
import random import random
import uuid
from six.moves import range from six.moves import range
@@ -2450,6 +2451,7 @@ class TestRingBuilder(unittest.TestCase):
self.assertEqual(changed_parts, 0) self.assertEqual(changed_parts, 0)
self.assertEqual(removed_devs, 0) self.assertEqual(removed_devs, 0)
old_ring = r
rd = rb.get_ring() rd = rb.get_ring()
rd.save(ring_file) rd.save(ring_file)
r = ring.Ring(ring_file) r = ring.Ring(ring_file)
@@ -2468,18 +2470,25 @@ class TestRingBuilder(unittest.TestCase):
self.assertEqual(dev, next_dev) self.assertEqual(dev, next_dev)
# same for last_part moves # same for last_part moves
for part in range(0, len(replica), 2): for part in range(0, rb.parts, 2):
this_last_moved = rb._last_part_moves[part] this_last_moved = rb._last_part_moves[part]
next_last_moved = rb._last_part_moves[part + 1] next_last_moved = rb._last_part_moves[part + 1]
self.assertEqual(this_last_moved, next_last_moved) self.assertEqual(this_last_moved, next_last_moved)
# Due to the increased partition power, the partition each object is for i in range(100):
# assigned to has changed. If the old partition was X, it will now be suffix = uuid.uuid4()
# either located in 2*X or 2*X+1 account = 'account_%s' % suffix
container = 'container_%s' % suffix
obj = 'obj_%s' % suffix
old_part, old_nodes = old_ring.get_nodes(account, container, obj)
new_part, new_nodes = r.get_nodes(account, container, obj)
# Due to the increased partition power, the partition each object
# is assigned to has changed. If the old partition was X, it will
# now be either located in 2*X or 2*X+1
self.assertTrue(new_part in [old_part * 2, old_part * 2 + 1]) self.assertTrue(new_part in [old_part * 2, old_part * 2 + 1])
# Importantly, we expect the objects to be placed on the same nodes # Importantly, we expect the objects to be placed on the same
# after increasing the partition power # nodes after increasing the partition power
self.assertEqual(old_nodes, new_nodes) self.assertEqual(old_nodes, new_nodes)