def set_api_version_request(self): """Set API version request based on the request header information.""" if API_VERSION_REQUEST_HEADER in self.headers: hdr_string = self.headers[API_VERSION_REQUEST_HEADER] # 'latest' is a special keyword which is equivalent to requesting # the maximum version of the API supported if hdr_string == 'latest': self.api_version_request = api_version.max_api_version() else: self.api_version_request = api_version.APIVersionRequest( hdr_string) # Check that the version requested is within the global # minimum/maximum of supported API versions if not self.api_version_request.matches( api_version.min_api_version(), api_version.max_api_version()): raise exception.InvalidGlobalAPIVersion( req_ver=self.api_version_request.get_string(), min_ver=api_version.min_api_version().get_string(), max_ver=api_version.max_api_version().get_string()) else: self.api_version_request = api_version.APIVersionRequest( api_version.DEFAULT_API_VERSION)
def set_api_version_request(self): """Set API version request based on the request header information.""" hdr_string = microversion_parse.get_version( self.headers, service_type='compute', legacy_headers=[LEGACY_API_VERSION_REQUEST_HEADER]) if hdr_string is None: self.api_version_request = api_version.APIVersionRequest( api_version.DEFAULT_API_VERSION) elif hdr_string == 'latest': # 'latest' is a special keyword which is equivalent to # requesting the maximum version of the API supported self.api_version_request = api_version.max_api_version() else: self.api_version_request = api_version.APIVersionRequest( hdr_string) # Check that the version requested is within the global # minimum/maximum of supported API versions if not self.api_version_request.matches( api_version.min_api_version(), api_version.max_api_version()): raise exception.InvalidGlobalAPIVersion( req_ver=self.api_version_request.get_string(), min_ver=api_version.min_api_version().get_string(), max_ver=api_version.max_api_version().get_string())
class VersionsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21): sample_dir = 'versions' # NOTE(gmann): Setting empty scenario for 'version' API testing # as those does not send request on particular endpoint and running # its tests alone is enough. scenarios = [] max_api_version = avr.max_api_version().get_string() def test_versions_get(self): response = self._do_get('', strip_version=True) self._verify_response('versions-get-resp', {'max_api_version': self.max_api_version}, response, 200, update_links=False) def test_versions_get_v2(self): response = self._do_get('/v2', strip_version=True) self._verify_response('v2-version-get-resp', {}, response, 200, update_links=False) def test_versions_get_v21(self): response = self._do_get('/v2.1', strip_version=True) self._verify_response('v21-version-get-resp', {'max_api_version': self.max_api_version}, response, 200, update_links=False)
class VersionsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21): """Validate that proper version documents can be fetched without auth.""" # Here we want to avoid stubbing keystone middleware. That will cause # "real" keystone middleware to run (and fail) if it's in the pipeline. # (The point of this test is to prove we do version discovery through # pipelines that *don't* authenticate.) STUB_KEYSTONE = False USE_PROJECT_ID = False sample_dir = 'versions' # NOTE(gmann): Setting empty scenario for 'version' API testing # as those does not send request on particular endpoint and running # its tests alone is enough. scenarios = [] max_api_version = {'max_api_version': avr.max_api_version().get_string()} def setUp(self): super(VersionsSampleJsonTest, self).setUp() # Version documents are supposed to be available without auth, so make # the auth middleware "fail" authentication. self.useFixture( fixtures.MockPatch( # [api]auth_strategy is set to noauth2 by the ConfFixture 'nova.api.openstack.auth.NoAuthMiddlewareBase.base_call', return_value=webob.Response(status=401))) def _get(self, url): return self._do_get( url, # Since we're explicitly getting discovery endpoints, strip the # automatic /v2[.1] added by the fixture. strip_version=True) @ddt.data('', '/') def test_versions_get_base(self, url): response = self._get(url) self._verify_response('versions-get-resp', self.max_api_version, response, 200, update_links=False) @ddt.data(('/v2', 'v2-version-get-resp', {}), ('/v2/', 'v2-version-get-resp', {}), ('/v2.1', 'v21-version-get-resp', max_api_version), ('/v2.1/', 'v21-version-get-resp', max_api_version)) @ddt.unpack def test_versions_get_versioned(self, url, tplname, subs): response = self._get(url) self._verify_response(tplname, subs, response, 200, update_links=False)
import webob from nova.api.openstack import api_version_request as avr from nova.api.openstack.compute import views from nova import test from nova.tests.unit.api.openstack import fakes from nova.tests.unit import matchers from nova import wsgi NS = { 'atom': 'http://www.w3.org/2005/Atom', 'ns': 'http://docs.openstack.org/common/api/v1.0' } MAX_API_VERSION = avr.max_api_version().get_string() EXP_LINKS = { 'v2.0': { 'html': 'http://docs.openstack.org/', }, 'v2.1': { 'html': 'http://docs.openstack.org/' }, } EXP_VERSIONS = { "v2.0": { "id": "v2.0", "status": "SUPPORTED",
from oslo_serialization import jsonutils from nova.api.openstack import api_version_request as avr from nova.api.openstack.compute import views from nova import test from nova.tests.unit.api.openstack import fakes from nova.tests.unit import matchers from nova import wsgi NS = { 'atom': 'http://www.w3.org/2005/Atom', 'ns': 'http://docs.openstack.org/common/api/v1.0' } MAX_API_VERSION = avr.max_api_version().get_string() EXP_LINKS = { 'v2.0': { 'html': 'http://docs.openstack.org/', }, 'v2.1': { 'html': 'http://docs.openstack.org/' }, } EXP_VERSIONS = { "v2.0": { "id": "v2.0", "status": "SUPPORTED",