Skip to content

Commit

Permalink
Connectivity between the endpoint version and OS_VOLUME_API_VERSION.
Browse files Browse the repository at this point in the history
Adds functionality which allows user to work with
that cinder API version which is the same as
the endpoint version.

Fixes: bug #1169455

Change-Id: I9bb46e602d15856d2da502a6ac2b6c25e76f4fa3
  • Loading branch information
Anastasia Latynskaya authored and Anastasia Latynskaya committed Jun 25, 2013
1 parent 93557c1 commit 6adda93
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cinderclient/client.py
Expand Up @@ -369,6 +369,17 @@ def _authenticate(self, url, body):

return self._extract_service_catalog(url, resp, body)

def get_volume_api_version_from_endpoint(self):
magic_tuple = urlparse.urlsplit(self.management_url)
scheme, netloc, path, query, frag = magic_tuple
v = path.split("/")[1]
valid_versions = ['v1', 'v2']
if v not in valid_versions:
msg = "Invalid client version '%s'. must be one of: %s" % (
(v, ', '.join(valid_versions)))
raise exceptions.UnsupportedVersion(msg)
return v[1:]


def get_client_class(version):
version_map = {
Expand Down
4 changes: 4 additions & 0 deletions cinderclient/exceptions.py
Expand Up @@ -10,6 +10,10 @@ class UnsupportedVersion(Exception):
pass


class InvalidAPIVersion(Exception):
pass


class CommandError(Exception):
pass

Expand Down
9 changes: 9 additions & 0 deletions cinderclient/shell.py
Expand Up @@ -448,6 +448,15 @@ def main(self, argv):
except exc.AuthorizationFailure:
raise exc.CommandError("Unable to authorize user")

endpoint_api_version = self.cs.get_volume_api_version_from_endpoint()
if endpoint_api_version != options.os_volume_api_version:
msg = (("Volume API version is set to %s "
"but you are accessing a %s endpoint. "
"Change its value via either --os-volume-api-version "
"or env[OS_VOLUME_API_VERSION]")
% (options.os_volume_api_version, endpoint_api_version))
raise exc.InvalidAPIVersion(msg)

args.func(self.cs, args)

def _run_extension_hooks(self, hook_type, *args, **kwargs):
Expand Down
9 changes: 9 additions & 0 deletions cinderclient/tests/v1/fakes.py
Expand Up @@ -119,6 +119,9 @@ def __init__(self, *args, **kwargs):
extensions=kwargs.get('extensions'))
self.client = FakeHTTPClient(**kwargs)

def get_volume_api_version_from_endpoint(self):
return self.client.get_volume_api_version_from_endpoint()


class FakeHTTPClient(base_client.HTTPClient):

Expand All @@ -127,6 +130,7 @@ def __init__(self, **kwargs):
self.password = 'password'
self.auth_url = 'auth_url'
self.callstack = []
self.management_url = 'http://10.0.2.15:8776/v1/fake'

def _cs_request(self, url, method, **kwargs):
# Check that certain things are called correctly
Expand Down Expand Up @@ -164,6 +168,11 @@ def _cs_request(self, url, method, **kwargs):
else:
return utils.TestResponse({"status": status}), body

def get_volume_api_version_from_endpoint(self):
magic_tuple = urlparse.urlsplit(self.management_url)
scheme, netloc, path, query, frag = magic_tuple
return path.lstrip('/').split('/')[0][1:]

#
# Snapshots
#
Expand Down
2 changes: 1 addition & 1 deletion cinderclient/tests/v1/test_shell.py
Expand Up @@ -32,7 +32,7 @@ class ShellTest(utils.TestCase):
'CINDER_USERNAME': 'username',
'CINDER_PASSWORD': 'password',
'CINDER_PROJECT_ID': 'project_id',
'OS_VOLUME_API_VERSION': '1.1',
'OS_VOLUME_API_VERSION': '1',
'CINDER_URL': 'http://no.where',
}

Expand Down
9 changes: 9 additions & 0 deletions cinderclient/tests/v2/fakes.py
Expand Up @@ -126,6 +126,9 @@ def __init__(self, *args, **kwargs):
extensions=kwargs.get('extensions'))
self.client = FakeHTTPClient(**kwargs)

def get_volume_api_version_from_endpoint(self):
return self.client.get_volume_api_version_from_endpoint()


class FakeHTTPClient(base_client.HTTPClient):

Expand All @@ -134,6 +137,7 @@ def __init__(self, **kwargs):
self.password = 'password'
self.auth_url = 'auth_url'
self.callstack = []
self.management_url = 'http://10.0.2.15:8776/v2/fake'

def _cs_request(self, url, method, **kwargs):
# Check that certain things are called correctly
Expand Down Expand Up @@ -171,6 +175,11 @@ def _cs_request(self, url, method, **kwargs):
else:
return utils.TestResponse({"status": status}), body

def get_volume_api_version_from_endpoint(self):
magic_tuple = urlparse.urlsplit(self.management_url)
scheme, netloc, path, query, frag = magic_tuple
return path.lstrip('/').split('/')[0][1:]

#
# Snapshots
#
Expand Down
3 changes: 3 additions & 0 deletions cinderclient/v1/client.py
Expand Up @@ -98,3 +98,6 @@ def authenticate(self):
credentials are wrong.
"""
self.client.authenticate()

def get_volume_api_version_from_endpoint(self):
return self.client.get_volume_api_version_from_endpoint()
3 changes: 3 additions & 0 deletions cinderclient/v2/client.py
Expand Up @@ -95,3 +95,6 @@ def authenticate(self):
credentials are wrong.
"""
self.client.authenticate()

def get_volume_api_version_from_endpoint(self):
return self.client.get_volume_api_version_from_endpoint()

0 comments on commit 6adda93

Please sign in to comment.