Add Discovery stub for Image Import
This change adds discovery stub for Image Import MVP returning ['glance-direct'] as import-methods if Image Import has been enabled in config. The default behavior for Pike is disabled so the GET call to /v2/info/import returns empty list as default. The stub is required for the client work to support the Minimum Viable Product testing. This change is based on the work started by Cyril and Nikhil on https://review.openstack.org/#/c/270980 dropping any components that are depending of the parts of IIR not implemented yet. Change-Id: I4bc4c1123fed7ea8a838ea3d06e9da966ae18f58 Co-Authored-By: Cyril Roelandt <cyril@redhat.com> Co-Authored-By: Nikhil Komawar <nik.komawar@gmail.com>
This commit is contained in:
parent
e1cf21dec2
commit
0539f612bc
46
glance/api/v2/discovery.py
Normal file
46
glance/api/v2/discovery.py
Normal 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())
|
@ -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)
|
||||
|
31
glance/tests/unit/v2/test_discovery_image_import.py
Normal file
31
glance/tests/unit/v2/test_discovery_image_import.py
Normal 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'])
|
Loading…
x
Reference in New Issue
Block a user