Merge "Add Discovery stub for Image Import"

This commit is contained in:
Jenkins 2017-07-19 16:09:41 +00:00 committed by Gerrit Code Review
commit 87f4209cca
3 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,46 @@
# Copyright (c) 2017 RedHat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo_config import cfg
from glance.common import wsgi
CONF = cfg.CONF
class InfoController(object):
def get_image_import(self, req):
# 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-
# coded.
import_methods = {
'description': 'Import methods available.',
'type': 'array',
'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
}
def create_resource():
return wsgi.Resource(InfoController())

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from glance.api.v2 import discovery
from glance.api.v2 import image_actions
from glance.api.v2 import image_data
from glance.api.v2 import image_members
@ -553,4 +554,16 @@ class API(wsgi.Router):
action='reject',
allowed_methods='GET, DELETE')
# Discovery API
info_resource = discovery.create_resource()
mapper.connect('info/import',
controller=info_resource,
action='get_image_import',
conditions={'method': ['GET']},
body_reject=True)
mapper.connect('info/import',
controller=reject_method_resource,
action='reject',
allowed_methods='GET')
super(API, self).__init__(mapper)

View File

@ -0,0 +1,31 @@
# Copyright (c) 2017 RedHat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import glance.api.v2.discovery
import glance.tests.unit.utils as unit_test_utils
import glance.tests.utils as test_utils
class TestInfoControllers(test_utils.BaseTestCase):
def setUp(self):
super(TestInfoControllers, self).setUp()
self.controller = glance.api.v2.discovery.InfoController()
def test_get_image_import(self):
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'])