summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoramalaba <princessbasha@gmail.com>2013-07-02 19:13:24 +0530
committeramalaba <princessbasha@gmail.com>2013-07-12 15:05:26 +0530
commit09b29aac12b2988db41834798f509b8a54500ab6 (patch)
treeb820126d6b85cbc048b5a8a653a2a668d42ec26c
parent62579fbb217f4c1a4668e793ebaafaf668619206 (diff)
downloadpython-glanceclient-09b29aac12b2988db41834798f509b8a54500ab6.tar.gz
Expose checksum index image property in client
Implement checksum image index property in the python-glanceclient Change-Id: If1426b7938457014ef27a86d3902d53854161627 Implements: blueprint index-using-checksum-image-property
-rw-r--r--glanceclient/v2/shell.py4
-rw-r--r--tests/v2/test_images.py56
-rw-r--r--tests/v2/test_shell_v2.py1
3 files changed, 60 insertions, 1 deletions
diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py
index d7e0b3f..cc05bb8 100644
--- a/glanceclient/v2/shell.py
+++ b/glanceclient/v2/shell.py
@@ -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])
diff --git a/tests/v2/test_images.py b/tests/v2/test_images.py
index ae40433..430c12e 100644
--- a/tests/v2/test_images.py
+++ b/tests/v2/test_images.py
@@ -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))
diff --git a/tests/v2/test_shell_v2.py b/tests/v2/test_shell_v2.py
index 1f3cc0b..0490790 100644
--- a/tests/v2/test_shell_v2.py
+++ b/tests/v2/test_shell_v2.py
@@ -33,6 +33,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 = {}