summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Rosmaita <rosmaita.fossdev@gmail.com>2018-08-21 15:08:56 -0400
committerBrian Rosmaita <rosmaita.fossdev@gmail.com>2019-01-17 14:22:48 -0500
commit4511a445d010345c2bbd41bec303fe6df6312f3c (patch)
tree714187bae0722bea5f7e472c33e33c0433e0cabb
parentc4c92ecb51f4a7b93c1a84d5084006fed15c6945 (diff)
downloadpython-glanceclient-4511a445d010345c2bbd41bec303fe6df6312f3c.tar.gz
Add image-list filter for multihash
This was missed when multihash support was added to the glanceclient. The os_hash_value is an indexed field in the API. Includes a release note. Closes-bug: #1788271 Change-Id: Ibfe28b8c644967b7e0295dfd3f55c3ae1b0cbb2d
-rw-r--r--glanceclient/tests/unit/v2/test_images.py60
-rw-r--r--glanceclient/tests/unit/v2/test_shell_v2.py8
-rw-r--r--glanceclient/v2/shell.py5
-rw-r--r--releasenotes/notes/multihash-filter-ef2a48dc48fae9dc.yaml13
4 files changed, 85 insertions, 1 deletions
diff --git a/glanceclient/tests/unit/v2/test_images.py b/glanceclient/tests/unit/v2/test_images.py
index 753f3c4..99926de 100644
--- a/glanceclient/tests/unit/v2/test_images.py
+++ b/glanceclient/tests/unit/v2/test_images.py
@@ -26,6 +26,10 @@ from glanceclient.v2 import images
_CHKSUM = '93264c3edf5972c9f1cb309543d38a5c'
_CHKSUM1 = '54264c3edf5972c9f1cb309453d38a46'
+_HASHVAL = '54264c3edf93264c3edf5972c9f1cb309543d38a5c5972c9f1cb309453d38a46'
+_HASHVAL1 = 'cb309543d38a5c5972c9f1cb309453d38a4654264c3edf93264c3edf5972c9f1'
+_HASHBAD = '93264c3edf597254264c3edf5972c9f1cb309453d38a46c9f1cb309543d38a5c'
+
_TAG1 = 'power'
_TAG2 = '64bit'
@@ -457,6 +461,41 @@ data_fixtures = {
{'images': []},
),
},
+ '/v2/images?limit=%d&os_hash_value=%s' % (images.DEFAULT_PAGE_SIZE,
+ _HASHVAL): {
+ 'GET': (
+ {},
+ {'images': [
+ {
+ 'id': '3a4560a1-e585-443e-9b39-553b46ec92d1',
+ 'name': 'image-1',
+ }
+ ]},
+ ),
+ },
+ '/v2/images?limit=%d&os_hash_value=%s' % (images.DEFAULT_PAGE_SIZE,
+ _HASHVAL1): {
+ 'GET': (
+ {},
+ {'images': [
+ {
+ 'id': '2a4560b2-e585-443e-9b39-553b46ec92d1',
+ 'name': 'image-1',
+ },
+ {
+ 'id': '6f99bf80-2ee6-47cf-acfe-1f1fabb7e810',
+ 'name': 'image-2',
+ },
+ ]},
+ ),
+ },
+ '/v2/images?limit=%d&os_hash_value=%s' % (images.DEFAULT_PAGE_SIZE,
+ _HASHBAD): {
+ 'GET': (
+ {},
+ {'images': []},
+ ),
+ },
'/v2/images?limit=%d&tag=%s' % (images.DEFAULT_PAGE_SIZE, _TAG1): {
'GET': (
{},
@@ -754,6 +793,27 @@ class TestController(testtools.TestCase):
images = self.controller.list(**filters)
self.assertEqual(0, len(images))
+ def test_list_images_for_hash_single_image(self):
+ fake_id = '3a4560a1-e585-443e-9b39-553b46ec92d1'
+ filters = {'filters': {'os_hash_value': _HASHVAL}}
+ images = self.controller.list(**filters)
+ self.assertEqual(1, len(images))
+ self.assertEqual('%s' % fake_id, images[0].id)
+
+ def test_list_images_for_hash_multiple_images(self):
+ fake_id1 = '2a4560b2-e585-443e-9b39-553b46ec92d1'
+ fake_id2 = '6f99bf80-2ee6-47cf-acfe-1f1fabb7e810'
+ filters = {'filters': {'os_hash_value': _HASHVAL1}}
+ images = self.controller.list(**filters)
+ self.assertEqual(2, len(images))
+ self.assertEqual('%s' % fake_id1, images[0].id)
+ self.assertEqual('%s' % fake_id2, images[1].id)
+
+ def test_list_images_for_wrong_hash(self):
+ filters = {'filters': {'os_hash_value': _HASHBAD}}
+ images = self.controller.list(**filters)
+ self.assertEqual(0, len(images))
+
def test_list_images_for_bogus_owner(self):
filters = {'filters': {'owner': _BOGUS_ID}}
images = self.controller.list(**filters)
diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py
index 919e645..bafa8e5 100644
--- a/glanceclient/tests/unit/v2/test_shell_v2.py
+++ b/glanceclient/tests/unit/v2/test_shell_v2.py
@@ -265,6 +265,7 @@ class ShellV2Test(testtools.TestCase):
'sort': None,
'verbose': False,
'include_stores': False,
+ 'os_hash_value': None,
'os_hidden': False
}
args = self._make_args(input)
@@ -302,6 +303,7 @@ class ShellV2Test(testtools.TestCase):
'sort': None,
'verbose': True,
'include_stores': False,
+ 'os_hash_value': None,
'os_hidden': False
}
args = self._make_args(input)
@@ -328,6 +330,7 @@ class ShellV2Test(testtools.TestCase):
'sort': None,
'verbose': False,
'include_stores': True,
+ 'os_hash_value': None,
'os_hidden': False
}
args = self._make_args(input)
@@ -353,6 +356,7 @@ class ShellV2Test(testtools.TestCase):
'sort': None,
'verbose': True,
'include_stores': True,
+ 'os_hash_value': None,
'os_hidden': False
}
args = self._make_args(input)
@@ -379,6 +383,7 @@ class ShellV2Test(testtools.TestCase):
'sort': None,
'verbose': False,
'include_stores': False,
+ 'os_hash_value': None,
'os_hidden': True
}
args = self._make_args(input)
@@ -416,6 +421,7 @@ class ShellV2Test(testtools.TestCase):
'sort': None,
'verbose': False,
'include_stores': False,
+ 'os_hash_value': None,
'os_hidden': False
}
args = self._make_args(input)
@@ -453,6 +459,7 @@ class ShellV2Test(testtools.TestCase):
'sort_dir': [],
'verbose': False,
'include_stores': False,
+ 'os_hash_value': None,
'os_hidden': False
}
args = self._make_args(input)
@@ -490,6 +497,7 @@ class ShellV2Test(testtools.TestCase):
'sort': None,
'verbose': False,
'include_stores': False,
+ 'os_hash_value': None,
'os_hidden': False
}
args = self._make_args(input)
diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py
index 544416a..75c3c0d 100644
--- a/glanceclient/v2/shell.py
+++ b/glanceclient/v2/shell.py
@@ -327,6 +327,9 @@ def do_image_update(gc, args):
action='append', dest='properties', default=[])
@utils.arg('--checksum', metavar='<CHECKSUM>',
help=_('Displays images that match the MD5 checksum.'))
+@utils.arg('--hash', dest='os_hash_value', default=None,
+ metavar='<HASH_VALUE>',
+ help=_('Displays images that match the specified hash value.'))
@utils.arg('--tag', metavar='<TAG>', action='append',
help=_("Filter images by a user-defined tag."))
@utils.arg('--sort-key', default=[], action='append',
@@ -358,7 +361,7 @@ def do_image_update(gc, args):
def do_image_list(gc, args):
"""List images you can access."""
filter_keys = ['visibility', 'member_status', 'owner', 'checksum', 'tag',
- 'os_hidden']
+ 'os_hidden', 'os_hash_value']
filter_items = [(key, getattr(args, key)) for key in filter_keys]
if args.properties:
diff --git a/releasenotes/notes/multihash-filter-ef2a48dc48fae9dc.yaml b/releasenotes/notes/multihash-filter-ef2a48dc48fae9dc.yaml
new file mode 100644
index 0000000..6bb22aa
--- /dev/null
+++ b/releasenotes/notes/multihash-filter-ef2a48dc48fae9dc.yaml
@@ -0,0 +1,13 @@
+---
+features:
+ - |
+ For parity with the old ``checksum`` field, this release adds the
+ ability for CLI users to filter the image list based upon a particular
+ multihash value using the ``--hash <HASH_VALUE>`` option. Issue the
+ command:
+
+ .. code-block:: none
+
+ glance help image-list
+
+ for more information.