ambiguous column 'checksum' error when querying image-list(v2).
- removed ambiguity by prefixing the column with models.Image - based on the image_get_all() method logic, changed the filters.get(checksum) to filters.pop(checksum) to avoid multiple addition of same criteria in the where clause. - modified the functional db test to include this failing scenario. Fixes bug 1205330 Change-Id: Ic2b5b9bed7c02865d66e2f92846dcc9c0e7e2f97
This commit is contained in:
parent
c56fa55bb9
commit
5679a56a75
|
@ -612,8 +612,8 @@ def image_get_all(context, filters=None, marker=None, limit=None,
|
|||
showing_deleted = False
|
||||
|
||||
if 'checksum' in filters:
|
||||
checksum = filters.get('checksum')
|
||||
query = query.filter_by(checksum=checksum)
|
||||
checksum = filters.pop('checksum')
|
||||
query = query.filter(models.Image.checksum == checksum)
|
||||
|
||||
if 'changes-since' in filters:
|
||||
# normalize timestamp to UTC, as sqlalchemy doesn't appear to
|
||||
|
|
|
@ -541,26 +541,76 @@ class DriverTests(object):
|
|||
|
||||
def test_image_get_all_owned(self):
|
||||
TENANT1 = uuidutils.generate_uuid()
|
||||
ctxt1 = context.RequestContext(is_admin=False, tenant=TENANT1,
|
||||
ctxt1 = context.RequestContext(is_admin=False,
|
||||
tenant=TENANT1,
|
||||
auth_tok='user:%s:user' % TENANT1)
|
||||
UUIDX = uuidutils.generate_uuid()
|
||||
self.db_api.image_create(ctxt1, {'id': UUIDX,
|
||||
'status': 'queued',
|
||||
'owner': TENANT1})
|
||||
image_meta_data = {'id': UUIDX, 'status': 'queued', 'owner': TENANT1}
|
||||
self.db_api.image_create(ctxt1, image_meta_data)
|
||||
|
||||
TENANT2 = uuidutils.generate_uuid()
|
||||
ctxt2 = context.RequestContext(is_admin=False, tenant=TENANT2,
|
||||
ctxt2 = context.RequestContext(is_admin=False,
|
||||
tenant=TENANT2,
|
||||
auth_tok='user:%s:user' % TENANT2)
|
||||
UUIDY = uuidutils.generate_uuid()
|
||||
self.db_api.image_create(ctxt2, {'id': UUIDY,
|
||||
'status': 'queued',
|
||||
'owner': TENANT2})
|
||||
image_meta_data = {'id': UUIDY, 'status': 'queued', 'owner': TENANT2}
|
||||
self.db_api.image_create(ctxt2, image_meta_data)
|
||||
|
||||
images = self.db_api.image_get_all(ctxt1)
|
||||
|
||||
image_ids = [image['id'] for image in images]
|
||||
expected = [UUIDX, UUID3, UUID2, UUID1]
|
||||
self.assertEqual(sorted(expected), sorted(image_ids))
|
||||
|
||||
def test_image_get_all_owned_checksum(self):
|
||||
TENANT1 = uuidutils.generate_uuid()
|
||||
ctxt1 = context.RequestContext(is_admin=False,
|
||||
tenant=TENANT1,
|
||||
auth_tok='user:%s:user' % TENANT1)
|
||||
UUIDX = uuidutils.generate_uuid()
|
||||
CHECKSUM1 = '91264c3edf5972c9f1cb309543d38a5c'
|
||||
image_meta_data = {
|
||||
'id': UUIDX,
|
||||
'status': 'queued',
|
||||
'checksum': CHECKSUM1,
|
||||
'owner': TENANT1
|
||||
}
|
||||
self.db_api.image_create(ctxt1, image_meta_data)
|
||||
image_member_data = {
|
||||
'image_id': UUIDX,
|
||||
'member': TENANT1,
|
||||
'can_share': False,
|
||||
"status": "accepted",
|
||||
}
|
||||
self.db_api.image_member_create(ctxt1, image_member_data)
|
||||
|
||||
TENANT2 = uuidutils.generate_uuid()
|
||||
ctxt2 = context.RequestContext(is_admin=False,
|
||||
tenant=TENANT2,
|
||||
auth_tok='user:%s:user' % TENANT2)
|
||||
UUIDY = uuidutils.generate_uuid()
|
||||
CHECKSUM2 = '92264c3edf5972c9f1cb309543d38a5c'
|
||||
image_meta_data = {
|
||||
'id': UUIDY,
|
||||
'status': 'queued',
|
||||
'checksum': CHECKSUM2,
|
||||
'owner': TENANT2
|
||||
}
|
||||
self.db_api.image_create(ctxt2, image_meta_data)
|
||||
image_member_data = {
|
||||
'image_id': UUIDY,
|
||||
'member': TENANT2,
|
||||
'can_share': False,
|
||||
"status": "accepted",
|
||||
}
|
||||
self.db_api.image_member_create(ctxt2, image_member_data)
|
||||
|
||||
filters = {'visibility': 'shared', 'checksum': CHECKSUM2}
|
||||
images = self.db_api.image_get_all(ctxt2, filters)
|
||||
|
||||
self.assertEquals(1, len(images))
|
||||
self.assertEqual(UUIDY, images[0]['id'])
|
||||
|
||||
def test_image_paginate(self):
|
||||
"""Paginate through a list of images using limit and marker"""
|
||||
extra_uuids = [uuidutils.generate_uuid() for i in range(2)]
|
||||
|
|
Loading…
Reference in New Issue