Exclude disabled API versions from listing
The code for listing supported API versions would return a static list, whether those versions were enabled or not. This changes the logic to drop versions that are not enabled so we don't report back support for something that then would cause a failure if the user tried to use it. Closes-bug: #1788039 Change-Id: I52c1264b3b67a5c1ea00de1c0de5bea04c3096ee Co-Authored-By: iain MacDonnell <iain.macdonnell@oracle.com> Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
parent
7c2086cb40
commit
3ae2bd6728
@ -17,6 +17,7 @@
|
||||
|
||||
import copy
|
||||
|
||||
from oslo_config import cfg
|
||||
from six.moves import http_client
|
||||
|
||||
from cinder.api import extensions
|
||||
@ -26,6 +27,9 @@ from cinder.api.openstack import wsgi
|
||||
from cinder.api.views import versions as views_versions
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
_LINKS = [{
|
||||
"rel": "describedby",
|
||||
"type": "text/html",
|
||||
@ -111,9 +115,15 @@ class VersionsController(wsgi.Controller):
|
||||
# available versions.
|
||||
@wsgi.response(http_client.MULTIPLE_CHOICES)
|
||||
def all(self, req):
|
||||
"""Return all known versions."""
|
||||
"""Return all known and enabled versions."""
|
||||
builder = views_versions.get_view_builder(req)
|
||||
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)
|
||||
|
||||
|
||||
|
@ -14,6 +14,8 @@
|
||||
# under the License.
|
||||
|
||||
import ddt
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as config_fixture
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
@ -29,6 +31,7 @@ from cinder import test
|
||||
from cinder.tests.unit.api import fakes
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
VERSION_HEADER_NAME = 'OpenStack-API-Version'
|
||||
VOLUME_SERVICE = 'volume '
|
||||
|
||||
@ -81,6 +84,21 @@ class VersionsControllerTestCase(test.TestCase):
|
||||
self.assertEqual(api_version_request._MIN_API_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):
|
||||
req = self.build_request(base_url='http://localhost/v2')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user