Skip to content

Commit

Permalink
Add config option to override url for versions
Browse files Browse the repository at this point in the history
The versions url returns the wrong data when cinder api is behind
a proxy. This adds a new config option so it can be set properly.

DocImpact

Change-Id: I46a90120b21e43bf8dca9e5f0efdf339f0d3e8e6
Closes-Bug: #1384379
  • Loading branch information
wanghao committed Mar 2, 2015
1 parent 1e2ac58 commit 2eb25ab
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cinder/api/views/versions.py
Expand Up @@ -16,9 +16,24 @@
import copy
import os

from oslo_config import cfg


versions_opts = [
cfg.StrOpt('public_endpoint', default=None,
help="Public url to use for versions endpoint. The default "
"is None, which will use the request's host_url "
"attribute to populate the URL base. If Cinder is "
"operating behind a proxy, you will want to change "
"this to represent the proxy's URL."),
]

CONF = cfg.CONF
CONF.register_opts(versions_opts)


def get_view_builder(req):
base_url = req.application_url
base_url = CONF.public_endpoint or req.application_url
return ViewBuilder(base_url)


Expand Down
71 changes: 71 additions & 0 deletions cinder/tests/api/test_versions.py
@@ -0,0 +1,71 @@
# Copyright (c) 2015 - 2016 Huawei Technologies Co., Ltd.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# 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.

import webob

from cinder.api import versions
from cinder import test


class VersionsTest(test.TestCase):

"""Test the version information returned from the API service."""

def test_get_version_list_public_endpoint(self):
req = webob.Request.blank('/', base_url='http://127.0.0.1:8776/')
req.accept = 'application/json'
self.override_config('public_endpoint', 'https://example.com:8776')
res = versions.Versions().index(req)
results = res['versions']
expected = [
{
'id': 'v1.0',
'status': 'SUPPORTED',
'updated': '2014-06-28T12:20:21Z',
'links': [{'rel': 'self',
'href': 'https://example.com:8776/v1/'}],
},
{
'id': 'v2.0',
'status': 'CURRENT',
'updated': '2012-11-21T11:33:21Z',
'links': [{'rel': 'self',
'href': 'https://example.com:8776/v2/'}],
},
]
self.assertEqual(expected, results)

def test_get_version_list(self):
req = webob.Request.blank('/', base_url='http://127.0.0.1:8776/')
req.accept = 'application/json'
res = versions.Versions().index(req)
results = res['versions']
expected = [
{
'id': 'v1.0',
'status': 'SUPPORTED',
'updated': '2014-06-28T12:20:21Z',
'links': [{'rel': 'self',
'href': 'http://127.0.0.1:8776/v1/'}],
},
{
'id': 'v2.0',
'status': 'CURRENT',
'updated': '2012-11-21T11:33:21Z',
'links': [{'rel': 'self',
'href': 'http://127.0.0.1:8776/v2/'}],
},
]
self.assertEqual(expected, results)

0 comments on commit 2eb25ab

Please sign in to comment.