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
This commit is contained in:
@@ -26,6 +26,10 @@ from glanceclient.v2 import images
|
|||||||
_CHKSUM = '93264c3edf5972c9f1cb309543d38a5c'
|
_CHKSUM = '93264c3edf5972c9f1cb309543d38a5c'
|
||||||
_CHKSUM1 = '54264c3edf5972c9f1cb309453d38a46'
|
_CHKSUM1 = '54264c3edf5972c9f1cb309453d38a46'
|
||||||
|
|
||||||
|
_HASHVAL = '54264c3edf93264c3edf5972c9f1cb309543d38a5c5972c9f1cb309453d38a46'
|
||||||
|
_HASHVAL1 = 'cb309543d38a5c5972c9f1cb309453d38a4654264c3edf93264c3edf5972c9f1'
|
||||||
|
_HASHBAD = '93264c3edf597254264c3edf5972c9f1cb309453d38a46c9f1cb309543d38a5c'
|
||||||
|
|
||||||
_TAG1 = 'power'
|
_TAG1 = 'power'
|
||||||
_TAG2 = '64bit'
|
_TAG2 = '64bit'
|
||||||
|
|
||||||
@@ -457,6 +461,41 @@ data_fixtures = {
|
|||||||
{'images': []},
|
{'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): {
|
'/v2/images?limit=%d&tag=%s' % (images.DEFAULT_PAGE_SIZE, _TAG1): {
|
||||||
'GET': (
|
'GET': (
|
||||||
{},
|
{},
|
||||||
@@ -754,6 +793,27 @@ class TestController(testtools.TestCase):
|
|||||||
images = self.controller.list(**filters)
|
images = self.controller.list(**filters)
|
||||||
self.assertEqual(0, len(images))
|
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):
|
def test_list_images_for_bogus_owner(self):
|
||||||
filters = {'filters': {'owner': _BOGUS_ID}}
|
filters = {'filters': {'owner': _BOGUS_ID}}
|
||||||
images = self.controller.list(**filters)
|
images = self.controller.list(**filters)
|
||||||
|
@@ -265,6 +265,7 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
'sort': None,
|
'sort': None,
|
||||||
'verbose': False,
|
'verbose': False,
|
||||||
'include_stores': False,
|
'include_stores': False,
|
||||||
|
'os_hash_value': None,
|
||||||
'os_hidden': False
|
'os_hidden': False
|
||||||
}
|
}
|
||||||
args = self._make_args(input)
|
args = self._make_args(input)
|
||||||
@@ -302,6 +303,7 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
'sort': None,
|
'sort': None,
|
||||||
'verbose': True,
|
'verbose': True,
|
||||||
'include_stores': False,
|
'include_stores': False,
|
||||||
|
'os_hash_value': None,
|
||||||
'os_hidden': False
|
'os_hidden': False
|
||||||
}
|
}
|
||||||
args = self._make_args(input)
|
args = self._make_args(input)
|
||||||
@@ -328,6 +330,7 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
'sort': None,
|
'sort': None,
|
||||||
'verbose': False,
|
'verbose': False,
|
||||||
'include_stores': True,
|
'include_stores': True,
|
||||||
|
'os_hash_value': None,
|
||||||
'os_hidden': False
|
'os_hidden': False
|
||||||
}
|
}
|
||||||
args = self._make_args(input)
|
args = self._make_args(input)
|
||||||
@@ -353,6 +356,7 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
'sort': None,
|
'sort': None,
|
||||||
'verbose': True,
|
'verbose': True,
|
||||||
'include_stores': True,
|
'include_stores': True,
|
||||||
|
'os_hash_value': None,
|
||||||
'os_hidden': False
|
'os_hidden': False
|
||||||
}
|
}
|
||||||
args = self._make_args(input)
|
args = self._make_args(input)
|
||||||
@@ -379,6 +383,7 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
'sort': None,
|
'sort': None,
|
||||||
'verbose': False,
|
'verbose': False,
|
||||||
'include_stores': False,
|
'include_stores': False,
|
||||||
|
'os_hash_value': None,
|
||||||
'os_hidden': True
|
'os_hidden': True
|
||||||
}
|
}
|
||||||
args = self._make_args(input)
|
args = self._make_args(input)
|
||||||
@@ -416,6 +421,7 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
'sort': None,
|
'sort': None,
|
||||||
'verbose': False,
|
'verbose': False,
|
||||||
'include_stores': False,
|
'include_stores': False,
|
||||||
|
'os_hash_value': None,
|
||||||
'os_hidden': False
|
'os_hidden': False
|
||||||
}
|
}
|
||||||
args = self._make_args(input)
|
args = self._make_args(input)
|
||||||
@@ -453,6 +459,7 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
'sort_dir': [],
|
'sort_dir': [],
|
||||||
'verbose': False,
|
'verbose': False,
|
||||||
'include_stores': False,
|
'include_stores': False,
|
||||||
|
'os_hash_value': None,
|
||||||
'os_hidden': False
|
'os_hidden': False
|
||||||
}
|
}
|
||||||
args = self._make_args(input)
|
args = self._make_args(input)
|
||||||
@@ -490,6 +497,7 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
'sort': None,
|
'sort': None,
|
||||||
'verbose': False,
|
'verbose': False,
|
||||||
'include_stores': False,
|
'include_stores': False,
|
||||||
|
'os_hash_value': None,
|
||||||
'os_hidden': False
|
'os_hidden': False
|
||||||
}
|
}
|
||||||
args = self._make_args(input)
|
args = self._make_args(input)
|
||||||
|
@@ -327,6 +327,9 @@ def do_image_update(gc, args):
|
|||||||
action='append', dest='properties', default=[])
|
action='append', dest='properties', default=[])
|
||||||
@utils.arg('--checksum', metavar='<CHECKSUM>',
|
@utils.arg('--checksum', metavar='<CHECKSUM>',
|
||||||
help=_('Displays images that match the MD5 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',
|
@utils.arg('--tag', metavar='<TAG>', action='append',
|
||||||
help=_("Filter images by a user-defined tag."))
|
help=_("Filter images by a user-defined tag."))
|
||||||
@utils.arg('--sort-key', default=[], action='append',
|
@utils.arg('--sort-key', default=[], action='append',
|
||||||
@@ -358,7 +361,7 @@ def do_image_update(gc, args):
|
|||||||
def do_image_list(gc, args):
|
def do_image_list(gc, args):
|
||||||
"""List images you can access."""
|
"""List images you can access."""
|
||||||
filter_keys = ['visibility', 'member_status', 'owner', 'checksum', 'tag',
|
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]
|
filter_items = [(key, getattr(args, key)) for key in filter_keys]
|
||||||
|
|
||||||
if args.properties:
|
if args.properties:
|
||||||
|
13
releasenotes/notes/multihash-filter-ef2a48dc48fae9dc.yaml
Normal file
13
releasenotes/notes/multihash-filter-ef2a48dc48fae9dc.yaml
Normal file
@@ -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.
|
Reference in New Issue
Block a user