From cff7455a689e452d12e85eec69137b3a3e0ec803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20L=C3=A9cuyer?= Date: Tue, 21 Mar 2017 09:54:33 +0100 Subject: [PATCH] Remove unused returned value object_path from yield_hashes() Some public functions in the diskfile manager expect or return full file paths. It implies a filesystem diskfile implementation. To make it easier to plug alternate diskfile implementations, patch functions to take more generic arguments. This commit changes DiskFileManager yield_hashes() returned values from: - object_path, object_hash, timestamps to: - object_hash, timestamps object_path was not used by any caller. Change-Id: I914fb1ec8ce7c9c26d22e1d07f03bd03f4504176 --- swift/obj/diskfile.py | 4 ++-- swift/obj/ssync_sender.py | 6 +++--- test/unit/obj/test_diskfile.py | 2 +- test/unit/obj/test_reconstructor.py | 2 +- test/unit/obj/test_ssync_sender.py | 24 ------------------------ 5 files changed, 7 insertions(+), 31 deletions(-) diff --git a/swift/obj/diskfile.py b/swift/obj/diskfile.py index bf0ae8a0b4..9ad9f04919 100644 --- a/swift/obj/diskfile.py +++ b/swift/obj/diskfile.py @@ -1351,7 +1351,7 @@ class BaseDiskFileManager(object): def yield_hashes(self, device, partition, policy, suffixes=None, **kwargs): """ - Yields tuples of (full_path, hash_only, timestamps) for object + Yields tuples of (hash_only, timestamps) for object information stored for the given device, partition, and (optionally) suffixes. If suffixes is None, all stored suffixes will be searched for object hashes. Note that if @@ -1407,7 +1407,7 @@ class BaseDiskFileManager(object): # file cannot be opened and therefore cannot # be ssync'd continue - yield (object_path, object_hash, timestamps) + yield (object_hash, timestamps) except AssertionError as err: self.logger.debug('Invalid file set in %s (%s)' % ( object_path, err)) diff --git a/swift/obj/ssync_sender.py b/swift/obj/ssync_sender.py index 5bf7f153d9..fcdc0496c9 100644 --- a/swift/obj/ssync_sender.py +++ b/swift/obj/ssync_sender.py @@ -271,10 +271,10 @@ class Sender(object): frag_index=self.job.get('frag_index')) if self.remote_check_objs is not None: hash_gen = six.moves.filter( - lambda path_objhash_timestamps: - path_objhash_timestamps[1] in + lambda objhash_timestamps: + objhash_timestamps[0] in self.remote_check_objs, hash_gen) - for path, object_hash, timestamps in hash_gen: + for object_hash, timestamps in hash_gen: self.available_map[object_hash] = timestamps with exceptions.MessageTimeout( self.daemon.node_timeout, diff --git a/test/unit/obj/test_diskfile.py b/test/unit/obj/test_diskfile.py index e79c3308c3..37080e42ab 100644 --- a/test/unit/obj/test_diskfile.py +++ b/test/unit/obj/test_diskfile.py @@ -1183,7 +1183,7 @@ class DiskFileManagerMixin(BaseDiskFileTestMixin): return files self.fail('Unexpected listdir of %r' % path) expected_items = [ - (os.path.join(part_path, hash_[-3:], hash_), hash_, timestamps) + (hash_, timestamps) for hash_, timestamps in expected.items()] with mock.patch('os.listdir', _listdir), \ mock.patch('os.unlink'): diff --git a/test/unit/obj/test_reconstructor.py b/test/unit/obj/test_reconstructor.py index d2814b52fb..e2fc8157d2 100644 --- a/test/unit/obj/test_reconstructor.py +++ b/test/unit/obj/test_reconstructor.py @@ -909,7 +909,7 @@ class TestGlobalSetupObjectReconstructor(unittest.TestCase): self.job['policy'], self.suffixes, frag_index=self.job.get('frag_index')) self.available_map = {} - for path, hash_, timestamps in hash_gen: + for hash_, timestamps in hash_gen: self.available_map[hash_] = timestamps context['available_map'] = self.available_map ssync_calls.append(context) diff --git a/test/unit/obj/test_ssync_sender.py b/test/unit/obj/test_ssync_sender.py index ab9053bd13..fe718a2370 100644 --- a/test/unit/obj/test_ssync_sender.py +++ b/test/unit/obj/test_ssync_sender.py @@ -433,8 +433,6 @@ class TestSender(BaseTest): if device == 'dev' and partition == '9' and suffixes == ['abc'] \ and policy == POLICIES.legacy: yield ( - '/srv/node/dev/objects/9/abc/' - '9d41d8cd98f00b204e9800998ecf0abc', '9d41d8cd98f00b204e9800998ecf0abc', {'ts_data': Timestamp(1380144470.00000), 'ts_meta': Timestamp(1380155570.00005)}) @@ -483,8 +481,6 @@ class TestSender(BaseTest): if device == 'dev' and partition == '9' and suffixes == ['abc'] \ and policy == POLICIES.legacy: yield ( - '/srv/node/dev/objects/9/abc/' - '9d41d8cd98f00b204e9800998ecf0abc', '9d41d8cd98f00b204e9800998ecf0abc', {'ts_data': Timestamp(1380144470.00000)}) else: @@ -521,8 +517,6 @@ class TestSender(BaseTest): if device == 'dev' and partition == '9' and suffixes == ['abc'] \ and policy == POLICIES.legacy: yield ( - '/srv/node/dev/objects/9/abc/' - '9d41d8cd98f00b204e9800998ecf0abc', '9d41d8cd98f00b204e9800998ecf0abc', {'ts_data': Timestamp(1380144470.00000)}) else: @@ -557,8 +551,6 @@ class TestSender(BaseTest): if device == 'dev' and partition == '9' and suffixes == ['abc'] \ and policy == POLICIES.legacy: yield ( - '/srv/node/dev/objects/9/abc/' - '9d41d8cd98f00b204e9800998ecf0abc', '9d41d8cd98f00b204e9800998ecf0abc', {'ts_data': Timestamp(1380144470.00000)}) else: @@ -758,19 +750,13 @@ class TestSender(BaseTest): policy == POLICIES.legacy and suffixes == ['abc', 'def']): yield ( - '/srv/node/dev/objects/9/abc/' - '9d41d8cd98f00b204e9800998ecf0abc', '9d41d8cd98f00b204e9800998ecf0abc', {'ts_data': Timestamp(1380144470.00000)}) yield ( - '/srv/node/dev/objects/9/def/' - '9d41d8cd98f00b204e9800998ecf0def', '9d41d8cd98f00b204e9800998ecf0def', {'ts_data': Timestamp(1380144472.22222), 'ts_meta': Timestamp(1380144473.22222)}) yield ( - '/srv/node/dev/objects/9/def/' - '9d41d8cd98f00b204e9800998ecf1def', '9d41d8cd98f00b204e9800998ecf1def', {'ts_data': Timestamp(1380144474.44444), 'ts_ctype': Timestamp(1380144474.44448), @@ -820,8 +806,6 @@ class TestSender(BaseTest): policy == POLICIES.legacy and suffixes == ['abc']): yield ( - '/srv/node/dev/objects/9/abc/' - '9d41d8cd98f00b204e9800998ecf0abc', '9d41d8cd98f00b204e9800998ecf0abc', {'ts_data': Timestamp(1380144470.00000)}) else: @@ -859,8 +843,6 @@ class TestSender(BaseTest): policy == POLICIES.legacy and suffixes == ['abc']): yield ( - '/srv/node/dev/objects/9/abc/' - '9d41d8cd98f00b204e9800998ecf0abc', '9d41d8cd98f00b204e9800998ecf0abc', {'ts_data': Timestamp(1380144470.00000)}) else: @@ -899,8 +881,6 @@ class TestSender(BaseTest): policy == POLICIES.legacy and suffixes == ['abc']): yield ( - '/srv/node/dev/objects/9/abc/' - '9d41d8cd98f00b204e9800998ecf0abc', '9d41d8cd98f00b204e9800998ecf0abc', {'ts_data': Timestamp(1380144470.00000)}) else: @@ -938,8 +918,6 @@ class TestSender(BaseTest): policy == POLICIES.legacy and suffixes == ['abc']): yield ( - '/srv/node/dev/objects/9/abc/' - '9d41d8cd98f00b204e9800998ecf0abc', '9d41d8cd98f00b204e9800998ecf0abc', {'ts_data': Timestamp(1380144470.00000)}) else: @@ -980,8 +958,6 @@ class TestSender(BaseTest): policy == POLICIES.legacy and suffixes == ['abc']): yield ( - '/srv/node/dev/objects/9/abc/' - '9d41d8cd98f00b204e9800998ecf0abc', '9d41d8cd98f00b204e9800998ecf0abc', {'ts_data': Timestamp(1380144470.00000)}) else: