Fix reconstructer to be able to run non ec policy environment

Since the related change, object-reconstructor gathers the local devices
for ec policy via get_local_devices method but the method causes TypeError when
attempting *reduce* for empty set list. the list can be empty when no EC config
found in swift.conf.

This patch fixes the get_local_devices to return empty set even when no ec config
in swift.conf without errors.

Co-Authored-By: Kirill Zaitsev <k.zaitsev@me.com>
Change-Id: Ic121fb547966787a43f9eae83c91bb2bf640c4be
Related-Change: 701a172afac37229b85ea762f20428f6f422d29b
Closes-Bug: #1707595
This commit is contained in:
Kota Tsuyuzaki 2017-07-31 16:20:11 +09:00
parent 340014ed22
commit 45cc1d02d0
2 changed files with 15 additions and 1 deletions

View File

@ -1034,7 +1034,7 @@ class ObjectReconstructor(Daemon):
policy2devices = self.get_policy2devices()
return reduce(set.union, (
set(d['device'] for d in devices)
for devices in policy2devices.values()))
for devices in policy2devices.values()), set())
def collect_parts(self, override_devices=None, override_partitions=None):
"""

View File

@ -3856,6 +3856,20 @@ class TestObjectReconstructor(BaseTestObjectReconstructor):
# hashpath is still there, but it's empty
self.assertEqual([], os.listdir(df._datadir))
def test_get_local_devices(self):
local_devs = self.reconstructor.get_local_devices()
self.assertEqual({'sda'}, local_devs)
@patch_policies(legacy_only=True)
def test_get_local_devices_with_no_ec_policy_env(self):
# even no ec_policy found on the server, it runs just like as
# no ec device found
self.policy = POLICIES.default
self._configure_reconstructor()
self.assertEqual([], self.reconstructor.policies)
local_devs = self.reconstructor.get_local_devices()
self.assertEqual(set(), local_devs)
class TestReconstructFragmentArchive(BaseTestObjectReconstructor):
obj_path = '/a/c/o' # subclass overrides this