Support version list API in client

The Congress API should be able to list
current supported API versions. This patch
implement the feature in congress client side.

Change-Id: I9d089411640161ea5220a32f078f8c4eb87be1b7
Implements: blueprint api-version
This commit is contained in:
Rui Chen 2015-07-27 15:05:00 +08:00
parent 96931323ab
commit f9858a8106
4 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,40 @@
# Copyright 2015 Huawei.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""List API versions implemenations"""
import logging
from cliff import lister
from congressclient.common import utils
class ListAPIVersions(lister.Lister):
"""List API Versions."""
log = logging.getLogger(__name__ + '.ListAPIVersions')
def get_parser(self, prog_name):
return super(ListAPIVersions, self).get_parser(prog_name)
def take_action(self, parsed_args):
client = self.app.client_manager.congressclient
data = client.list_api_versions()['versions']
# sort API by id
data.sort(key=lambda item: item.get('id'))
columns = ['id', 'status', 'updated']
return (columns,
(utils.get_dict_properties(s, columns) for s in data))

View File

@ -0,0 +1,65 @@
# Copyright 2015 Huawei.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from congressclient.osc.v1 import api_versions
from congressclient.tests import common
class TestAPIVersions(common.TestCongressBase):
def test_list_api_versions(self):
fake_response = {
"versions": [
{
"status": "CURRENT",
"updated": "2015-08-12T17:42:13Z",
"id": "v2",
"links": [
{
"href": "http://localhost:1789/v2/",
"rel": "self"
}
]
},
{
"status": "SUPPORTED",
"updated": "2013-08-12T17:42:13Z",
"id": "v1",
"links": [
{
"href": "http://localhost:1789/v1/",
"rel": "self"
}
]
}
]
}
with mock.patch.object(self.app.client_manager.congressclient,
'list_api_versions',
return_value=fake_response) as lister:
cmd = api_versions.ListAPIVersions(self.app, self.namespace)
parsed_args = self.check_parser(cmd, [], [])
result = cmd.take_action(parsed_args)
lister.assert_called_once_with()
self.assertEqual(['id', 'status', 'updated'], result[0])
self.assertEqual(('v1', 'SUPPORTED', '2013-08-12T17:42:13Z'),
next(result[1]))
self.assertEqual(('v2', 'CURRENT', '2015-08-12T17:42:13Z'),
next(result[1]))

View File

@ -55,6 +55,7 @@ class Client(object):
datasource_rows = '/v1/data-sources/%s/tables/%s/rows'
driver = '/v1/system/drivers'
driver_path = '/v1/system/drivers/%s'
policy_api_versions = '/'
def __init__(self, **kwargs):
super(Client, self).__init__()
@ -187,3 +188,7 @@ class Client(object):
(driver) + "?action=request-refresh",
body=body)
return body
def list_api_versions(self):
resp, body = self.httpclient.get(self.policy_api_versions)
return body

View File

@ -53,6 +53,7 @@ openstack.congressclient.v1 =
congress_driver_config_show = congressclient.osc.v1.driver:ShowDriverConfig
congress_driver_schema_show = congressclient.osc.v1.driver:ShowDriverSchema
congress_driver_list = congressclient.osc.v1.driver:ListDrivers
congress_version_list = congressclient.osc.v1.api_versions:ListAPIVersions
[build_sphinx]
source-dir = doc/source