Merge "Make more use of get_partition_for_hash in unit tests"

This commit is contained in:
Zuul 2021-03-17 19:34:59 +00:00 committed by Gerrit Code Review
commit 05284376e3
2 changed files with 6 additions and 12 deletions

View File

@ -11,7 +11,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import binascii
import errno
import fcntl
import json
@ -23,7 +22,6 @@ import mock
import os
import pickle
import shutil
import struct
import tempfile
import unittest
import uuid
@ -78,9 +76,8 @@ class TestRelinker(unittest.TestCase):
container = 'c'
obj = 'o-' + str(uuid.uuid4())
self._hash = utils.hash_path(account, container, obj)
digest = binascii.unhexlify(self._hash)
self.part = struct.unpack_from('>I', digest)[0] >> 24
self.next_part = struct.unpack_from('>I', digest)[0] >> 23
self.part = utils.get_partition_for_hash(self._hash, 8)
self.next_part = utils.get_partition_for_hash(self._hash, 9)
self.obj_path = os.path.join(os.path.sep, account, container, obj)
# There's 1/512 chance that both old and new parts will be 0;
# that's not a terribly interesting case, as there's nothing to do

View File

@ -29,7 +29,6 @@ import uuid
import xattr
import re
import six
import struct
from collections import defaultdict
from random import shuffle, randint
from shutil import rmtree
@ -4790,9 +4789,8 @@ class DiskFileMixin(BaseDiskFileTestMixin):
# DiskFile: first cleanup the current directory, but also cleanup the
# previous old directory
for policy in POLICIES:
digest = utils.hash_path(
'a', 'c', 'o_%s' % policy, raw_digest=True)
partition = struct.unpack_from('>I', digest)[0] >> (32 - 10)
hash_path = utils.hash_path('a', 'c', 'o_%s' % policy)
partition = utils.get_partition_for_hash(hash_path, 10)
timestamp = Timestamp(time()).internal
df_dir = self._create_diskfile_dir(
timestamp, policy, partition=partition, next_part_power=10)
@ -4812,9 +4810,8 @@ class DiskFileMixin(BaseDiskFileTestMixin):
def test_killed_before_cleanup(self, mock_cleanup):
for policy in POLICIES:
timestamp = Timestamp(time()).internal
digest = utils.hash_path(
'a', 'c', 'o_%s' % policy, raw_digest=True)
partition = struct.unpack_from('>I', digest)[0] >> (32 - 10)
hash_path = utils.hash_path('a', 'c', 'o_%s' % policy)
partition = utils.get_partition_for_hash(hash_path, 10)
df_dir = self._create_diskfile_dir(timestamp, policy,
partition=partition,
next_part_power=11,