diff --git a/congressclient/osc/v1/datasource.py b/congressclient/osc/v1/datasource.py index 2df8071..32b1d22 100644 --- a/congressclient/osc/v1/datasource.py +++ b/congressclient/osc/v1/datasource.py @@ -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="", @@ -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): diff --git a/congressclient/tests/v1/test_datasource.py b/congressclient/tests/v1/test_datasource.py index 1d9c5c9..ffe6697 100644 --- a/congressclient/tests/v1/test_datasource.py +++ b/congressclient/tests/v1/test_datasource.py @@ -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): diff --git a/setup.cfg b/setup.cfg index f6eab20..06dc09b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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