summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-08-08 17:31:12 +0000
committerGerrit Code Review <review@openstack.org>2017-08-08 17:31:12 +0000
commitea56d5331c30e59b15cd448833af6103d5d79bd6 (patch)
tree00f6f02a134455b4cce77b69c2b29f6cacf41d6c
parent4b72b7ab72542db7f08f995bb38cab5b3008bf74 (diff)
parentb321dd798575a4e39c01f3b6db29d875cd142fe2 (diff)
downloadpython-cinderclient-ea56d5331c30e59b15cd448833af6103d5d79bd6.tar.gz
Merge "Fix get_highest_client_server_version with Cinder API + uWSGI" into stable/pike
-rw-r--r--cinderclient/client.py26
-rw-r--r--cinderclient/tests/unit/test_client.py16
2 files changed, 30 insertions, 12 deletions
diff --git a/cinderclient/client.py b/cinderclient/client.py
index dabfcd3..6537cfe 100644
--- a/cinderclient/client.py
+++ b/cinderclient/client.py
@@ -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:
diff --git a/cinderclient/tests/unit/test_client.py b/cinderclient/tests/unit/test_client.py
index bd3b3f6..5697039 100644
--- a/cinderclient/tests/unit/test_client.py
+++ b/cinderclient/tests/unit/test_client.py
@@ -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'))