Fix endpoint identification for api-version query
The api-version query is a GET against the root endpoint of cinder. Determining this root endpoint had a flaw with the newer wsgi deployment URLs that would cause it to find the root endpoint of the web server and not cinder. This updates the logic to work with legacy, wsgi, and custom URLs for the Cinder endpoint. Change-Id: Iaeba1f8d50ee8cc9410cc9f638770a56796871fb Closes-bug: #1785594 Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
parent
460229c609
commit
e5217d901d
@ -210,7 +210,13 @@ class SessionClient(adapter.LegacyJsonAdapter):
|
||||
|
||||
def _get_base_url(self):
|
||||
endpoint = self.get_endpoint()
|
||||
base_url = '/'.join(endpoint.split('/')[:3]) + '/'
|
||||
m = re.search('(.+)/v[1-3].*', endpoint)
|
||||
if m:
|
||||
# Get everything up until the version identifier
|
||||
base_url = '%s/' % m.group(1)
|
||||
else:
|
||||
# Fall back to the root of the URL
|
||||
base_url = '/'.join(endpoint.split('/')[:3]) + '/'
|
||||
return base_url
|
||||
|
||||
def get_volume_api_version_from_endpoint(self):
|
||||
|
@ -32,6 +32,7 @@ from cinderclient.tests.unit import utils
|
||||
from cinderclient.tests.unit.v3 import fakes
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class ClientTest(utils.TestCase):
|
||||
|
||||
def test_get_client_class_v1(self):
|
||||
@ -99,11 +100,21 @@ class ClientTest(utils.TestCase):
|
||||
unknown_url)
|
||||
|
||||
@mock.patch('cinderclient.client.SessionClient.get_endpoint')
|
||||
def test_get_base_url(self, mock_get_endpoint):
|
||||
url = 'http://192.168.122.104:8776/v3/de50d1f33a38415fadfd3e1dea28f4d3'
|
||||
@ddt.data(
|
||||
('http://192.168.1.1:8776/v2', 'http://192.168.1.1:8776/'),
|
||||
('http://192.168.1.1:8776/v3/e5526285ebd741b1819393f772f11fc3',
|
||||
'http://192.168.1.1:8776/'),
|
||||
('https://192.168.1.1:8080/volumes/v3/'
|
||||
'e5526285ebd741b1819393f772f11fc3',
|
||||
'https://192.168.1.1:8080/volumes/'),
|
||||
('http://192.168.1.1/volumes/v3/e5526285ebd741b1819393f772f11fc3',
|
||||
'http://192.168.1.1/volumes/'),
|
||||
('https://volume.example.com/', 'https://volume.example.com/'))
|
||||
@ddt.unpack
|
||||
def test_get_base_url(self, url, expected_base, mock_get_endpoint):
|
||||
mock_get_endpoint.return_value = url
|
||||
cs = cinderclient.client.SessionClient(self, api_version='3.0')
|
||||
self.assertEqual('http://192.168.122.104:8776/', cs._get_base_url())
|
||||
self.assertEqual(expected_base, cs._get_base_url())
|
||||
|
||||
@mock.patch.object(adapter.Adapter, 'request')
|
||||
@mock.patch.object(exceptions, 'from_response')
|
||||
|
Loading…
Reference in New Issue
Block a user