Merge "Support push rows to datasources"
This commit is contained in:
commit
88f45f21c7
|
@ -18,6 +18,7 @@ from cliff import command
|
|||
from cliff import lister
|
||||
from cliff import show
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
|
||||
from congressclient.common import parseractions
|
||||
|
@ -322,6 +323,37 @@ class DeleteDatasource(command.Command):
|
|||
client.delete_datasource(datasource_id)
|
||||
|
||||
|
||||
class UpdateDatasourceRow(command.Command):
|
||||
"""Update rows to a datasource table."""
|
||||
|
||||
log = logging.getLogger(__name__ + '.UpdateDatasourceRow')
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(UpdateDatasourceRow, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'datasource',
|
||||
metavar="<datasource>",
|
||||
help="Name or ID of the datasource to Update")
|
||||
parser.add_argument(
|
||||
'table',
|
||||
metavar="<table>",
|
||||
help="Name or ID of the table to Update")
|
||||
parser.add_argument(
|
||||
'rows',
|
||||
type=jsonutils.loads,
|
||||
metavar="<rows>",
|
||||
help=("List of Rows should be formmated json style."
|
||||
" ex. [[row1], [row2]]"))
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug('take_action(%s)' % parsed_args)
|
||||
client = self.app.client_manager.congressclient
|
||||
body = parsed_args.rows
|
||||
client.update_datasource_rows(
|
||||
parsed_args.datasource, parsed_args.table, body)
|
||||
|
||||
|
||||
class DatasourceRequestRefresh(command.Command):
|
||||
"""Trigger a datasource to poll."""
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#
|
||||
|
||||
import mock
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from congressclient.common import utils
|
||||
from congressclient.osc.v1 import datasource
|
||||
|
@ -361,6 +362,31 @@ class TestDeleteDatasourceDriver(common.TestCongressBase):
|
|||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestUpdateDatasourceRow(common.TestCongressBase):
|
||||
|
||||
def test_update_datasource_row(self):
|
||||
driver = 'push'
|
||||
table_name = 'table'
|
||||
rows = [["data1", "data2"],
|
||||
["data3", "data4"]]
|
||||
|
||||
arglist = [driver, table_name, jsonutils.dumps(rows)]
|
||||
verifylist = [('datasource', driver),
|
||||
('table', table_name),
|
||||
('rows', rows)]
|
||||
|
||||
mocker = mock.Mock(return_value=None)
|
||||
self.app.client_manager.congressclient.update_datasource_rows = mocker
|
||||
self.app.client_manager.congressclient.list_datasources = mock.Mock()
|
||||
|
||||
cmd = datasource.UpdateDatasourceRow(self.app, self.namespace)
|
||||
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
||||
with mock.patch.object(utils, 'get_resource_id_from_name',
|
||||
return_value="push"):
|
||||
cmd.take_action(parsed_args)
|
||||
mocker.assert_called_with(driver, table_name, rows)
|
||||
|
||||
|
||||
class TestDatasourceRequestRefresh(common.TestCongressBase):
|
||||
|
||||
def test_datasource_request_refresh(self):
|
||||
|
|
|
@ -137,6 +137,19 @@ class Client(object):
|
|||
(datasource_name, table_name))
|
||||
return body
|
||||
|
||||
def update_datasource_rows(self, datasource_name, table_name, body=None):
|
||||
"""Update rows in a table of a datasource.
|
||||
|
||||
Args:
|
||||
datasource_name: Name or id of the datasource
|
||||
table_name: Table name for updating
|
||||
body: Rows for update.
|
||||
"""
|
||||
resp, body = self.httpclient.put(self.datasource_rows %
|
||||
(datasource_name, table_name),
|
||||
body=body)
|
||||
return body
|
||||
|
||||
def list_datasource_status(self, datasource_name):
|
||||
resp, body = self.httpclient.get(self.datasource_status %
|
||||
datasource_name)
|
||||
|
|
|
@ -44,6 +44,7 @@ openstack.congressclient.v1 =
|
|||
congress_datasource_request-refresh = congressclient.osc.v1.datasource:DatasourceRequestRefresh
|
||||
congress_datasource_table_list = congressclient.osc.v1.datasource:ListDatasourceTables
|
||||
congress_datasource_row_list = congressclient.osc.v1.datasource:ListDatasourceRows
|
||||
congress_datasource_row_update = congressclient.osc.v1.datasource:UpdateDatasourceRow
|
||||
congress_datasource_status_show = congressclient.osc.v1.datasource:ShowDatasourceStatus
|
||||
congress_datasource_actions_show= congressclient.osc.v1.datasource:ShowDatasourceActions
|
||||
congress_datasource_schema_show = congressclient.osc.v1.datasource:ShowDatasourceSchema
|
||||
|
|
Loading…
Reference in New Issue