Fix 'filter' object has no len ()

Karbor has a python3 compatibility issue where it will fail with:
TypeError: object of type 'filter' has no len(). 'filter' is a list
in python.

Change-Id: I6505e454e2073c1611cbe5c4887241253051b1f1
Closes-Bug: #1891732
This commit is contained in:
wangyu 2020-08-15 11:37:09 +08:00
parent 0764f5dab1
commit 5d6f5eb7ab
2 changed files with 5 additions and 5 deletions

View File

@ -273,8 +273,8 @@ class Server(object):
def _volume_attached(self, volume_id):
volume_item = self.cinder_client.volumes.get(volume_id)
server_attachments = filter(lambda x: x['server_id'] == self.id,
volume_item.attachments)
server_attachments = list(filter(lambda x: x['server_id'] == self.id,
volume_item.attachments))
if len(server_attachments) > 0:
return True
else:
@ -287,8 +287,8 @@ class Server(object):
def _volume_detached(self, volume_id):
volume_item = self.cinder_client.volumes.get(volume_id)
server_attachments = filter(lambda x: x['server_id'] == self.id,
volume_item.attachments)
server_attachments = list(filter(lambda x: x['server_id'] == self.id,
volume_item.attachments))
if len(server_attachments) > 0:
return False
else:

View File

@ -127,7 +127,7 @@ class ScheduledOperationsTest(karbor_base.KarborBaseTest):
operation_item = self.karbor_client.scheduled_operations.get(
operation.id)
plan_id = operation_item.operation_definition["plan_id"]
cps = filter(lambda x: x.protection_plan["id"] == plan_id, items)
cps = list(filter(lambda x: x.protection_plan["id"] == plan_id, items))
self.assertEqual(freq, len(cps))
for cp in cps: