summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Antonio Osorio Robles <juan.osorio.robles@ericsson.com>2015-05-20 03:50:29 +0300
committerJuan Antonio Osorio Robles <juan.osorio.robles@ericsson.com>2015-05-20 19:44:38 +0300
commit240c5812678400ab4b823b1e2f8bff7a8a55cb48 (patch)
treea6dd40eb4ac774d5bd6a9390ece8ba953cb4b3eb
parent4c4b8e8025cd4012d5bf7879061b63d9e13e2f4f (diff)
downloadpython-barbicanclient-240c5812678400ab4b823b1e2f8bff7a8a55cb48.tar.gz
Add capability of specifying Barbican version to client
While specifying the version of the Barbican API was possible before, this was being ignored on the client and the default version was always hardcoded. This CR now takes that into account and will append the version to the base endpoint. Change-Id: I2bd8bf64792dd91d7b79709398840c0c2d07a69d
-rw-r--r--barbicanclient/client.py8
-rw-r--r--functionaltests/client/test_client_connectivity.py15
2 files changed, 21 insertions, 2 deletions
diff --git a/barbicanclient/client.py b/barbicanclient/client.py
index 939f8fb..7f0a6b2 100644
--- a/barbicanclient/client.py
+++ b/barbicanclient/client.py
@@ -38,15 +38,19 @@ class _HTTPClient(adapter.Adapter):
def __init__(self, session, project_id=None, **kwargs):
kwargs.setdefault('interface', _DEFAULT_SERVICE_INTERFACE)
kwargs.setdefault('service_type', _DEFAULT_SERVICE_TYPE)
+ kwargs.setdefault('version', _DEFAULT_API_VERSION)
endpoint = kwargs.pop('endpoint', None)
super(_HTTPClient, self).__init__(session, **kwargs)
if not endpoint:
endpoint = self.get_endpoint()
+ # NOTE(jaosorior): We are manually appending the given version. This
+ # could be filled automatically by keystoneclient; but
+ # we need the fix-version-api blueprint to land in the
+ # server first.
+ self.endpoint_override = '{0}/{1}'.format(endpoint, self.version)
- self.endpoint_override = '{0}/{1}'.format(endpoint,
- _DEFAULT_API_VERSION)
if project_id is None:
self._default_headers = dict()
else:
diff --git a/functionaltests/client/test_client_connectivity.py b/functionaltests/client/test_client_connectivity.py
index 31d5e12..c2a28ea 100644
--- a/functionaltests/client/test_client_connectivity.py
+++ b/functionaltests/client/test_client_connectivity.py
@@ -16,6 +16,7 @@ import logging
from functionaltests.base import BaseTestCase
from barbicanclient import client
+from barbicanclient import exceptions
from keystoneclient.auth import identity
from keystoneclient import session
from tempest import config
@@ -64,6 +65,11 @@ class WhenTestingClientConnectivity(BaseTestCase):
self.assertIsNotNone(orders)
self.assertIsNotNone(secrets)
+ def assert_client_cannot_contact_barbican(self, client):
+ self.assertRaises(exceptions.HTTPClientError, client.containers.list)
+ self.assertRaises(exceptions.HTTPClientError, client.orders.list)
+ self.assertRaises(exceptions.HTTPClientError, client.secrets.list)
+
def test_can_access_server_if_endpoint_and_session_specified(self):
barbicanclient = client.Client(
endpoint=CONF.keymanager.url,
@@ -86,3 +92,12 @@ class WhenTestingClientConnectivity(BaseTestCase):
auth=self.auth)
self.assert_client_can_contact_barbican(barbicanclient)
+
+ def test_client_cannot_access_server_if_nonexistent_version_specified(self):
+ barbicanclient = client.Client(
+ endpoint=CONF.keymanager.url,
+ project_id=CONF.keymanager.project_id,
+ auth=self.auth,
+ version='nonexistent_version')
+
+ self.assert_client_cannot_contact_barbican(barbicanclient)