summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-03-26 00:32:20 +0000
committerGerrit Code Review <review@openstack.org>2014-03-26 00:32:20 +0000
commit16ca30673773ff4e30c4165e7b355cedc65c789b (patch)
tree2c435712a42b7f590f4d52111a7ea3c47242e65f
parent028bdb851967698b1239f33ab3c4296ee8d25553 (diff)
parentba530a44fbb6c591647a98405b27a64809f8b3c4 (diff)
downloadpython-keystoneclient-0.7.0.tar.gz
Merge "Discover should support other services"0.7.0
-rw-r--r--keystoneclient/discover.py7
-rw-r--r--keystoneclient/tests/test_discovery.py151
2 files changed, 150 insertions, 8 deletions
diff --git a/keystoneclient/discover.py b/keystoneclient/discover.py
index 9c6313f..77cc00e 100644
--- a/keystoneclient/discover.py
+++ b/keystoneclient/discover.py
@@ -153,6 +153,13 @@ def available_versions(url, session=None, **kwargs):
except (KeyError, TypeError):
pass
+ # Most servers don't have a 'values' element so accept a simple
+ # versions dict if available.
+ try:
+ return body_resp['versions']
+ except KeyError:
+ pass
+
# Otherwise if we query an endpoint like /v2.0 then we will get back
# just the one available version.
try:
diff --git a/keystoneclient/tests/test_discovery.py b/keystoneclient/tests/test_discovery.py
index 0d32d7d..e55151f 100644
--- a/keystoneclient/tests/test_discovery.py
+++ b/keystoneclient/tests/test_discovery.py
@@ -11,6 +11,7 @@
# under the License.
import httpretty
+import six
from testtools import matchers
from keystoneclient import client
@@ -146,6 +147,88 @@ V3_AUTH_RESPONSE = jsonutils.dumps({
},
})
+CINDER_EXAMPLES = {
+ "versions": [
+ {
+ "status": "CURRENT",
+ "updated": "2012-01-04T11:33:21Z",
+ "id": "v1.0",
+ "links": [
+ {
+ "href": "%sv1/" % BASE_URL,
+ "rel": "self"
+ }
+ ]
+ },
+ {
+ "status": "CURRENT",
+ "updated": "2012-11-21T11:33:21Z",
+ "id": "v2.0",
+ "links": [
+ {
+ "href": "%sv2/" % BASE_URL,
+ "rel": "self"
+ }
+ ]
+ }
+ ]
+}
+
+GLANCE_EXAMPLES = {
+ "versions": [
+ {
+ "status": "CURRENT",
+ "id": "v2.2",
+ "links": [
+ {
+ "href": "%sv2/" % BASE_URL,
+ "rel": "self"
+ }
+ ]
+ },
+ {
+ "status": "SUPPORTED",
+ "id": "v2.1",
+ "links": [
+ {
+ "href": "%sv2/" % BASE_URL,
+ "rel": "self"
+ }
+ ]
+ },
+ {
+ "status": "SUPPORTED",
+ "id": "v2.0",
+ "links": [
+ {
+ "href": "%sv2/" % BASE_URL,
+ "rel": "self"
+ }
+ ]
+ },
+ {
+ "status": "CURRENT",
+ "id": "v1.1",
+ "links": [
+ {
+ "href": "%sv1/" % BASE_URL,
+ "rel": "self"
+ }
+ ]
+ },
+ {
+ "status": "SUPPORTED",
+ "id": "v1.0",
+ "links": [
+ {
+ "href": "%sv1/" % BASE_URL,
+ "rel": "self"
+ }
+ ]
+ }
+ ]
+}
+
def _create_version_list(versions):
return jsonutils.dumps({'versions': {'values': versions}})
@@ -165,16 +248,22 @@ V2_VERSION_ENTRY = _create_single_version(V2_VERSION)
@httpretty.activate
class AvailableVersionsTests(utils.TestCase):
- def test_available_versions(self):
- httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
- body=V3_VERSION_LIST)
+ def test_available_versions_basics(self):
+ examples = {'keystone': V3_VERSION_LIST,
+ 'cinder': jsonutils.dumps(CINDER_EXAMPLES),
+ 'glance': jsonutils.dumps(GLANCE_EXAMPLES)}
- versions = discover.available_versions(BASE_URL)
+ for path, ex in six.iteritems(examples):
+ url = "%s%s" % (BASE_URL, path)
- for v in versions:
- self.assertIn('id', v)
- self.assertIn('status', v)
- self.assertIn('links', v)
+ httpretty.register_uri(httpretty.GET, url, status=300, body=ex)
+ versions = discover.available_versions(url)
+
+ for v in versions:
+ for n in ('id', 'status', 'links'):
+ msg = '%s missing from %s version data' % (n, path)
+ self.assertThat(v, matchers.Annotate(msg,
+ matchers.Contains(n)))
def test_available_versions_individual(self):
httpretty.register_uri(httpretty.GET, V3_URL, status=200,
@@ -188,6 +277,52 @@ class AvailableVersionsTests(utils.TestCase):
self.assertIn('media-types', v)
self.assertIn('links', v)
+ def test_available_keystone_data(self):
+ httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
+ body=V3_VERSION_LIST)
+
+ versions = discover.available_versions(BASE_URL)
+ self.assertEqual(2, len(versions))
+
+ for v in versions:
+ self.assertIn(v['id'], ('v2.0', 'v3.0'))
+ self.assertEqual(v['updated'], UPDATED)
+ self.assertEqual(v['status'], 'stable')
+
+ if v['id'] == 'v3.0':
+ self.assertEqual(v['media-types'], V3_MEDIA_TYPES)
+
+ def test_available_cinder_data(self):
+ body = jsonutils.dumps(CINDER_EXAMPLES)
+ httpretty.register_uri(httpretty.GET, BASE_URL, status=300, body=body)
+
+ versions = discover.available_versions(BASE_URL)
+ self.assertEqual(2, len(versions))
+
+ for v in versions:
+ self.assertEqual(v['status'], 'CURRENT')
+ if v['id'] == 'v1.0':
+ self.assertEqual(v['updated'], '2012-01-04T11:33:21Z')
+ elif v['id'] == 'v2.0':
+ self.assertEqual(v['updated'], '2012-11-21T11:33:21Z')
+ else:
+ self.fail("Invalid version found")
+
+ def test_available_glance_data(self):
+ body = jsonutils.dumps(GLANCE_EXAMPLES)
+ httpretty.register_uri(httpretty.GET, BASE_URL, status=200, body=body)
+
+ versions = discover.available_versions(BASE_URL)
+ self.assertEqual(5, len(versions))
+
+ for v in versions:
+ if v['id'] in ('v2.2', 'v1.1'):
+ self.assertEqual(v['status'], 'CURRENT')
+ elif v['id'] in ('v2.1', 'v2.0', 'v1.0'):
+ self.assertEqual(v['status'], 'SUPPORTED')
+ else:
+ self.fail("Invalid version found")
+
@httpretty.activate
class ClientDiscoveryTests(utils.TestCase):