Added datasource status command

$ openstack congress datasource status list

Change-Id: I77163e85457ef6a1410c0fc5f647f8c8d9eb236f
This commit is contained in:
Tim Hinrichs 2014-10-16 07:10:06 -07:00
parent c96e9846b7
commit bcb1b90b10
4 changed files with 57 additions and 0 deletions

View File

@ -67,6 +67,32 @@ class ListDatasourceTables(lister.Lister):
for s in data))
class ListDatasourceStatus(lister.Lister):
"""List status for datasource."""
log = logging.getLogger(__name__ + '.ListDatasourceStatus')
def get_parser(self, prog_name):
parser = super(ListDatasourceStatus, self).get_parser(prog_name)
parser.add_argument(
'datasource_name',
metavar="<datasource-name>",
help="Name of the datasource")
return parser
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
client = self.app.client_manager.congressclient
data = client.list_datasource_status(
parsed_args.datasource_name)['results']
columns = ['key', 'value']
formatters = {'DatasourceStatus': utils.format_list}
return (columns,
(utils.get_dict_properties(s, columns,
formatters=formatters)
for s in data))
class ListDatasourceRows(lister.Lister):
"""List datasource rows."""

View File

@ -67,6 +67,30 @@ class TestListDatasourceTables(common.TestCongressBase):
self.assertEqual(['id'], result[0])
class TestListDatasourceStatus(common.TestCongressBase):
def test_list_datasource_status(self):
datasource_name = 'neutron'
arglist = [
datasource_name
]
verifylist = [
('datasource_name', datasource_name)
]
response = {
"results": [("last_updated", "now"),
("last_error", "None")]
}
lister = mock.Mock(return_value=response)
self.app.client_manager.congressclient.list_datasource_status = lister
cmd = datasource.ListDatasourceStatus(self.app, self.namespace)
parsed_args = self.check_parser(cmd, arglist, verifylist)
result = cmd.take_action(parsed_args)
lister.assert_called_with(datasource_name)
self.assertEqual(['key', 'value'], result[0])
class TestListDatasourceRows(common.TestCongressBase):
def test_list_datasource_row(self):

View File

@ -46,6 +46,7 @@ class Client(object):
policy_action = '/v1/policies/%s?%s'
datasources = '/v1/data-sources'
datasource_tables = '/v1/data-sources/%s/tables'
datasource_status = '/v1/data-sources/%s/status'
datasource_rows = '/v1/data-sources/%s/tables/%s/rows'
def __init__(self, **kwargs):
@ -110,3 +111,8 @@ class Client(object):
resp, body = self.httpclient.get(self.datasource_rows %
(datasource_name, table_name))
return body
def list_datasource_status(self, datasource_name):
resp, body = self.httpclient.get(self.datasource_status %
datasource_name)
return body

View File

@ -39,6 +39,7 @@ openstack.congressclient.v1 =
congress_datasource_list = congressclient.osc.v1.datasource:ListDatasources
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
[build_sphinx]
source-dir = doc/source