Remove unnecessary db calls to list_datasources
This commit removes unnecessary db calls to list_datasources as the api calls work for both datasource name or id Change-Id: I4028f88cbdabe2752b2b78250dbc2a011532604e Closes-Bug:#1647535
This commit is contained in:
parent
d769eed682
commit
0fd8e34c55
|
@ -62,10 +62,8 @@ class ListDatasourceTables(lister.Lister):
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)' % parsed_args)
|
self.log.debug('take_action(%s)' % parsed_args)
|
||||||
client = self.app.client_manager.congressclient
|
client = self.app.client_manager.congressclient
|
||||||
results = client.list_datasources()
|
name_or_id = parsed_args.datasource_name
|
||||||
datasource_id = utils.get_resource_id_from_name(
|
data = client.list_datasource_tables(name_or_id)['results']
|
||||||
parsed_args.datasource_name, results)
|
|
||||||
data = client.list_datasource_tables(datasource_id)['results']
|
|
||||||
columns = ['id']
|
columns = ['id']
|
||||||
formatters = {'DatasourceTables': utils.format_list}
|
formatters = {'DatasourceTables': utils.format_list}
|
||||||
return (columns,
|
return (columns,
|
||||||
|
@ -90,11 +88,7 @@ class ShowDatasourceStatus(show.ShowOne):
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)' % parsed_args)
|
self.log.debug('take_action(%s)' % parsed_args)
|
||||||
client = self.app.client_manager.congressclient
|
client = self.app.client_manager.congressclient
|
||||||
|
datasource_id = parsed_args.datasource_name
|
||||||
results = client.list_datasources()
|
|
||||||
datasource_id = utils.get_resource_id_from_name(
|
|
||||||
parsed_args.datasource_name, results)
|
|
||||||
|
|
||||||
data = client.list_datasource_status(datasource_id)
|
data = client.list_datasource_status(datasource_id)
|
||||||
return zip(*sorted(six.iteritems(data)))
|
return zip(*sorted(six.iteritems(data)))
|
||||||
|
|
||||||
|
@ -119,11 +113,7 @@ class ShowDatasourceActions(lister.Lister):
|
||||||
parsed_args.max_width = 40
|
parsed_args.max_width = 40
|
||||||
|
|
||||||
client = self.app.client_manager.congressclient
|
client = self.app.client_manager.congressclient
|
||||||
|
datasource_id = parsed_args.datasource_name
|
||||||
results = client.list_datasources()
|
|
||||||
datasource_id = utils.get_resource_id_from_name(
|
|
||||||
parsed_args.datasource_name, results)
|
|
||||||
|
|
||||||
data = client.list_datasource_actions(datasource_id)
|
data = client.list_datasource_actions(datasource_id)
|
||||||
formatters = {'args': utils.format_long_dict_list}
|
formatters = {'args': utils.format_long_dict_list}
|
||||||
newdata = [{'action': x['name'],
|
newdata = [{'action': x['name'],
|
||||||
|
@ -153,9 +143,7 @@ class ShowDatasourceSchema(lister.Lister):
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)' % parsed_args)
|
self.log.debug('take_action(%s)' % parsed_args)
|
||||||
client = self.app.client_manager.congressclient
|
client = self.app.client_manager.congressclient
|
||||||
results = client.list_datasources()
|
datasource_id = parsed_args.datasource_name
|
||||||
datasource_id = utils.get_resource_id_from_name(
|
|
||||||
parsed_args.datasource_name, results)
|
|
||||||
data = client.show_datasource_schema(datasource_id)
|
data = client.show_datasource_schema(datasource_id)
|
||||||
formatters = {'columns': utils.format_long_dict_list}
|
formatters = {'columns': utils.format_long_dict_list}
|
||||||
newdata = [{'table': x['table_id'],
|
newdata = [{'table': x['table_id'],
|
||||||
|
@ -188,9 +176,7 @@ class ShowDatasourceTableSchema(lister.Lister):
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)' % parsed_args)
|
self.log.debug('take_action(%s)' % parsed_args)
|
||||||
client = self.app.client_manager.congressclient
|
client = self.app.client_manager.congressclient
|
||||||
results = client.list_datasources()
|
datasource_id = parsed_args.datasource_name
|
||||||
datasource_id = utils.get_resource_id_from_name(
|
|
||||||
parsed_args.datasource_name, results)
|
|
||||||
data = client.show_datasource_table_schema(
|
data = client.show_datasource_table_schema(
|
||||||
datasource_id,
|
datasource_id,
|
||||||
parsed_args.table_name)
|
parsed_args.table_name)
|
||||||
|
@ -220,10 +206,7 @@ class ListDatasourceRows(lister.Lister):
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)' % parsed_args)
|
self.log.debug('take_action(%s)' % parsed_args)
|
||||||
client = self.app.client_manager.congressclient
|
client = self.app.client_manager.congressclient
|
||||||
|
datasource_id = parsed_args.datasource_name
|
||||||
results = client.list_datasources()
|
|
||||||
datasource_id = utils.get_resource_id_from_name(
|
|
||||||
parsed_args.datasource_name, results)
|
|
||||||
results = client.list_datasource_rows(datasource_id,
|
results = client.list_datasource_rows(datasource_id,
|
||||||
parsed_args.table)['results']
|
parsed_args.table)['results']
|
||||||
if results:
|
if results:
|
||||||
|
@ -317,9 +300,7 @@ class DeleteDatasource(command.Command):
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)' % parsed_args)
|
self.log.debug('take_action(%s)' % parsed_args)
|
||||||
client = self.app.client_manager.congressclient
|
client = self.app.client_manager.congressclient
|
||||||
results = client.list_datasources()
|
datasource_id = parsed_args.datasource
|
||||||
datasource_id = utils.get_resource_id_from_name(
|
|
||||||
parsed_args.datasource, results)
|
|
||||||
client.delete_datasource(datasource_id)
|
client.delete_datasource(datasource_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -96,16 +96,13 @@ class TestListDatasourceTables(common.TestCongressBase):
|
||||||
{"id": "networks"}]
|
{"id": "networks"}]
|
||||||
}
|
}
|
||||||
lister = mock.Mock(return_value=response)
|
lister = mock.Mock(return_value=response)
|
||||||
self.app.client_manager.congressclient.list_datasources = mock.Mock()
|
|
||||||
self.app.client_manager.congressclient.list_datasource_tables = lister
|
self.app.client_manager.congressclient.list_datasource_tables = lister
|
||||||
cmd = datasource.ListDatasourceTables(self.app, self.namespace)
|
cmd = datasource.ListDatasourceTables(self.app, self.namespace)
|
||||||
|
|
||||||
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
||||||
|
|
||||||
with mock.patch.object(utils, "get_resource_id_from_name",
|
|
||||||
return_value="id"):
|
|
||||||
result = cmd.take_action(parsed_args)
|
result = cmd.take_action(parsed_args)
|
||||||
lister.assert_called_with("id")
|
lister.assert_called_with(datasource_name)
|
||||||
self.assertEqual(['id'], result[0])
|
self.assertEqual(['id'], result[0])
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,15 +119,12 @@ class TestListDatasourceStatus(common.TestCongressBase):
|
||||||
'last_error': "None"}
|
'last_error': "None"}
|
||||||
lister = mock.Mock(return_value=response)
|
lister = mock.Mock(return_value=response)
|
||||||
self.app.client_manager.congressclient.list_datasource_status = lister
|
self.app.client_manager.congressclient.list_datasource_status = lister
|
||||||
self.app.client_manager.congressclient.list_datasources = mock.Mock()
|
|
||||||
cmd = datasource.ShowDatasourceStatus(self.app, self.namespace)
|
cmd = datasource.ShowDatasourceStatus(self.app, self.namespace)
|
||||||
|
|
||||||
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
||||||
with mock.patch.object(utils, "get_resource_id_from_name",
|
|
||||||
return_value="id"):
|
|
||||||
result = list(cmd.take_action(parsed_args))
|
result = list(cmd.take_action(parsed_args))
|
||||||
|
|
||||||
lister.assert_called_with("id")
|
lister.assert_called_with(datasource_name)
|
||||||
self.assertEqual([('last_error', 'last_updated'),
|
self.assertEqual([('last_error', 'last_updated'),
|
||||||
('None', 'now')],
|
('None', 'now')],
|
||||||
result)
|
result)
|
||||||
|
@ -155,15 +149,12 @@ class TestShowDatasourceActions(common.TestCongressBase):
|
||||||
}
|
}
|
||||||
lister = mock.Mock(return_value=response)
|
lister = mock.Mock(return_value=response)
|
||||||
self.app.client_manager.congressclient.list_datasource_actions = lister
|
self.app.client_manager.congressclient.list_datasource_actions = lister
|
||||||
self.app.client_manager.congressclient.list_datasources = mock.Mock()
|
|
||||||
cmd = datasource.ShowDatasourceActions(self.app, self.namespace)
|
cmd = datasource.ShowDatasourceActions(self.app, self.namespace)
|
||||||
|
|
||||||
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
||||||
with mock.patch.object(utils, "get_resource_id_from_name",
|
|
||||||
return_value="id"):
|
|
||||||
result = cmd.take_action(parsed_args)
|
result = cmd.take_action(parsed_args)
|
||||||
|
|
||||||
lister.assert_called_once_with("id")
|
lister.assert_called_once_with(datasource_name)
|
||||||
self.assertEqual(['action', 'args', 'description'], result[0])
|
self.assertEqual(['action', 'args', 'description'], result[0])
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,15 +180,12 @@ class TestShowDatasourceSchema(common.TestCongressBase):
|
||||||
}
|
}
|
||||||
lister = mock.Mock(return_value=response)
|
lister = mock.Mock(return_value=response)
|
||||||
self.app.client_manager.congressclient.show_datasource_schema = lister
|
self.app.client_manager.congressclient.show_datasource_schema = lister
|
||||||
self.app.client_manager.congressclient.list_datasources = mock.Mock()
|
|
||||||
cmd = datasource.ShowDatasourceSchema(self.app, self.namespace)
|
cmd = datasource.ShowDatasourceSchema(self.app, self.namespace)
|
||||||
|
|
||||||
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
||||||
with mock.patch.object(utils, "get_resource_id_from_name",
|
|
||||||
return_value="id"):
|
|
||||||
result = cmd.take_action(parsed_args)
|
result = cmd.take_action(parsed_args)
|
||||||
|
|
||||||
lister.assert_called_with("id")
|
lister.assert_called_with(datasource_name)
|
||||||
self.assertEqual(['table', 'columns'], result[0])
|
self.assertEqual(['table', 'columns'], result[0])
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,11 +212,9 @@ class TestShowDatasourceTableSchema(common.TestCongressBase):
|
||||||
cmd = datasource.ShowDatasourceTableSchema(self.app, self.namespace)
|
cmd = datasource.ShowDatasourceTableSchema(self.app, self.namespace)
|
||||||
|
|
||||||
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
||||||
with mock.patch.object(utils, "get_resource_id_from_name",
|
|
||||||
return_value="id"):
|
|
||||||
result = cmd.take_action(parsed_args)
|
result = cmd.take_action(parsed_args)
|
||||||
|
|
||||||
lister.assert_called_with("id", table_name)
|
lister.assert_called_with(datasource_name, table_name)
|
||||||
self.assertEqual(['name', 'description'], result[0])
|
self.assertEqual(['name', 'description'], result[0])
|
||||||
|
|
||||||
|
|
||||||
|
@ -256,18 +242,15 @@ class TestListDatasourceRows(common.TestCongressBase):
|
||||||
|
|
||||||
client = self.app.client_manager.congressclient
|
client = self.app.client_manager.congressclient
|
||||||
lister = mock.Mock(return_value=response)
|
lister = mock.Mock(return_value=response)
|
||||||
self.app.client_manager.congressclient.list_datasources = mock.Mock()
|
|
||||||
client.list_datasource_rows = lister
|
client.list_datasource_rows = lister
|
||||||
schema_lister = mock.Mock(return_value=schema_response)
|
schema_lister = mock.Mock(return_value=schema_response)
|
||||||
client.show_datasource_table_schema = schema_lister
|
client.show_datasource_table_schema = schema_lister
|
||||||
cmd = datasource.ListDatasourceRows(self.app, self.namespace)
|
cmd = datasource.ListDatasourceRows(self.app, self.namespace)
|
||||||
|
|
||||||
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
||||||
with mock.patch.object(utils, "get_resource_id_from_name",
|
|
||||||
return_value="id"):
|
|
||||||
result = cmd.take_action(parsed_args)
|
result = cmd.take_action(parsed_args)
|
||||||
|
|
||||||
lister.assert_called_with('id', table_name)
|
lister.assert_called_with(datasource_name, table_name)
|
||||||
self.assertEqual(['ID', 'name'], result[0])
|
self.assertEqual(['ID', 'name'], result[0])
|
||||||
|
|
||||||
|
|
||||||
|
@ -352,13 +335,10 @@ class TestDeleteDatasourceDriver(common.TestCongressBase):
|
||||||
|
|
||||||
mocker = mock.Mock(return_value=None)
|
mocker = mock.Mock(return_value=None)
|
||||||
self.app.client_manager.congressclient.delete_datasource = mocker
|
self.app.client_manager.congressclient.delete_datasource = mocker
|
||||||
self.app.client_manager.congressclient.list_datasources = mock.Mock()
|
|
||||||
cmd = datasource.DeleteDatasource(self.app, self.namespace)
|
cmd = datasource.DeleteDatasource(self.app, self.namespace)
|
||||||
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
||||||
with mock.patch.object(utils, "get_resource_id_from_name",
|
|
||||||
return_value="id"):
|
|
||||||
result = cmd.take_action(parsed_args)
|
result = cmd.take_action(parsed_args)
|
||||||
mocker.assert_called_with("id")
|
mocker.assert_called_with(driver)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue