Add "get_current" method to VersionManager
get_current returns the current endpoint's API version info. Related to bp api-microversion-support Co-Authored-By: Alex Xu <hejie.xu@intel.com> Change-Id: I36e84680c578a88d5c274f8ca24ecd18d1f3a179
This commit is contained in:
parent
936cf572df
commit
eddb4d61c2
novaclient
@ -58,6 +58,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
self.os_cache = 'os_cache'
|
||||
self.http_log_debug = 'http_log_debug'
|
||||
self.last_request_id = None
|
||||
self.management_url = self.get_endpoint()
|
||||
|
||||
def _cs_request(self, url, method, **kwargs):
|
||||
# Check that certain things are called correctly
|
||||
@ -81,6 +82,8 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
# To get API version information, it is necessary to GET
|
||||
# a nova endpoint directly without "v2/<tenant-id>".
|
||||
callback = "get_versions"
|
||||
elif callback == "get_http:__nova_api:8774_v2_1":
|
||||
callback = "get_current_version"
|
||||
|
||||
if not hasattr(self, callback):
|
||||
raise AssertionError('Called unknown API method: %s %s, '
|
||||
@ -99,7 +102,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
return r, body
|
||||
|
||||
def get_endpoint(self):
|
||||
return "http://nova-api:8774/v2/190a755eef2e4aac9f06aa6be9786385"
|
||||
return "http://nova-api:8774/v2.1/190a755eef2e4aac9f06aa6be9786385"
|
||||
|
||||
def get_versions(self):
|
||||
return (200, {}, {
|
||||
@ -118,6 +121,16 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"id": "v2.1"}
|
||||
]})
|
||||
|
||||
def get_current_version(self):
|
||||
return (200, {}, {
|
||||
"version": {"status": "CURRENT",
|
||||
"updated": "2013-07-23T11:33:21Z",
|
||||
"links": [{"href": "http://nova-api:8774/v2.1/",
|
||||
"rel": "self"}],
|
||||
"min_version": "2.1",
|
||||
"version": "2.3",
|
||||
"id": "v2.1"}})
|
||||
|
||||
#
|
||||
# agents
|
||||
#
|
||||
|
@ -36,3 +36,31 @@ class VersionsTest(utils.TestCase):
|
||||
def test_list_services_with_session_client(self, mock_is_session_client):
|
||||
self.cs.versions.list()
|
||||
self.cs.assert_called('GET', 'http://nova-api:8774/')
|
||||
|
||||
@mock.patch.object(versions.VersionManager, '_is_session_client',
|
||||
return_value=False)
|
||||
@mock.patch.object(versions.VersionManager, 'list')
|
||||
def test_get_current_with_http_client(self, mock_list,
|
||||
mock_is_session_client):
|
||||
current_version = versions.Version(
|
||||
None, {"links": [{"href": "http://nova-api:8774/v2.1"}]},
|
||||
loaded=True)
|
||||
|
||||
mock_list.return_value = [
|
||||
versions.Version(
|
||||
None, {"links": [{"href": "http://url/v1"}]}, loaded=True),
|
||||
versions.Version(
|
||||
None, {"links": [{"href": "http://url/v2"}]}, loaded=True),
|
||||
versions.Version(
|
||||
None, {"links": [{"href": "http://url/v3"}]}, loaded=True),
|
||||
current_version,
|
||||
versions.Version(
|
||||
None, {"links": [{"href": "http://url/v21"}]}, loaded=True)]
|
||||
self.assertEqual(current_version, self.cs.versions.get_current())
|
||||
|
||||
@mock.patch.object(versions.VersionManager, '_is_session_client',
|
||||
return_value=True)
|
||||
def test_get_current_with_session_client(self, mock_is_session_client):
|
||||
self.cs.callback = []
|
||||
self.cs.versions.get_current()
|
||||
self.cs.assert_called('GET', 'http://nova-api:8774/v2.1')
|
||||
|
@ -36,6 +36,21 @@ class VersionManager(base.ManagerWithFind):
|
||||
def _is_session_client(self):
|
||||
return isinstance(self.api.client, client.SessionClient)
|
||||
|
||||
def get_current(self):
|
||||
"""Returns info about current version."""
|
||||
if self._is_session_client():
|
||||
url = self.api.client.get_endpoint().rsplit("/", 1)[0]
|
||||
return self._get(url, "version")
|
||||
else:
|
||||
# NOTE(andreykurilin): HTTPClient doesn't have ability to send get
|
||||
# request without token in the url, so `self._get` doesn't work.
|
||||
all_versions = self.list()
|
||||
url = self.client.management_url.rsplit("/", 1)[0]
|
||||
for version in all_versions:
|
||||
for link in version.links:
|
||||
if link["href"].rstrip('/') == url:
|
||||
return version
|
||||
|
||||
def list(self):
|
||||
"""List all versions."""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user