Merge "Exclude disabled API versions from listing"
This commit is contained in:
commit
7f27679466
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from six.moves import http_client
|
from six.moves import http_client
|
||||||
|
|
||||||
from cinder.api import extensions
|
from cinder.api import extensions
|
||||||
@ -26,6 +27,9 @@ from cinder.api.openstack import wsgi
|
|||||||
from cinder.api.views import versions as views_versions
|
from cinder.api.views import versions as views_versions
|
||||||
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
_LINKS = [{
|
_LINKS = [{
|
||||||
"rel": "describedby",
|
"rel": "describedby",
|
||||||
"type": "text/html",
|
"type": "text/html",
|
||||||
@ -111,9 +115,15 @@ class VersionsController(wsgi.Controller):
|
|||||||
# available versions.
|
# available versions.
|
||||||
@wsgi.response(http_client.MULTIPLE_CHOICES)
|
@wsgi.response(http_client.MULTIPLE_CHOICES)
|
||||||
def all(self, req):
|
def all(self, req):
|
||||||
"""Return all known versions."""
|
"""Return all known and enabled versions."""
|
||||||
builder = views_versions.get_view_builder(req)
|
builder = views_versions.get_view_builder(req)
|
||||||
known_versions = copy.deepcopy(_KNOWN_VERSIONS)
|
known_versions = copy.deepcopy(_KNOWN_VERSIONS)
|
||||||
|
|
||||||
|
if not CONF.enable_v2_api:
|
||||||
|
known_versions.pop('v2.0')
|
||||||
|
if not CONF.enable_v3_api:
|
||||||
|
known_versions.pop('v3.0')
|
||||||
|
|
||||||
return builder.build_versions(known_versions)
|
return builder.build_versions(known_versions)
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import ddt
|
import ddt
|
||||||
|
from oslo_config import cfg
|
||||||
|
from oslo_config import fixture as config_fixture
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
import six
|
import six
|
||||||
@ -29,6 +31,7 @@ from cinder import test
|
|||||||
from cinder.tests.unit.api import fakes
|
from cinder.tests.unit.api import fakes
|
||||||
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
VERSION_HEADER_NAME = 'OpenStack-API-Version'
|
VERSION_HEADER_NAME = 'OpenStack-API-Version'
|
||||||
VOLUME_SERVICE = 'volume '
|
VOLUME_SERVICE = 'volume '
|
||||||
|
|
||||||
@ -81,6 +84,21 @@ class VersionsControllerTestCase(test.TestCase):
|
|||||||
self.assertEqual(api_version_request._MIN_API_VERSION,
|
self.assertEqual(api_version_request._MIN_API_VERSION,
|
||||||
v3.get('min_version'))
|
v3.get('min_version'))
|
||||||
|
|
||||||
|
@ddt.data('2.0', '3.0')
|
||||||
|
def test_all_versions_excludes_disabled(self, version):
|
||||||
|
self.fixture = self.useFixture(config_fixture.Config(CONF))
|
||||||
|
if version == '2.0':
|
||||||
|
self.fixture.config(enable_v2_api=False)
|
||||||
|
elif version == '3.0':
|
||||||
|
self.fixture.config(enable_v3_api=False)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
vc = versions.VersionsController()
|
||||||
|
req = self.build_request(base_url='http://localhost')
|
||||||
|
resp = vc.all(req)
|
||||||
|
all_versions = [x['id'] for x in resp['versions']]
|
||||||
|
self.assertNotIn('v' + version, all_versions)
|
||||||
|
|
||||||
def test_versions_v2_no_header(self):
|
def test_versions_v2_no_header(self):
|
||||||
req = self.build_request(base_url='http://localhost/v2')
|
req = self.build_request(base_url='http://localhost/v2')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user