Merge "Fix image_search request"

This commit is contained in:
Zuul
2018-03-06 03:53:50 +00:00
committed by Gerrit Code Review
4 changed files with 13 additions and 13 deletions

View File

@@ -149,7 +149,7 @@ class Manager(object):
if qparams: if qparams:
url = "%s?%s" % (url, urlparse.urlencode(qparams)) url = "%s?%s" % (url, urlparse.urlencode(qparams))
resp, body = self.api.json_request('SEARCH', url, body=body) resp, body = self.api.json_request('GET', url, body=body)
data = self._format_body_data(body, response_key) data = self._format_body_data(body, response_key)
if obj_class is None: if obj_class is None:
obj_class = self.resource_class obj_class = self.resource_class

View File

@@ -48,10 +48,6 @@ fake_responses = {
{}, {},
{'images': [IMAGE1, IMAGE2]}, {'images': [IMAGE1, IMAGE2]},
), ),
'SEARCH': (
{},
{'images': [IMAGE3]},
),
}, },
'/v1/images/?limit=2': '/v1/images/?limit=2':
{ {
@@ -95,6 +91,13 @@ fake_responses = {
{'images': [IMAGE2, IMAGE1]}, {'images': [IMAGE2, IMAGE1]},
), ),
}, },
'/v1/images/%s/search' % IMAGE3['image']:
{
'GET': (
{},
{'images': [IMAGE3]},
),
},
} }
@@ -180,9 +183,8 @@ class ImageManagerTest(testtools.TestCase):
def test_image_search(self): def test_image_search(self):
images = self.mgr.search_image(**SEARCH_IMAGE) images = self.mgr.search_image(**SEARCH_IMAGE)
expect = [ expect = [
('SEARCH', '/v1/images/', {}, ('GET', '/v1/images/%s/search' % IMAGE3['image'], {},
{'image': IMAGE3['image'], {'image_driver': IMAGE3['image_driver']}),
'image_driver': IMAGE3['image_driver']}),
] ]
self.assertEqual(expect, self.api.calls) self.assertEqual(expect, self.api.calls)
self.assertThat(images, matchers.HasLength(1)) self.assertThat(images, matchers.HasLength(1))

View File

@@ -96,7 +96,7 @@ class ImageManager(base.Manager):
"Key must be in %s" % ','.join(PULL_ATTRIBUTES)) "Key must be in %s" % ','.join(PULL_ATTRIBUTES))
return self._create(self._path(), new) return self._create(self._path(), new)
def search_image(self, **kwargs): def search_image(self, image, **kwargs):
"""Retrieves list of images based on image name and image_driver name """Retrieves list of images based on image name and image_driver name
:returns: A list of images based on the search query :returns: A list of images based on the search query
@@ -110,5 +110,4 @@ class ImageManager(base.Manager):
else: else:
raise exceptions.InvalidAttribute( raise exceptions.InvalidAttribute(
"Key must be in %s" % ','.join(IMAGE_SEARCH_ATTRIBUTES)) "Key must be in %s" % ','.join(IMAGE_SEARCH_ATTRIBUTES))
path = '' return self._search(self._path(image) + '/search', image_query)
return self._search(self._path(path), image_query)

View File

@@ -80,10 +80,9 @@ def do_image_show(cs, args):
def do_image_search(cs, args): def do_image_search(cs, args):
"""Print list of available images from repository based on user query.""" """Print list of available images from repository based on user query."""
opts = {} opts = {}
opts['image'] = args.image
opts['image_driver'] = args.image_driver opts['image_driver'] = args.image_driver
opts['exact_match'] = args.exact_match opts['exact_match'] = args.exact_match
images = cs.images.search_image(**opts) images = cs.images.search_image(args.image, **opts)
columns = ('ID', 'Name', 'Tags', 'Status', 'Size', 'Metadata') columns = ('ID', 'Name', 'Tags', 'Status', 'Size', 'Metadata')
utils.print_list(images, columns, utils.print_list(images, columns,
{'versions': zun_utils.print_list_field('versions')}, {'versions': zun_utils.print_list_field('versions')},