Merge "static method to get_server_version"
This commit is contained in:
@@ -40,6 +40,7 @@ from cinderclient import api_versions
|
|||||||
from cinderclient import exceptions
|
from cinderclient import exceptions
|
||||||
import cinderclient.extension
|
import cinderclient.extension
|
||||||
from cinderclient._i18n import _
|
from cinderclient._i18n import _
|
||||||
|
from cinderclient._i18n import _LW
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
@@ -72,6 +73,30 @@ for svc in ('volume', 'volumev2', 'volumev3'):
|
|||||||
discover.add_catalog_discover_hack(svc, re.compile('/v[12]/\w+/?$'), '/')
|
discover.add_catalog_discover_hack(svc, re.compile('/v[12]/\w+/?$'), '/')
|
||||||
|
|
||||||
|
|
||||||
|
def get_server_version(url):
|
||||||
|
"""Queries the server via the naked endpoint and gets version info.
|
||||||
|
|
||||||
|
:param url: url of the cinder endpoint
|
||||||
|
:returns: APIVersion object for min and max version supported by
|
||||||
|
the server
|
||||||
|
"""
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
try:
|
||||||
|
scheme, netloc, path, query, frag = urlparse.urlsplit(url)
|
||||||
|
response = requests.get(scheme + '://' + netloc)
|
||||||
|
data = json.loads(response.text)
|
||||||
|
versions = data['versions']
|
||||||
|
for version in versions:
|
||||||
|
if '3.' in version['version']:
|
||||||
|
return (api_versions.APIVersion(version['min_version']),
|
||||||
|
api_versions.APIVersion(version['version']))
|
||||||
|
except exceptions.ClientException as e:
|
||||||
|
logger.warning(_LW("Error in server version query:%s\n"
|
||||||
|
"Returning APIVersion 2.0") % six.text_type(e.message))
|
||||||
|
return api_versions.APIVersion("2.0"), api_versions.APIVersion("2.0")
|
||||||
|
|
||||||
|
|
||||||
def get_volume_api_from_url(url):
|
def get_volume_api_from_url(url):
|
||||||
scheme, netloc, path, query, frag = urlparse.urlsplit(url)
|
scheme, netloc, path, query, frag = urlparse.urlsplit(url)
|
||||||
components = path.split("/")
|
components = path.split("/")
|
||||||
|
@@ -24,8 +24,11 @@ import six
|
|||||||
import cinderclient.client
|
import cinderclient.client
|
||||||
import cinderclient.v1.client
|
import cinderclient.v1.client
|
||||||
import cinderclient.v2.client
|
import cinderclient.v2.client
|
||||||
|
from cinderclient import api_versions
|
||||||
from cinderclient import exceptions
|
from cinderclient import exceptions
|
||||||
|
from cinderclient import utils
|
||||||
from cinderclient.tests.unit import utils
|
from cinderclient.tests.unit import utils
|
||||||
|
from cinderclient.tests.unit.v3 import fakes
|
||||||
|
|
||||||
|
|
||||||
class ClientTest(utils.TestCase):
|
class ClientTest(utils.TestCase):
|
||||||
@@ -304,3 +307,28 @@ class ClientTestSensitiveInfo(utils.TestCase):
|
|||||||
output = self.logger.output.split('\n')
|
output = self.logger.output.split('\n')
|
||||||
self.assertIn('***', output[1], output)
|
self.assertIn('***', output[1], output)
|
||||||
self.assertNotIn(auth_password, output[1], output)
|
self.assertNotIn(auth_password, output[1], output)
|
||||||
|
|
||||||
|
|
||||||
|
class GetAPIVersionTestCase(utils.TestCase):
|
||||||
|
|
||||||
|
@mock.patch('cinderclient.client.requests.get')
|
||||||
|
def test_get_server_version(self, mock_request):
|
||||||
|
|
||||||
|
mock_response = utils.TestResponse({
|
||||||
|
"status_code": 200,
|
||||||
|
"text": json.dumps(fakes.fake_request_get())
|
||||||
|
})
|
||||||
|
|
||||||
|
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'))
|
||||||
|
@@ -460,3 +460,43 @@ class FakeHTTPClient(fake_v2.FakeHTTPClient):
|
|||||||
'guaranteed_until': "2013-11-12T21:00:00.000000",
|
'guaranteed_until': "2013-11-12T21:00:00.000000",
|
||||||
}
|
}
|
||||||
return 200, {}, {'message': message}
|
return 200, {}, {'message': message}
|
||||||
|
|
||||||
|
|
||||||
|
def fake_request_get():
|
||||||
|
versions = {'versions': [{'id': 'v1.0',
|
||||||
|
'links': [{'href': 'http://docs.openstack.org/',
|
||||||
|
'rel': 'describedby',
|
||||||
|
'type': 'text/html'},
|
||||||
|
{'href': 'http://192.168.122.197/v1/',
|
||||||
|
'rel': 'self'}],
|
||||||
|
'media-types': [{'base': 'application/json',
|
||||||
|
'type': 'application/'}],
|
||||||
|
'min_version': '',
|
||||||
|
'status': 'DEPRECATED',
|
||||||
|
'updated': '2016-05-02T20:25:19Z',
|
||||||
|
'version': ''},
|
||||||
|
{'id': 'v2.0',
|
||||||
|
'links': [{'href': 'http://docs.openstack.org/',
|
||||||
|
'rel': 'describedby',
|
||||||
|
'type': 'text/html'},
|
||||||
|
{'href': 'http://192.168.122.197/v2/',
|
||||||
|
'rel': 'self'}],
|
||||||
|
'media-types': [{'base': 'application/json',
|
||||||
|
'type': 'application/'}],
|
||||||
|
'min_version': '',
|
||||||
|
'status': 'SUPPORTED',
|
||||||
|
'updated': '2014-06-28T12:20:21Z',
|
||||||
|
'version': ''},
|
||||||
|
{'id': 'v3.0',
|
||||||
|
'links': [{'href': 'http://docs.openstack.org/',
|
||||||
|
'rel': 'describedby',
|
||||||
|
'type': 'text/html'},
|
||||||
|
{'href': 'http://192.168.122.197/v3/',
|
||||||
|
'rel': 'self'}],
|
||||||
|
'media-types': [{'base': 'application/json',
|
||||||
|
'type': 'application/'}],
|
||||||
|
'min_version': '3.0',
|
||||||
|
'status': 'CURRENT',
|
||||||
|
'updated': '2016-02-08T12:20:21Z',
|
||||||
|
'version': '3.16'}]}
|
||||||
|
return versions
|
||||||
|
Reference in New Issue
Block a user