From eaa8811030364b5a771c1d7d4c2cbbce71ba40ae Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sat, 10 Feb 2018 22:16:20 +0000 Subject: [PATCH] Fix image_search request First, change the URL to 'images//search' which is the correct URL to use. Second, change the HTTP method from 'SEARCH' to 'GET' because 'GET' is the standard HTTP method. Change-Id: I2bf054b16414f67954ac4eb973889fc0d488a260 --- zunclient/common/base.py | 2 +- zunclient/tests/unit/v1/test_images.py | 16 +++++++++------- zunclient/v1/images.py | 5 ++--- zunclient/v1/images_shell.py | 3 +-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/zunclient/common/base.py b/zunclient/common/base.py index 7a0343ff..042628f3 100644 --- a/zunclient/common/base.py +++ b/zunclient/common/base.py @@ -149,7 +149,7 @@ class Manager(object): if 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) if obj_class is None: obj_class = self.resource_class diff --git a/zunclient/tests/unit/v1/test_images.py b/zunclient/tests/unit/v1/test_images.py index ca2c09e5..554f0e63 100644 --- a/zunclient/tests/unit/v1/test_images.py +++ b/zunclient/tests/unit/v1/test_images.py @@ -48,10 +48,6 @@ fake_responses = { {}, {'images': [IMAGE1, IMAGE2]}, ), - 'SEARCH': ( - {}, - {'images': [IMAGE3]}, - ), }, '/v1/images/?limit=2': { @@ -95,6 +91,13 @@ fake_responses = { {'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): images = self.mgr.search_image(**SEARCH_IMAGE) expect = [ - ('SEARCH', '/v1/images/', {}, - {'image': IMAGE3['image'], - 'image_driver': IMAGE3['image_driver']}), + ('GET', '/v1/images/%s/search' % IMAGE3['image'], {}, + {'image_driver': IMAGE3['image_driver']}), ] self.assertEqual(expect, self.api.calls) self.assertThat(images, matchers.HasLength(1)) diff --git a/zunclient/v1/images.py b/zunclient/v1/images.py index 931e6213..99114e67 100644 --- a/zunclient/v1/images.py +++ b/zunclient/v1/images.py @@ -96,7 +96,7 @@ class ImageManager(base.Manager): "Key must be in %s" % ','.join(PULL_ATTRIBUTES)) 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 :returns: A list of images based on the search query @@ -110,5 +110,4 @@ class ImageManager(base.Manager): else: raise exceptions.InvalidAttribute( "Key must be in %s" % ','.join(IMAGE_SEARCH_ATTRIBUTES)) - path = '' - return self._search(self._path(path), image_query) + return self._search(self._path(image) + '/search', image_query) diff --git a/zunclient/v1/images_shell.py b/zunclient/v1/images_shell.py index a3dcac5f..934af2d9 100644 --- a/zunclient/v1/images_shell.py +++ b/zunclient/v1/images_shell.py @@ -80,10 +80,9 @@ def do_image_show(cs, args): def do_image_search(cs, args): """Print list of available images from repository based on user query.""" opts = {} - opts['image'] = args.image opts['image_driver'] = args.image_driver 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') utils.print_list(images, columns, {'versions': zun_utils.print_list_field('versions')},