Merge "Expose checksum index image property in client"
This commit is contained in:
@@ -25,9 +25,11 @@ from glanceclient import exc
|
||||
help='The status of images to display.')
|
||||
@utils.arg('--owner', metavar='<OWNER>',
|
||||
help='Display images owned by <OWNER>.')
|
||||
@utils.arg('--checksum', metavar='<CHECKSUM>',
|
||||
help='Display images matching the checksum')
|
||||
def do_image_list(gc, args):
|
||||
"""List images you can access."""
|
||||
filter_keys = ['visibility', 'member_status', 'owner']
|
||||
filter_keys = ['visibility', 'member_status', 'owner', 'checksum']
|
||||
filter_items = [(key, getattr(args, key)) for key in filter_keys]
|
||||
filters = dict([item for item in filter_items if item[1] is not None])
|
||||
|
||||
|
@@ -21,6 +21,9 @@ import warlock
|
||||
from glanceclient.v2 import images
|
||||
from tests import utils
|
||||
|
||||
_CHKSUM = '93264c3edf5972c9f1cb309543d38a5c'
|
||||
_CHKSUM1 = '54264c3edf5972c9f1cb309453d38a46'
|
||||
|
||||
_BOGUS_ID = '63e7f218-29de-4477-abdc-8db7c9533188'
|
||||
_EVERYTHING_ID = '802cbbb7-0379-4c38-853f-37302b5e3d29'
|
||||
_OWNED_IMAGE_ID = 'a4963502-acc7-42ba-ad60-5aa0962b7faf'
|
||||
@@ -189,6 +192,38 @@ fixtures = {
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v2/images?checksum=%s&limit=%d' % (_CHKSUM, images.DEFAULT_PAGE_SIZE): {
|
||||
'GET': (
|
||||
{},
|
||||
{'images': [
|
||||
{
|
||||
'id': '3a4560a1-e585-443e-9b39-553b46ec92d1',
|
||||
'name': 'image-1',
|
||||
}
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v2/images?checksum=%s&limit=%d' % (_CHKSUM1, images.DEFAULT_PAGE_SIZE): {
|
||||
'GET': (
|
||||
{},
|
||||
{'images': [
|
||||
{
|
||||
'id': '2a4560b2-e585-443e-9b39-553b46ec92d1',
|
||||
'name': 'image-1',
|
||||
},
|
||||
{
|
||||
'id': '6f99bf80-2ee6-47cf-acfe-1f1fabb7e810',
|
||||
'name': 'image-2',
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v2/images?checksum=wrong&limit=%d' % images.DEFAULT_PAGE_SIZE: {
|
||||
'GET': (
|
||||
{},
|
||||
{'images': []},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -243,6 +278,27 @@ class TestController(testtools.TestCase):
|
||||
images = list(self.controller.list(**filters))
|
||||
self.assertEqual(images[0].id, _OWNED_IMAGE_ID)
|
||||
|
||||
def test_list_images_for_checksum_single_image(self):
|
||||
fake_id = '3a4560a1-e585-443e-9b39-553b46ec92d1'
|
||||
filters = {'filters': dict([('checksum', _CHKSUM)])}
|
||||
images = list(self.controller.list(**filters))
|
||||
self.assertEquals(1, len(images))
|
||||
self.assertEqual(images[0].id, '%s' % fake_id)
|
||||
|
||||
def test_list_images_for_checksum_multiple_images(self):
|
||||
fake_id1 = '2a4560b2-e585-443e-9b39-553b46ec92d1'
|
||||
fake_id2 = '6f99bf80-2ee6-47cf-acfe-1f1fabb7e810'
|
||||
filters = {'filters': dict([('checksum', _CHKSUM1)])}
|
||||
images = list(self.controller.list(**filters))
|
||||
self.assertEquals(2, len(images))
|
||||
self.assertEqual(images[0].id, '%s' % fake_id1)
|
||||
self.assertEqual(images[1].id, '%s' % fake_id2)
|
||||
|
||||
def test_list_images_for_wrong_checksum(self):
|
||||
filters = {'filters': dict([('checksum', 'wrong')])}
|
||||
images = list(self.controller.list(**filters))
|
||||
self.assertEquals(0, len(images))
|
||||
|
||||
def test_list_images_for_bogus_owner(self):
|
||||
filters = {'filters': dict([('owner', _BOGUS_ID)])}
|
||||
images = list(self.controller.list(**filters))
|
||||
|
@@ -39,6 +39,7 @@ class LegacyShellV1Test(testtools.TestCase):
|
||||
self.visibility = True
|
||||
self.member_status = 'Fake'
|
||||
self.owner = 'test'
|
||||
self.checksum = 'fake_checksum'
|
||||
|
||||
with mock.patch.object(gc.images, 'list') as mocked_list:
|
||||
mocked_list.return_value = {}
|
||||
|
Reference in New Issue
Block a user