Fix get_highest_client_server_version with Cinder API + uWSGI
get_highest_client_server_version should work with any endpoint type: cinder-api with eventlet, uWSGI, etc. This patch is based on python-novaclient patch [1]. In a future, we can deprecate get_highest_client_server_version in flavor of keystoneauth descovery feature. [1] Icba858b496855e2ffd71b35168e8057b28236119 Closes-Bug: #1708188 Change-Id: I9acf6dc84c32b25bfe3254eb0f97248736498d32
This commit is contained in:
parent
370566e2e9
commit
19bb7cdf4f
|
@ -39,6 +39,7 @@ from oslo_utils import importutils
|
|||
from oslo_utils import strutils
|
||||
osprofiler_web = importutils.try_import("osprofiler.web") # noqa
|
||||
import requests
|
||||
from six.moves import urllib
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from cinderclient import api_versions
|
||||
|
@ -83,8 +84,29 @@ def get_server_version(url):
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
try:
|
||||
scheme, netloc, path, query, frag = urlparse.urlsplit(url)
|
||||
response = requests.get(scheme + '://' + netloc)
|
||||
u = urllib.parse.urlparse(url)
|
||||
version_url = None
|
||||
|
||||
# NOTE(andreykurilin): endpoint URL has at least 2 formats:
|
||||
# 1. The classic (legacy) endpoint:
|
||||
# http://{host}:{optional_port}/v{1 or 2 or 3}/{project-id}
|
||||
# http://{host}:{optional_port}/v{1 or 2 or 3}
|
||||
# 3. Under wsgi:
|
||||
# http://{host}:{optional_port}/volume/v{1 or 2 or 3}
|
||||
for ver in ['v1', 'v2', 'v3']:
|
||||
if u.path.endswith(ver) or "/{0}/".format(ver) in u.path:
|
||||
path = u.path[:u.path.rfind(ver)]
|
||||
version_url = '%s://%s%s' % (u.scheme, u.netloc, path)
|
||||
break
|
||||
|
||||
if not version_url:
|
||||
# NOTE(andreykurilin): probably, it is one of the next cases:
|
||||
# * https://volume.example.com/
|
||||
# * https://example.com/volume
|
||||
# leave as is without cropping.
|
||||
version_url = url
|
||||
|
||||
response = requests.get(version_url)
|
||||
data = json.loads(response.text)
|
||||
versions = data['versions']
|
||||
for version in versions:
|
||||
|
|
|
@ -332,8 +332,12 @@ class GetAPIVersionTestCase(utils.TestCase):
|
|||
self.assertEqual(api_versions.APIVersion('2.0'), max_version)
|
||||
|
||||
@mock.patch('cinderclient.client.requests.get')
|
||||
def test_get_server_version(self, mock_request):
|
||||
|
||||
@ddt.data(
|
||||
'http://192.168.122.127:8776/v3/e5526285ebd741b1819393f772f11fc3',
|
||||
'https://192.168.122.127:8776/v3/e55285ebd741b1819393f772f11fc3',
|
||||
'http://192.168.122.127/volumesv3/e5526285ebd741b1819393f772f11fc3'
|
||||
)
|
||||
def test_get_server_version(self, url, mock_request):
|
||||
mock_response = utils.TestResponse({
|
||||
"status_code": 200,
|
||||
"text": json.dumps(fakes.fake_request_get())
|
||||
|
@ -341,14 +345,6 @@ class GetAPIVersionTestCase(utils.TestCase):
|
|||
|
||||
mock_request.return_value = mock_response
|
||||
|
||||
url = "http://192.168.122.127:8776/v3/e5526285ebd741b1819393f772f11fc3"
|
||||
|
||||
min_version, max_version = cinderclient.client.get_server_version(url)
|
||||
self.assertEqual(min_version, api_versions.APIVersion('3.0'))
|
||||
self.assertEqual(max_version, api_versions.APIVersion('3.16'))
|
||||
|
||||
url = "https://192.168.122.127:8776/v3/e55285ebd741b1819393f772f11fc3"
|
||||
|
||||
min_version, max_version = cinderclient.client.get_server_version(url)
|
||||
self.assertEqual(min_version, api_versions.APIVersion('3.0'))
|
||||
self.assertEqual(max_version, api_versions.APIVersion('3.16'))
|
||||
|
|
Loading…
Reference in New Issue