Merge "Extend remove_version_from_href support" into stable/queens
This commit is contained in:
commit
15a47ef681
@ -139,20 +139,25 @@ def limited(items, request, max_limit=CONF.osapi_max_limit):
|
|||||||
def remove_version_from_href(href):
|
def remove_version_from_href(href):
|
||||||
"""Removes the first api version from the href.
|
"""Removes the first api version from the href.
|
||||||
|
|
||||||
Given: 'http://www.manila.com/v1.1/123'
|
Given: 'http://manila.example.com/v1.1/123'
|
||||||
Returns: 'http://www.manila.com/123'
|
Returns: 'http://manila.example.com/123'
|
||||||
|
|
||||||
Given: 'http://www.manila.com/v1.1'
|
Given: 'http://www.manila.com/v1.1'
|
||||||
Returns: 'http://www.manila.com'
|
Returns: 'http://www.manila.com'
|
||||||
|
|
||||||
|
Given: 'http://manila.example.com/share/v1.1/123'
|
||||||
|
Returns: 'http://manila.example.com/share/123'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
parsed_url = parse.urlsplit(href)
|
parsed_url = parse.urlsplit(href)
|
||||||
url_parts = parsed_url.path.split('/', 2)
|
url_parts = parsed_url.path.split('/')
|
||||||
|
|
||||||
# NOTE: this should match vX.X or vX
|
# NOTE: this should match vX.X or vX
|
||||||
expression = re.compile(r'^v([0-9]+|[0-9]+\.[0-9]+)(/.*|$)')
|
expression = re.compile(r'^v([0-9]+|[0-9]+\.[0-9]+)(/.*|$)')
|
||||||
if expression.match(url_parts[1]):
|
for x in range(len(url_parts)):
|
||||||
del url_parts[1]
|
if expression.match(url_parts[x]):
|
||||||
|
del url_parts[x]
|
||||||
|
break
|
||||||
|
|
||||||
new_path = '/'.join(url_parts)
|
new_path = '/'.join(url_parts)
|
||||||
|
|
||||||
|
@ -193,50 +193,36 @@ class PaginationParamsTest(test.TestCase):
|
|||||||
@ddt.ddt
|
@ddt.ddt
|
||||||
class MiscFunctionsTest(test.TestCase):
|
class MiscFunctionsTest(test.TestCase):
|
||||||
|
|
||||||
def test_remove_major_version_from_href(self):
|
@ddt.data(
|
||||||
fixture = 'http://www.testsite.com/v1/images'
|
('http://manila.example.com/v2/b2d18606-2673-4965-885a-4f5a8b955b9b/',
|
||||||
expected = 'http://www.testsite.com/images'
|
'http://manila.example.com/b2d18606-2673-4965-885a-4f5a8b955b9b/'),
|
||||||
|
('http://manila.example.com/v1/',
|
||||||
|
'http://manila.example.com/'),
|
||||||
|
('http://manila.example.com/share/v2.22/',
|
||||||
|
'http://manila.example.com/share/'),
|
||||||
|
('http://manila.example.com/share/v1/'
|
||||||
|
'b2d18606-2673-4965-885a-4f5a8b955b9b/',
|
||||||
|
'http://manila.example.com/share/'
|
||||||
|
'b2d18606-2673-4965-885a-4f5a8b955b9b/'),
|
||||||
|
('http://10.10.10.10:3366/v1/',
|
||||||
|
'http://10.10.10.10:3366/'),
|
||||||
|
('http://10.10.10.10:3366/v2/b2d18606-2673-4965-885a-4f5a8b955b9b/',
|
||||||
|
'http://10.10.10.10:3366/b2d18606-2673-4965-885a-4f5a8b955b9b/'),
|
||||||
|
('http://manila.example.com:3366/v1.1/',
|
||||||
|
'http://manila.example.com:3366/'),
|
||||||
|
('http://manila.example.com:3366/v2/'
|
||||||
|
'b2d18606-2673-4965-885a-4f5a8b955b9b/',
|
||||||
|
'http://manila.example.com:3366/'
|
||||||
|
'b2d18606-2673-4965-885a-4f5a8b955b9b/'))
|
||||||
|
@ddt.unpack
|
||||||
|
def test_remove_version_from_href(self, fixture, expected):
|
||||||
actual = common.remove_version_from_href(fixture)
|
actual = common.remove_version_from_href(fixture)
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
def test_remove_version_from_href(self):
|
@ddt.data('http://manila.example.com/1.1/shares',
|
||||||
fixture = 'http://www.testsite.com/v1.1/images'
|
'http://manila.example.com/v/shares',
|
||||||
expected = 'http://www.testsite.com/images'
|
'http://manila.example.com/v1.1shares')
|
||||||
actual = common.remove_version_from_href(fixture)
|
def test_remove_version_from_href_bad_request(self, fixture):
|
||||||
self.assertEqual(expected, actual)
|
|
||||||
|
|
||||||
def test_remove_version_from_href_2(self):
|
|
||||||
fixture = 'http://www.testsite.com/v1.1/'
|
|
||||||
expected = 'http://www.testsite.com/'
|
|
||||||
actual = common.remove_version_from_href(fixture)
|
|
||||||
self.assertEqual(expected, actual)
|
|
||||||
|
|
||||||
def test_remove_version_from_href_3(self):
|
|
||||||
fixture = 'http://www.testsite.com/v10.10'
|
|
||||||
expected = 'http://www.testsite.com'
|
|
||||||
actual = common.remove_version_from_href(fixture)
|
|
||||||
self.assertEqual(expected, actual)
|
|
||||||
|
|
||||||
def test_remove_version_from_href_4(self):
|
|
||||||
fixture = 'http://www.testsite.com/v1.1/images/v10.5'
|
|
||||||
expected = 'http://www.testsite.com/images/v10.5'
|
|
||||||
actual = common.remove_version_from_href(fixture)
|
|
||||||
self.assertEqual(expected, actual)
|
|
||||||
|
|
||||||
def test_remove_version_from_href_bad_request(self):
|
|
||||||
fixture = 'http://www.testsite.com/1.1/images'
|
|
||||||
self.assertRaises(ValueError,
|
|
||||||
common.remove_version_from_href,
|
|
||||||
fixture)
|
|
||||||
|
|
||||||
def test_remove_version_from_href_bad_request_2(self):
|
|
||||||
fixture = 'http://www.testsite.com/v/images'
|
|
||||||
self.assertRaises(ValueError,
|
|
||||||
common.remove_version_from_href,
|
|
||||||
fixture)
|
|
||||||
|
|
||||||
def test_remove_version_from_href_bad_request_3(self):
|
|
||||||
fixture = 'http://www.testsite.com/v1.1images'
|
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
common.remove_version_from_href,
|
common.remove_version_from_href,
|
||||||
fixture)
|
fixture)
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
`Launchpad bug 1815038 <https://bugs.launchpad.net/manila/+bug/1815038>`_
|
||||||
|
has been fixed and now we correctly parse the base URL from manila's
|
||||||
|
endpoint url, accounting for proxy URLs.
|
Loading…
x
Reference in New Issue
Block a user