Change code to be more Pythonic

Minor refactor to code that is not "Pythonic".
Using a generator comprehension with "all" can improves performance

Change-Id: I4817ddb8a2af4e1e5b8a74e3950194d23df18a0f
This commit is contained in:
Arnon Yaari 2017-05-22 17:33:10 +03:00
parent c68131decf
commit 00390448b8
1 changed files with 4 additions and 4 deletions

View File

@ -423,7 +423,7 @@ class ISCSIConnector(base.BaseLinuxConnector, base_iscsi.BaseISCSIConnector):
# TODO(justinsb): This retry-with-delay is a pattern, move to utils?
tries = 0
# Loop until at least 1 path becomes available
while all(map(lambda x: not os.path.exists(x), host_devices)):
while all(not os.path.exists(x) for x in host_devices):
if tries >= self.device_scan_attempts:
raise exception.VolumeDeviceNotFound(device=host_devices)
@ -436,12 +436,12 @@ class ISCSIConnector(base.BaseLinuxConnector, base_iscsi.BaseISCSIConnector):
host_devices, target_props = (
self._get_potential_volume_paths(connection_properties))
else:
if (tries):
if tries:
host_devices = self._get_device_path(target_props)
self._run_iscsiadm(target_props, ("--rescan",))
tries = tries + 1
if all(map(lambda x: not os.path.exists(x), host_devices)):
tries += 1
if all(not os.path.exists(x) for x in host_devices):
time.sleep(tries ** 2)
else:
break