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
This commit is contained in:
wangyao 2018-07-16 19:15:51 +08:00
parent 77f9647644
commit 09c686c483
6 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
features:
- The command ``trove log-list`` is now available to use in
the python-openstackclient CLI as ``openstack database log list``

View File

@ -71,6 +71,7 @@ openstack.database.v1 =
database_instance_update = troveclient.osc.v1.database_instances:UpdateDatabaseInstance
database_instance_upgrade = troveclient.osc.v1.database_instances:UpgradeDatabaseInstance
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
database_log_list = troveclient.osc.v1.database_logs:ListDatabaseLogs
database_quota_show = troveclient.osc.v1.database_quota:ShowDatabaseQuota
database_quota_update = troveclient.osc.v1.database_quota:UpdateDatabaseQuota
database_log_enable = troveclient.osc.v1.database_instances:EnableDatabaseInstanceLog

View File

@ -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

View File

@ -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"}]})

View File

@ -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]

View File

@ -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)