diff options
author | wangyao <wangyao@cmss.chinamobile.com> | 2018-07-16 19:15:51 +0800 |
---|---|---|
committer | wangyao <wangyao@cmss.chinamobile.com> | 2018-07-17 09:24:52 +0800 |
commit | 09c686c483c7ec1b2674ca829ea0fcd68fe4c2b7 (patch) | |
tree | 256785baca97d3d965f2e8a2bb9573ebadd797c9 /troveclient | |
parent | 77f96476449e2418a64cbb508be68ccd77b38e79 (diff) | |
download | python-troveclient-09c686c483c7ec1b2674ca829ea0fcd68fe4c2b7.tar.gz |
Add log-list to OSC
This change adds database support to the python-openstackclient
project for the log-list command.
The trove command log-list is now:
openstack database log list
Change-Id: If048a653df01244882a451e3fddf28a8faac59f6
Partially-Implements: blueprint trove-support-in-python-openstackclient
Diffstat (limited to 'troveclient')
-rw-r--r-- | troveclient/osc/v1/database_logs.py | 43 | ||||
-rw-r--r-- | troveclient/tests/fakes.py | 22 | ||||
-rw-r--r-- | troveclient/tests/osc/v1/fakes.py | 8 | ||||
-rw-r--r-- | troveclient/tests/osc/v1/test_database_logs.py | 49 |
4 files changed, 122 insertions, 0 deletions
diff --git a/troveclient/osc/v1/database_logs.py b/troveclient/osc/v1/database_logs.py new file mode 100644 index 0000000..aaba81e --- /dev/null +++ b/troveclient/osc/v1/database_logs.py @@ -0,0 +1,43 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Database v1 Logs action implementations""" + +from osc_lib.command import command +from osc_lib import utils as osc_utils + +from troveclient.i18n import _ + + +class ListDatabaseLogs(command.Lister): + + _description = _("Lists the log files available for instance.") + columns = ['Name', 'Type', 'Status', 'Published', 'Pending', + 'Container', 'Prefix'] + + def get_parser(self, prog_name): + parser = super(ListDatabaseLogs, self).get_parser(prog_name) + parser.add_argument( + 'instance', + metavar='<instance>', + help=_('ID or name of the instance.') + ) + return parser + + def take_action(self, parsed_args): + database_instances = self.app.client_manager.database.instances + instance = osc_utils.find_resource(database_instances, + parsed_args.instance) + log_list = database_instances.log_list(instance) + logs = [osc_utils.get_item_properties(l, self.columns) + for l in log_list] + return self.columns, logs diff --git a/troveclient/tests/fakes.py b/troveclient/tests/fakes.py index 7864054..b4b747b 100644 --- a/troveclient/tests/fakes.py +++ b/troveclient/tests/fakes.py @@ -822,3 +822,25 @@ class FakeHTTPClient(base_client.HTTPClient): def update_instances_quota(self, **kw): return (200, {}, {"quotas": {"instances": 51}}) + + def get_logs(self, **kw): + return (200, {}, {"logs": [ + { + "name": "general", + "type": "USER", + "status": "Partial", + "published": "128", + "pending": "4096", + "container": "data_logs", + "prefix": "mysql-general", + "metafile": "mysql-general_metafile" + }, + { + "name": "slow_query", + "type": "USER", + "status": "Ready", + "published": "0", + "pending": "128", + "container": "None", + "prefix": "None", + "metafile": "mysql-slow_query_metafile"}]}) diff --git a/troveclient/tests/osc/v1/fakes.py b/troveclient/tests/osc/v1/fakes.py index 057c446..6128add 100644 --- a/troveclient/tests/osc/v1/fakes.py +++ b/troveclient/tests/osc/v1/fakes.py @@ -180,3 +180,11 @@ class FakeQuota(object): def get_quotas(self): return [quota.Quotas.resource_class(None, q) for q in self.fake_quotas] + + +class FakeLogs(object): + fake_logs = fakes.FakeHTTPClient().get_logs()[2]['logs'] + + def get_logs(self): + return [instances.DatastoreLog(None, fake_log) + for fake_log in self.fake_logs] diff --git a/troveclient/tests/osc/v1/test_database_logs.py b/troveclient/tests/osc/v1/test_database_logs.py new file mode 100644 index 0000000..1654380 --- /dev/null +++ b/troveclient/tests/osc/v1/test_database_logs.py @@ -0,0 +1,49 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock + +from osc_lib import utils + +from troveclient.osc.v1 import database_logs +from troveclient.tests.osc.v1 import fakes + + +class TestLogs(fakes.TestDatabasev1): + fake_logs = fakes.FakeLogs() + + def setUp(self): + super(TestLogs, self).setUp() + self.instance_client = self.app.client_manager.database.instances + + +class TestLogList(TestLogs): + + columns = database_logs.ListDatabaseLogs.columns + values = [('general', 'USER', 'Partial', '128', '4096', 'data_logs', + 'mysql-general'), + ('slow_query', 'USER', 'Ready', '0', '128', 'None', 'None')] + + def setUp(self): + super(TestLogList, self).setUp() + self.cmd = database_logs.ListDatabaseLogs(self.app, None) + data = self.fake_logs.get_logs() + self.instance_client.log_list.return_value = data + + @mock.patch.object(utils, 'find_resource') + def test_log_list(self, mock_find): + args = ['instance'] + mock_find.return_value = args[0] + parsed_args = self.check_parser(self.cmd, args, []) + columns, data = self.cmd.take_action(parsed_args) + self.assertEqual(self.columns, columns) + self.assertEqual(self.values, data) |