From acf72e88030901473470934be9e1ea060684f946 Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Wed, 17 Mar 2021 12:43:53 +0000 Subject: [PATCH] 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 --- test/unit/cli/test_relinker.py | 7 ++----- test/unit/obj/test_diskfile.py | 11 ++++------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/test/unit/cli/test_relinker.py b/test/unit/cli/test_relinker.py index dd905f3b1e..75dd13b67a 100644 --- a/test/unit/cli/test_relinker.py +++ b/test/unit/cli/test_relinker.py @@ -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 diff --git a/test/unit/obj/test_diskfile.py b/test/unit/obj/test_diskfile.py index 3727191d6d..e9c1112e16 100644 --- a/test/unit/obj/test_diskfile.py +++ b/test/unit/obj/test_diskfile.py @@ -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,