Improve status API

The congress-server previously returned the status api response as:
{'results': [{'last_updated': 'now'}, {'last_error': 'foo'}]} though
it would be better if it returned it as:
{'last_updated': 'now', 'last_error': 'foo'}. This patch fixes the client
side of this api call and also corrects the cli command to say show over list.
There is also a server side patch as well that is required for this.

Change-Id: I869d74fac424e608ceeca1984eef9ae73c38dd42
This commit is contained in:
Aaron Rosen
2015-02-05 17:29:38 -08:00
parent 637100e1b2
commit 9b10aded83
3 changed files with 14 additions and 23 deletions

View File

@@ -97,13 +97,13 @@ class ListDatasourceTables(lister.Lister):
for s in data))
class ListDatasourceStatus(lister.Lister):
class ShowDatasourceStatus(show.ShowOne):
"""List status for datasource."""
log = logging.getLogger(__name__ + '.ListDatasourceStatus')
log = logging.getLogger(__name__ + '.ShowDatasourceStatus')
def get_parser(self, prog_name):
parser = super(ListDatasourceStatus, self).get_parser(prog_name)
parser = super(ShowDatasourceStatus, self).get_parser(prog_name)
parser.add_argument(
'datasource_name',
metavar="<datasource-name>",
@@ -118,18 +118,8 @@ class ListDatasourceStatus(lister.Lister):
datasource_id = get_resource_id_from_name(parsed_args.datasource_name,
results)
data = client.list_datasource_status(datasource_id)['results']
newdata = []
for d in data:
temp = [{'key': key, 'value': value}
for key, value in d.items()]
newdata.append(temp[0])
columns = ['key', 'value']
formatters = {'DatasourceStatus': utils.format_list}
return (columns,
(utils.get_dict_properties(s, columns,
formatters=formatters)
for s in newdata))
data = client.list_datasource_status(datasource_id)
return zip(*sorted(six.iteritems(data)))
class ShowDatasourceSchema(lister.Lister):

View File

@@ -76,22 +76,23 @@ class TestListDatasourceStatus(common.TestCongressBase):
verifylist = [
('datasource_name', datasource_name)
]
response = {
"results": [{'last_updated': "now"},
{'last_error': "None"}]
}
response = {'last_updated': "now",
'last_error': "None"}
lister = mock.Mock(return_value=response)
self.app.client_manager.congressclient.list_datasource_status = lister
self.app.client_manager.congressclient.list_datasources = mock.Mock()
cmd = datasource.ListDatasourceStatus(self.app, self.namespace)
cmd = datasource.ShowDatasourceStatus(self.app, self.namespace)
parsed_args = self.check_parser(cmd, arglist, verifylist)
with mock.patch.object(datasource, "get_resource_id_from_name",
return_value="id"):
result = cmd.take_action(parsed_args)
result = list(cmd.take_action(parsed_args))
lister.assert_called_with("id")
self.assertEqual(['key', 'value'], result[0])
self.assertEqual([('last_error', 'last_updated'),
('None', 'now')],
result)
class TestShowDatasourceSchema(common.TestCongressBase):

View File

@@ -43,7 +43,7 @@ openstack.congressclient.v1 =
congress_datasource_delete = congressclient.osc.v1.datasource:DeleteDatasource
congress_datasource_table_list = congressclient.osc.v1.datasource:ListDatasourceTables
congress_datasource_row_list = congressclient.osc.v1.datasource:ListDatasourceRows
congress_datasource_status_list = congressclient.osc.v1.datasource:ListDatasourceStatus
congress_datasource_status_show = congressclient.osc.v1.datasource:ShowDatasourceStatus
congress_datasource_schema_show = congressclient.osc.v1.datasource:ShowDatasourceSchema
congress_datasource_table_schema_show = congressclient.osc.v1.datasource:ShowDatasourceTableSchema
congress_policy_table_show = congressclient.osc.v1.policy:ShowPolicyTable