Make more use of get_partition_for_hash in unit tests

Refactor to make more use of the utils.get_partition_for_hash() helper
function that was added in [1].

[1] Related-Change: I5fbf8671f2ee63467d46f651e2c24529a2697626

Change-Id: I0d3c4cae88ed50a09e892e6d77b5aaa96e6195a5
This commit is contained in:
Alistair Coles 2021-03-17 12:43:53 +00:00
parent 354a86a80e
commit acf72e8803
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
@ -4791,9 +4790,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)
@ -4814,9 +4812,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,