Enable Image Import per default and make current

Makes the EXPERIMENTAL Image Import 2.6 as CURRENT
Enables the Image Import feature per default

Change-Id: Ib6e4f511e1aa1f943977085547f50afee4c996d0
This commit is contained in:
Erno Kuvaja 2018-01-10 10:03:10 +00:00
parent 223f2cf887
commit 955b917b98
4 changed files with 21 additions and 343 deletions

View File

@ -73,11 +73,9 @@ class Controller(object):
version_objs = []
if CONF.enable_v2_api:
if CONF.enable_image_import:
version_objs.append(
build_version_object(2.6, 'v2', 'EXPERIMENTAL'))
version_objs.extend([
build_version_object(2.5, 'v2', 'CURRENT'),
build_version_object(2.6, 'v2', 'CURRENT'),
build_version_object(2.5, 'v2', 'SUPPORTED'),
build_version_object(2.4, 'v2', 'SUPPORTED'),
build_version_object(2.3, 'v2', 'SUPPORTED'),
build_version_object(2.2, 'v2', 'SUPPORTED'),

View File

@ -704,7 +704,7 @@ Related options:
""")),
cfg.BoolOpt('enable_image_import',
default=False,
default=True,
deprecated_for_removal=True,
deprecated_reason=_("""
This option is deprecated for removal in Rocky.
@ -721,7 +721,7 @@ Import, it's disabled per default in Pike, enabled per
default in Queens and removed in Rocky. This allows Glance to
operate with previous version configs upon upgrade.
Setting this option to True will enable the endpoints related
Setting this option to False will disable the endpoints related
to Image Import Refactoring work.
Related options:

View File

@ -42,21 +42,19 @@ def _generate_v1_versions(url):
return v1_versions
def _generate_v2_versions(url, include_experimental=False):
def _generate_v2_versions(url):
version_list = []
if include_experimental:
version_list.append(
{
'id': 'v2.6',
'status': 'EXPERIMENTAL',
'links': [{'rel': 'self', 'href': url % '2'}],
})
version_list.extend([
{
'id': 'v2.5',
'id': 'v2.6',
'status': 'CURRENT',
'links': [{'rel': 'self', 'href': url % '2'}],
},
{
'id': 'v2.5',
'status': 'SUPPORTED',
'links': [{'rel': 'self', 'href': url % '2'}],
},
{
'id': 'v2.4',
'status': 'SUPPORTED',
@ -87,9 +85,9 @@ def _generate_v2_versions(url, include_experimental=False):
return v2_versions
def _generate_all_versions(url, include_experimental=False):
def _generate_all_versions(url):
v1 = _generate_v1_versions(url)
v2 = _generate_v2_versions(url, include_experimental)
v2 = _generate_v2_versions(url)
all_versions = {'versions': v2['versions'] + v1['versions']}
return all_versions
@ -112,24 +110,6 @@ class TestApiVersions(functional.FunctionalTest):
content = jsonutils.loads(content_json.decode())
self.assertEqual(versions, content)
def test_version_configurations_EXPERIMENTAL(self):
"""Test that versioning is handled properly through all channels"""
self.api_server.enable_v1_api = True
self.api_server.enable_v2_api = True
self.api_server.enable_image_import = True
self.start_servers(**self.__dict__.copy())
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
versions = _generate_all_versions(url, include_experimental=True)
# Verify version choices returned.
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content_json = http.request(path, 'GET')
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(versions, content)
def test_v2_api_configuration(self):
self.api_server.enable_v1_api = False
self.api_server.enable_v2_api = True
@ -146,23 +126,6 @@ class TestApiVersions(functional.FunctionalTest):
content = jsonutils.loads(content_json.decode())
self.assertEqual(versions, content)
def test_v2_api_configuration_EXPERIMENTAL(self):
self.api_server.enable_v1_api = False
self.api_server.enable_v2_api = True
self.api_server.enable_image_import = True
self.start_servers(**self.__dict__.copy())
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
versions = _generate_v2_versions(url, include_experimental=True)
# Verify version choices returned.
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content_json = http.request(path, 'GET')
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(versions, content)
def test_v1_api_configuration(self):
self.api_server.enable_v1_api = True
self.api_server.enable_v2_api = False
@ -179,25 +142,6 @@ class TestApiVersions(functional.FunctionalTest):
content = jsonutils.loads(content_json.decode())
self.assertEqual(versions, content)
def test_v1_api_configuration_EXPERIMENTAL(self):
# enabling image import should have no effect, but
# nothing else should blow up, either
self.api_server.enable_v1_api = True
self.api_server.enable_v2_api = False
self.api_server.enable_image_import = True
self.start_servers(**self.__dict__.copy())
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
versions = _generate_v1_versions(url)
# Verify version choices returned.
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content_json = http.request(path, 'GET')
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(versions, content)
class TestApiPaths(functional.FunctionalTest):
def setUp(self):
@ -374,184 +318,3 @@ class TestApiPaths(functional.FunctionalTest):
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)
# NOTE(rosmaita): yes, this is a lot of duplicated code from the above
# class, but it will be much easier to rip out in Queens if we simply
# do a copy-pasta now
class TestApiPathsEXPERIMENTAL(functional.FunctionalTest):
def setUp(self):
super(TestApiPathsEXPERIMENTAL, self).setUp()
self.api_server.enable_image_import = True
self.start_servers(**self.__dict__.copy())
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
self.versions = _generate_all_versions(url, include_experimental=True)
images = {'images': []}
self.images_json = jsonutils.dumps(images)
def test_get_root_path(self):
"""Assert GET / with `no Accept:` header.
Verify version choices returned.
Bug lp:803260 no Accept header causes a 500 in glance-api
"""
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content_json = http.request(path, 'GET')
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)
def test_get_images_path(self):
"""Assert GET /images with `no Accept:` header.
Verify version choices returned.
"""
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content_json = http.request(path, 'GET')
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)
def test_get_v1_images_path(self):
"""GET /v1/images with `no Accept:` header.
Verify empty images list returned.
"""
path = 'http://%s:%d/v1/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(http_client.OK, response.status)
def test_get_root_path_with_unknown_header(self):
"""Assert GET / with Accept: unknown header
Verify version choices returned. Verify message in API log about
unknown accept header.
"""
path = 'http://%s:%d/' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
headers = {'Accept': 'unknown'}
response, content_json = http.request(path, 'GET', headers=headers)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)
def test_get_root_path_with_openstack_header(self):
"""Assert GET / with an Accept: application/vnd.openstack.images-v1
Verify empty image list returned
"""
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
headers = {'Accept': 'application/vnd.openstack.images-v1'}
response, content = http.request(path, 'GET', headers=headers)
self.assertEqual(http_client.OK, response.status)
self.assertEqual(self.images_json, content.decode())
def test_get_images_path_with_openstack_header(self):
"""Assert GET /images with a
`Accept: application/vnd.openstack.compute-v1` header.
Verify version choices returned. Verify message in API log
about unknown accept header.
"""
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
headers = {'Accept': 'application/vnd.openstack.compute-v1'}
response, content_json = http.request(path, 'GET', headers=headers)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)
def test_get_v10_images_path(self):
"""Assert GET /v1.0/images with no Accept: header
Verify version choices returned
"""
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
def test_get_v1a_images_path(self):
"""Assert GET /v1.a/images with no Accept: header
Verify version choices returned
"""
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
def test_get_va1_images_path(self):
"""Assert GET /va.1/images with no Accept: header
Verify version choices returned
"""
path = 'http://%s:%d/va.1/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content_json = http.request(path, 'GET')
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)
def test_get_versions_path(self):
"""Assert GET /versions with no Accept: header
Verify version choices returned
"""
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content_json = http.request(path, 'GET')
self.assertEqual(http_client.OK, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)
def test_get_versions_path_with_openstack_header(self):
"""Assert GET /versions with the
`Accept: application/vnd.openstack.images-v1` header.
Verify version choices returned.
"""
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
headers = {'Accept': 'application/vnd.openstack.images-v1'}
response, content_json = http.request(path, 'GET', headers=headers)
self.assertEqual(http_client.OK, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)
def test_get_v1_versions_path(self):
"""Assert GET /v1/versions with `no Accept:` header
Verify 404 returned
"""
path = 'http://%s:%d/v1/versions' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(http_client.NOT_FOUND, response.status)
def test_get_versions_choices(self):
"""Verify version choices returned"""
path = 'http://%s:%d/v10' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content_json = http.request(path, 'GET')
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)
def test_get_images_path_with_openstack_v2_header(self):
"""Assert GET /images with a
`Accept: application/vnd.openstack.compute-v2` header.
Verify version choices returned. Verify message in API log
about unknown version in accept header.
"""
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
headers = {'Accept': 'application/vnd.openstack.images-v10'}
response, content_json = http.request(path, 'GET', headers=headers)
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)
def test_get_v12_images_path(self):
"""Assert GET /v1.2/images with `no Accept:` header
Verify version choices returned
"""
path = 'http://%s:%d/v1.2/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content_json = http.request(path, 'GET')
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
content = jsonutils.loads(content_json.decode())
self.assertEqual(self.versions, content)

View File

@ -23,9 +23,6 @@ from glance.common.wsgi import Request as WsgiRequest
from glance.tests.unit import base
# NOTE(rosmaita): rip out all the EXPERIMENTAL stuff when 2.6 becomes
# CURRENT in Queens (or figure out a better way to write these tests!)
class VersionsTest(base.IsolatedUnitTest):
"""Test the version information returned from the API service."""
@ -33,11 +30,17 @@ class VersionsTest(base.IsolatedUnitTest):
def _get_versions_list(self, url):
versions = [
{
'id': 'v2.5',
'id': 'v2.6',
'status': 'CURRENT',
'links': [{'rel': 'self',
'href': '%s/v2/' % url}],
},
{
'id': 'v2.5',
'status': 'SUPPORTED',
'links': [{'rel': 'self',
'href': '%s/v2/' % url}],
},
{
'id': 'v2.4',
'status': 'SUPPORTED',
@ -83,16 +86,6 @@ class VersionsTest(base.IsolatedUnitTest):
]
return versions
def _get_versions_list_experimental(self, url):
vplus = [
{
'id': 'v2.6',
'status': 'EXPERIMENTAL',
'links': [{'rel': 'self',
'href': '%s/v2/' % url}],
}] + self._get_versions_list(url)
return vplus
def test_get_version_list(self):
req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
req.accept = 'application/json'
@ -104,19 +97,6 @@ class VersionsTest(base.IsolatedUnitTest):
expected = self._get_versions_list('http://127.0.0.1:9292')
self.assertEqual(expected, results)
def test_get_version_list_EXPERIMENTAL(self):
req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
req.accept = 'application/json'
self.config(bind_host='127.0.0.1', bind_port=9292,
enable_image_import=True)
res = versions.Controller().index(req)
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions']
expected = self._get_versions_list_experimental(
'http://127.0.0.1:9292')
self.assertEqual(expected, results)
def test_get_version_list_public_endpoint(self):
req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
req.accept = 'application/json'
@ -129,20 +109,6 @@ class VersionsTest(base.IsolatedUnitTest):
expected = self._get_versions_list('https://example.com:9292')
self.assertEqual(expected, results)
def test_get_version_list_public_endpoint_EXPERIMENTAL(self):
req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
req.accept = 'application/json'
self.config(bind_host='127.0.0.1', bind_port=9292,
public_endpoint='https://example.com:9292',
enable_image_import=True)
res = versions.Controller().index(req)
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions']
expected = self._get_versions_list_experimental(
'https://example.com:9292')
self.assertEqual(expected, results)
def test_get_version_list_secure_proxy_ssl_header(self):
self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO')
url = 'http://localhost:9292'
@ -155,19 +121,6 @@ class VersionsTest(base.IsolatedUnitTest):
expected = self._get_versions_list(url)
self.assertEqual(expected, results)
def test_get_version_list_secure_proxy_ssl_header_EXPERIMENTAL(self):
self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO',
enable_image_import=True)
url = 'http://localhost:9292'
environ = webob.request.environ_from_url(url)
req = WsgiRequest(environ)
res = versions.Controller().index(req)
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions']
expected = self._get_versions_list_experimental(url)
self.assertEqual(expected, results)
def test_get_version_list_secure_proxy_ssl_header_https(self):
self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO')
url = 'http://localhost:9292'
@ -182,21 +135,6 @@ class VersionsTest(base.IsolatedUnitTest):
expected = self._get_versions_list(ssl_url)
self.assertEqual(expected, results)
def test_get_version_list_secure_proxy_ssl_header_https_EXPERIMENTAL(self):
self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO',
enable_image_import=True)
url = 'http://localhost:9292'
ssl_url = 'https://localhost:9292'
environ = webob.request.environ_from_url(url)
environ['HTTP_X_FORWARDED_PROTO'] = "https"
req = WsgiRequest(environ)
res = versions.Controller().index(req)
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions']
expected = self._get_versions_list_experimental(ssl_url)
self.assertEqual(expected, results)
class VersionNegotiationTest(base.IsolatedUnitTest):
@ -260,14 +198,8 @@ class VersionNegotiationTest(base.IsolatedUnitTest):
self.middleware.process_request(request)
self.assertEqual('/v2/images', request.path_info)
def test_request_url_v2_6_unsupported(self):
def test_request_url_v2_6(self):
request = webob.Request.blank('/v2.6/images')
resp = self.middleware.process_request(request)
self.assertIsInstance(resp, versions.Controller)
def test_request_url_v2_6_EXPERIMENTAL(self):
request = webob.Request.blank('/v2.6/images')
self.config(enable_image_import=True)
self.middleware.process_request(request)
self.assertEqual('/v2/images', request.path_info)
@ -282,17 +214,6 @@ class VersionNegotiationTest(base.IsolatedUnitTest):
resp = self.middleware.process_request(request)
self.assertIsInstance(resp, versions.Controller)
def test_request_url_v3_unsupported(self):
request = webob.Request.blank('/v3/images')
resp = self.middleware.process_request(request)
self.assertIsInstance(resp, versions.Controller)
def test_request_url_v3_unsupported_EXPERIMENTAL(self):
request = webob.Request.blank('/v3/images')
self.config(enable_image_import=True)
resp = self.middleware.process_request(request)
self.assertIsInstance(resp, versions.Controller)
class VersionsAndNegotiationTest(VersionNegotiationTest, VersionsTest):
@ -304,16 +225,12 @@ class VersionsAndNegotiationTest(VersionNegotiationTest, VersionsTest):
def _get_list_of_version_ids(self, status):
request = webob.Request.blank('/')
request.accept = 'application/json'
# TODO(rosmaita): remove in Queens when option is removed
self.config(enable_image_import=True)
response = versions.Controller().index(request)
v_list = jsonutils.loads(response.body)['versions']
return [v['id'] for v in v_list if v['status'] == status]
def _assert_version_is_negotiated(self, version_id):
request = webob.Request.blank("/%s/images" % version_id)
# TODO(rosmaita): remove in Queens when option is removed
self.config(enable_image_import=True)
self.middleware.process_request(request)
major = version_id.split('.', 1)[0]
expected = "/%s/images" % major