Port glance.db to Python 3
* add(), save(): don't compare None to an integer, it raises a TypeError on Python 3. * _pop_task_info_values(): copy values items because the values dictionary is modified in the loop body. * replace filter() with a list-comprehension: filter() returns a generator on Python 3 which has no length. * tox.ini: add test_db and test_quota unit tests to Python 3.4 Change-Id: I1494e81b154fc64df814b5f96c15fe032bb5057b
This commit is contained in:
parent
eeedd2030d
commit
eb769fe477
|
@ -253,7 +253,8 @@ class ImageRepo(object):
|
|||
|
||||
def add(self, image):
|
||||
image_values = self._format_image_to_db(image)
|
||||
if image_values['size'] > CONF.image_size_cap:
|
||||
if (image_values['size'] is not None
|
||||
and image_values['size'] > CONF.image_size_cap):
|
||||
raise exception.ImageSizeLimitExceeded
|
||||
# the updated_at value is not set in the _format_image_to_db
|
||||
# function since it is specific to image create
|
||||
|
@ -266,7 +267,8 @@ class ImageRepo(object):
|
|||
|
||||
def save(self, image, from_state=None):
|
||||
image_values = self._format_image_to_db(image)
|
||||
if image_values['size'] > CONF.image_size_cap:
|
||||
if (image_values['size'] is not None
|
||||
and image_values['size'] > CONF.image_size_cap):
|
||||
raise exception.ImageSizeLimitExceeded
|
||||
try:
|
||||
new_values = self.db_api.image_update(self.context,
|
||||
|
|
|
@ -145,7 +145,7 @@ def _image_member_format(image_id, tenant_id, can_share, status='pending'):
|
|||
|
||||
def _pop_task_info_values(values):
|
||||
task_info_values = {}
|
||||
for k, v in values.items():
|
||||
for k, v in list(values.items()):
|
||||
if k in ['input', 'result', 'message']:
|
||||
values.pop(k)
|
||||
task_info_values[k] = v
|
||||
|
@ -373,7 +373,7 @@ def _sort_images(images, sort_key, sort_dir):
|
|||
raise exception.Invalid(message='Number of sort dirs does not match '
|
||||
'the number of sort keys')
|
||||
|
||||
for key, dir in reversed(zip(sort_key, sort_dir)):
|
||||
for key, dir in reversed(list(zip(sort_key, sort_dir))):
|
||||
reverse = dir == 'desc'
|
||||
images.sort(key=itemgetter(key), reverse=reverse)
|
||||
|
||||
|
@ -489,7 +489,7 @@ def image_member_count(context, image_id):
|
|||
raise exception.Invalid(msg)
|
||||
|
||||
members = DATA['members']
|
||||
return len(filter(lambda x: x['image_id'] == image_id, members))
|
||||
return len([x for x in members if x['image_id'] == image_id])
|
||||
|
||||
|
||||
@log_call
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -33,6 +33,7 @@ commands =
|
|||
glance.tests.unit.test_cache_middleware \
|
||||
glance.tests.unit.test_context \
|
||||
glance.tests.unit.test_context_middleware \
|
||||
glance.tests.unit.test_db \
|
||||
glance.tests.unit.test_db_metadef \
|
||||
glance.tests.unit.test_domain \
|
||||
glance.tests.unit.test_domain_proxy \
|
||||
|
@ -44,6 +45,7 @@ commands =
|
|||
glance.tests.unit.test_notifier \
|
||||
glance.tests.unit.test_opts \
|
||||
glance.tests.unit.test_policy \
|
||||
glance.tests.unit.test_quota \
|
||||
glance.tests.unit.test_schema \
|
||||
glance.tests.unit.test_scrubber \
|
||||
glance.tests.unit.test_store_artifact \
|
||||
|
|
Loading…
Reference in New Issue