Merge "Discover should support other services"
This commit is contained in:
@@ -153,6 +153,13 @@ def available_versions(url, session=None, **kwargs):
|
|||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
pass
|
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
|
# Otherwise if we query an endpoint like /v2.0 then we will get back
|
||||||
# just the one available version.
|
# just the one available version.
|
||||||
try:
|
try:
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
import httpretty
|
||||||
|
import six
|
||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
|
|
||||||
from keystoneclient import client
|
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):
|
def _create_version_list(versions):
|
||||||
return jsonutils.dumps({'versions': {'values': versions}})
|
return jsonutils.dumps({'versions': {'values': versions}})
|
||||||
@@ -165,16 +248,22 @@ V2_VERSION_ENTRY = _create_single_version(V2_VERSION)
|
|||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
class AvailableVersionsTests(utils.TestCase):
|
class AvailableVersionsTests(utils.TestCase):
|
||||||
|
|
||||||
def test_available_versions(self):
|
def test_available_versions_basics(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
examples = {'keystone': V3_VERSION_LIST,
|
||||||
body=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)
|
||||||
|
|
||||||
|
httpretty.register_uri(httpretty.GET, url, status=300, body=ex)
|
||||||
|
versions = discover.available_versions(url)
|
||||||
|
|
||||||
for v in versions:
|
for v in versions:
|
||||||
self.assertIn('id', v)
|
for n in ('id', 'status', 'links'):
|
||||||
self.assertIn('status', v)
|
msg = '%s missing from %s version data' % (n, path)
|
||||||
self.assertIn('links', v)
|
self.assertThat(v, matchers.Annotate(msg,
|
||||||
|
matchers.Contains(n)))
|
||||||
|
|
||||||
def test_available_versions_individual(self):
|
def test_available_versions_individual(self):
|
||||||
httpretty.register_uri(httpretty.GET, V3_URL, status=200,
|
httpretty.register_uri(httpretty.GET, V3_URL, status=200,
|
||||||
@@ -188,6 +277,52 @@ class AvailableVersionsTests(utils.TestCase):
|
|||||||
self.assertIn('media-types', v)
|
self.assertIn('media-types', v)
|
||||||
self.assertIn('links', 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
|
@httpretty.activate
|
||||||
class ClientDiscoveryTests(utils.TestCase):
|
class ClientDiscoveryTests(utils.TestCase):
|
||||||
|
Reference in New Issue
Block a user