From ecb040c17786fa28d521a247c556a99442e37d5f Mon Sep 17 00:00:00 2001 From: Abhishek Kekane Date: Wed, 4 May 2022 05:41:56 +0000 Subject: [PATCH] [APIImpact] Correct API response code for PUT /v2/cache/{image_id} PUT /v2/cache/{image_id} returns HTTP 200 response code to user but as per proposal it should be HTTP 202. This change returns HTTP 202 response to user. Closes-Bug: #1971521 Change-Id: I6a875a38bef5beafe352ab3320f3fd199db89aa1 --- api-ref/source/v2/cache-manage.inc | 2 +- glance/api/v2/cached_images.py | 4 +++- glance/tests/functional/v2/test_cache_api.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api-ref/source/v2/cache-manage.inc b/api-ref/source/v2/cache-manage.inc index 93379f434a..00156ab9d3 100644 --- a/api-ref/source/v2/cache-manage.inc +++ b/api-ref/source/v2/cache-manage.inc @@ -47,7 +47,7 @@ Queue image Queues image for caching. *(Since Image API v2.14)* -Normal response codes: 200 +Normal response codes: 202 Error response codes: 400, 401, 403, 404 diff --git a/glance/api/v2/cached_images.py b/glance/api/v2/cached_images.py index 002b8cf9bf..812ddb3cda 100644 --- a/glance/api/v2/cached_images.py +++ b/glance/api/v2/cached_images.py @@ -238,7 +238,9 @@ class CachedImageDeserializer(wsgi.JSONRequestDeserializer): class CachedImageSerializer(wsgi.JSONResponseSerializer): - pass + + def queue_image_from_api(self, response, result): + response.status_int = 202 def create_resource(): diff --git a/glance/tests/functional/v2/test_cache_api.py b/glance/tests/functional/v2/test_cache_api.py index bd3048aef5..4865c6d4f9 100644 --- a/glance/tests/functional/v2/test_cache_api.py +++ b/glance/tests/functional/v2/test_cache_api.py @@ -79,7 +79,7 @@ class TestImageCache(functional.SynchronousAPIBase): if response.status_code == 200: return response.json - def cache_queue(self, image_id, expected_code=200): + def cache_queue(self, image_id, expected_code=202): # Queue image for prefetching path = '/v2/cache/%s' % image_id response = self.api_put(path)