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
This commit is contained in:
parent
8886dcd114
commit
692dc04087
@ -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
|
||||
}
|
||||
|
@ -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'])
|
||||
|
Loading…
Reference in New Issue
Block a user