Merge "Revert "Make the InstanceMapping marker UUID-like""
This commit is contained in:
commit
9e328b7bb4
@ -111,20 +111,6 @@ def _db_error(caught_exception):
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _uuid_shift(uuid):
|
||||
"""We need a way to non-destructively modify UUIDs so that we can store a
|
||||
marker without having duplicate InstanceMapping entries. This accomplishes
|
||||
this by applying a ROT8 mapping to the non-dash characters in a UUID.
|
||||
Calling _uuid_shift twice returns the value to the original UUID.
|
||||
"""
|
||||
mapper = {"0": "8", "1": "9", "2": "a", "3": "b", "4": "c", "5": "d",
|
||||
"6": "e", "7": "f", "8": "0", "9": "1", "a": "2", "b": "3",
|
||||
"c": "4", "d": "5", "e": "6", "f": "7", "-": "-"}
|
||||
return "".join([mapper[char] for char in uuid])
|
||||
# Since shifting twice returns you to the original, we can alias.
|
||||
_uuid_unshift = _uuid_shift
|
||||
|
||||
|
||||
class FloatingIpCommands(object):
|
||||
"""Class for managing floating IP."""
|
||||
|
||||
@ -1182,7 +1168,7 @@ class CellV2Commands(object):
|
||||
marker = None
|
||||
else:
|
||||
# There should be only one here
|
||||
marker = _uuid_unshift(marker_mapping[0].instance_uuid)
|
||||
marker = marker_mapping[0].instance_uuid.replace(' ', '-')
|
||||
marker_mapping[0].destroy()
|
||||
|
||||
next_marker = True
|
||||
@ -1196,7 +1182,7 @@ class CellV2Commands(object):
|
||||
if next_marker:
|
||||
# Don't judge me. There's already an InstanceMapping with this UUID
|
||||
# so the marker needs to be non destructively modified.
|
||||
next_marker = _uuid_shift(next_marker)
|
||||
next_marker = next_marker.replace('-', ' ')
|
||||
objects.InstanceMapping(ctxt, instance_uuid=next_marker,
|
||||
project_id=marker_project_id).create()
|
||||
return 1
|
||||
|
@ -75,17 +75,6 @@ class UtilitiesTestCase(test.NoDBTestCase):
|
||||
url4_safe,
|
||||
manage.mask_passwd_in_url(url4))
|
||||
|
||||
def test_shift_uuid(self):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
shifted = manage._uuid_shift(uuid)
|
||||
self.assertTrue(uuidutils.is_uuid_like(shifted))
|
||||
unshifted = manage._uuid_unshift(shifted)
|
||||
self.assertEqual(uuid, unshifted)
|
||||
# Verify that shifting twice results in no change to the original
|
||||
uuid = uuidutils.generate_uuid()
|
||||
double_shift = manage._uuid_shift(manage._uuid_shift(uuid))
|
||||
self.assertEqual(uuid, double_shift)
|
||||
|
||||
|
||||
class FloatingIpCommandsTestCase(test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
@ -1266,7 +1255,7 @@ class CellV2CommandsTestCase(test.NoDBTestCase):
|
||||
|
||||
# Instances are mapped in the order created so we know the marker is
|
||||
# based off the third instance.
|
||||
marker = manage._uuid_shift(instance_uuids[2])
|
||||
marker = instance_uuids[2].replace('-', ' ')
|
||||
marker_mapping = objects.InstanceMapping.get_by_instance_uuid(ctxt,
|
||||
marker)
|
||||
marker_mapping.destroy()
|
||||
|
Loading…
Reference in New Issue
Block a user