Esempio n. 1
0
 def _check_version(self, version, headers=None):
     if headers is None:
         headers = {}
     # ensure that major version in the URL matches the header
     if version.major != versions.BASE_VERSION:
         raise exc.HTTPNotAcceptable(
             "Mutually exclusive versions requested. Version %(ver)s "
             "requested but not supported by this service. The supported "
             "version range is: [%(min)s, %(max)s]." % {
                 'ver': version,
                 'min': versions.min_version_string(),
                 'max': versions.max_version_string()
             },
             headers=headers)
     # ensure the minor version is within the supported range
     if version < min_version() or version > max_version():
         raise exc.HTTPNotAcceptable(
             "Version %(ver)s was requested but the minor version is not "
             "supported by this service. The supported version range is: "
             "[%(min)s, %(max)s]." % {
                 'ver': version,
                 'min': versions.min_version_string(),
                 'max': versions.max_version_string()
             },
             headers=headers)
Esempio n. 2
0
def min_version():
    return base.Version(
        {
            base.Version.string:
            ' '.join([
                versions.service_type_string(),
                versions.min_version_string()
            ])
        }, versions.min_version_string(), versions.max_version_string())
Esempio n. 3
0
    def _route(self, args, request=None):
        v = base.Version(pecan.request.headers, versions.min_version_string(),
                         versions.max_version_string())

        # The Vary header is used as a hint to caching proxies and user agents
        # that the response is also dependent on the OpenStack-API-Version and
        # not just the body and query parameters. See RFC 7231 for details.
        pecan.response.headers['Vary'] = base.Version.string

        # Always set the min and max headers
        pecan.response.headers[base.Version.min_string] = (
            versions.min_version_string())
        pecan.response.headers[base.Version.max_string] = (
            versions.max_version_string())

        # assert that requested version is supported
        self._check_version(v, pecan.response.headers)
        pecan.response.headers[base.Version.string] = str(v)
        pecan.request.version = v

        return super(Controller, self)._route(args, request)
Esempio n. 4
0
#        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 watcher.api.controllers.v1 import versions
from watcher.tests.api import base as api_base

SERVICE_TYPE = 'infra-optim'
H_MIN_VER = 'openstack-api-minimum-version'
H_MAX_VER = 'openstack-api-maximum-version'
H_RESP_VER = 'openstack-api-version'
MIN_VER = versions.min_version_string()
MAX_VER = versions.max_version_string()


class TestMicroversions(api_base.FunctionalTest):

    controller_list_response = [
        'scoring_engines', 'audit_templates', 'audits', 'actions',
        'action_plans', 'services'
    ]

    def setUp(self):
        super(TestMicroversions, self).setUp()

    def test_wrong_major_version(self):
        response = self.get_json(