From 692dc040872e04d27469570a508018c44f8d88ef Mon Sep 17 00:00:00 2001 From: Brian Rosmaita Date: Thu, 17 Aug 2017 09:18:20 -0400 Subject: [PATCH] Return 404 for import-info call Change the response to GET v2/info/import to be a 404 when Glance is configured with enable_image_import = False so that the response is consistent with the v2.5 API. See the bug for details. Change-Id: Ib56b600dbf53672bcaa4fd959adb736de4cdff50 Closes-bug: #1711362 --- glance/api/v2/discovery.py | 14 +++++++++----- .../unit/v2/test_discovery_image_import.py | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/glance/api/v2/discovery.py b/glance/api/v2/discovery.py index 0166ed9d9c..563ac08aa3 100644 --- a/glance/api/v2/discovery.py +++ b/glance/api/v2/discovery.py @@ -14,14 +14,23 @@ # limitations under the License. from oslo_config import cfg +import webob.exc from glance.common import wsgi +from glance.i18n import _ + CONF = cfg.CONF class InfoController(object): def get_image_import(self, req): + # TODO(jokke): Will be removed after the config option + # is removed. (deprecated) + if not CONF.enable_image_import: + msg = _("Image import is not supported at this site.") + raise webob.exc.HTTPNotFound(explanation=msg) + # TODO(jokke): All the rest of the boundaries should be implemented. # TODO(jokke): Once we have the rest of the methods implemented # the value should be inherited from the CONF rather than hard- @@ -32,11 +41,6 @@ class InfoController(object): 'value': ['glance-direct'] } - # TODO(jokke): Will be removed after the config option - # is removed. (deprecated) - if not CONF.enable_image_import: - import_methods['value'] = [] - return { 'import-methods': import_methods } diff --git a/glance/tests/unit/v2/test_discovery_image_import.py b/glance/tests/unit/v2/test_discovery_image_import.py index 82d3a18986..43667b1b84 100644 --- a/glance/tests/unit/v2/test_discovery_image_import.py +++ b/glance/tests/unit/v2/test_discovery_image_import.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import webob.exc + import glance.api.v2.discovery import glance.tests.unit.utils as unit_test_utils import glance.tests.utils as test_utils @@ -24,8 +26,21 @@ class TestInfoControllers(test_utils.BaseTestCase): super(TestInfoControllers, self).setUp() self.controller = glance.api.v2.discovery.InfoController() - def test_get_image_import(self): + def test_get_import_info_when_import_not_enabled(self): + """When import not enabled, should return 404 just like v2.5""" + self.config(enable_image_import=False) + req = unit_test_utils.get_fake_request() + self.assertRaises(webob.exc.HTTPNotFound, + self.controller.get_image_import, + req) + + def test_get_import_info(self): + # TODO(rosmaita): change this when import methods are + # listed in the config file + import_method = 'glance-direct' + + self.config(enable_image_import=True) req = unit_test_utils.get_fake_request() output = self.controller.get_image_import(req) self.assertIn('import-methods', output) - self.assertEqual([], output['import-methods']['value']) + self.assertEqual([import_method], output['import-methods']['value'])