summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangyao <wangyao@cmss.chinamobile.com>2017-11-30 21:16:18 +0800
committerwangyao <wangyao@cmss.chinamobile.com>2017-11-30 21:16:18 +0800
commit4d93fc91dd83f03fbcc02f9039e9a0794291a863 (patch)
tree09c360f6e0386d964e655da1611ea1db05ac3de9
parent7e14c4f2b0a4a4243ff3977a4ca1ae280d2893b9 (diff)
Add configuration-show to OSC
This change adds database support to the python-openstackclient project for the configuration-show command. The trove command configuration-show is now: openstack database configuration show Change-Id: I2f2cd93054ecaa8f67722a0efd8789b63e59b373 Partially-Implements: trove-support-in-python-openstackclient
Notes
Notes (review): Code-Review+2: Manoj Kumar <manoj@linux.vnet.ibm.com> Workflow+1: Manoj Kumar <manoj@linux.vnet.ibm.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 06 Dec 2017 19:15:15 +0000 Reviewed-on: https://review.openstack.org/524172 Project: openstack/python-troveclient Branch: refs/heads/master
-rw-r--r--releasenotes/notes/add-configuration-show-to-osc-c139bb20a2ec18ec.yaml5
-rw-r--r--setup.cfg1
-rw-r--r--troveclient/osc/v1/database_configurations.py29
-rw-r--r--troveclient/tests/osc/v1/test_database_configurations.py30
4 files changed, 65 insertions, 0 deletions
diff --git a/releasenotes/notes/add-configuration-show-to-osc-c139bb20a2ec18ec.yaml b/releasenotes/notes/add-configuration-show-to-osc-c139bb20a2ec18ec.yaml
new file mode 100644
index 0000000..52baec6
--- /dev/null
+++ b/releasenotes/notes/add-configuration-show-to-osc-c139bb20a2ec18ec.yaml
@@ -0,0 +1,5 @@
1---
2features:
3 - The command ``trove configuration-show`` is now available to
4 use in the python-openstackclient CLI as ``openstack database
5 configuration show``
diff --git a/setup.cfg b/setup.cfg
index bba3b9a..4113fba 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -33,6 +33,7 @@ openstack.database.v1 =
33 database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups 33 database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups
34 database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters 34 database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
35 database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations 35 database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations
36 database_configuration_show = troveclient.osc.v1.database_configurations:ShowDatabaseConfiguration
36 database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors 37 database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors
37 database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances 38 database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances
38 database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits 39 database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
diff --git a/troveclient/osc/v1/database_configurations.py b/troveclient/osc/v1/database_configurations.py
index f0b79ff..59deea6 100644
--- a/troveclient/osc/v1/database_configurations.py
+++ b/troveclient/osc/v1/database_configurations.py
@@ -12,12 +12,21 @@
12 12
13"""Database v1 Configurations action implementations""" 13"""Database v1 Configurations action implementations"""
14 14
15import json
15from osc_lib.command import command 16from osc_lib.command import command
16from osc_lib import utils as osc_utils 17from osc_lib import utils as osc_utils
18import six
17 19
18from troveclient.i18n import _ 20from troveclient.i18n import _
19 21
20 22
23def set_attributes_for_print_detail(configuration):
24 info = configuration._info.copy()
25 info['values'] = json.dumps(configuration.values)
26 del info['datastore_version_id']
27 return info
28
29
21class ListDatabaseConfigurations(command.Lister): 30class ListDatabaseConfigurations(command.Lister):
22 31
23 _description = _("List database configurations") 32 _description = _("List database configurations")
@@ -51,3 +60,23 @@ class ListDatabaseConfigurations(command.Lister):
51 config = [osc_utils.get_item_properties(c, self.columns) 60 config = [osc_utils.get_item_properties(c, self.columns)
52 for c in config] 61 for c in config]
53 return self.columns, config 62 return self.columns, config
63
64
65class ShowDatabaseConfiguration(command.ShowOne):
66 _description = _("Shows details of a database configuration group.")
67
68 def get_parser(self, prog_name):
69 parser = super(ShowDatabaseConfiguration, self).get_parser(prog_name)
70 parser.add_argument(
71 'configuration_group',
72 metavar='<configuration_group>',
73 help=_('ID or name of the configuration group'),
74 )
75 return parser
76
77 def take_action(self, parsed_args):
78 db_configurations = self.app.client_manager.database.configurations
79 configuration = osc_utils.find_resource(
80 db_configurations, parsed_args.configuration_group)
81 configuration = set_attributes_for_print_detail(configuration)
82 return zip(*sorted(six.iteritems(configuration)))
diff --git a/troveclient/tests/osc/v1/test_database_configurations.py b/troveclient/tests/osc/v1/test_database_configurations.py
index 3f43e80..8176971 100644
--- a/troveclient/tests/osc/v1/test_database_configurations.py
+++ b/troveclient/tests/osc/v1/test_database_configurations.py
@@ -47,3 +47,33 @@ class TestConfigurationList(TestConfigurations):
47 self.configuration_client.list.assert_called_once_with(**self.defaults) 47 self.configuration_client.list.assert_called_once_with(**self.defaults)
48 self.assertEqual(self.columns, columns) 48 self.assertEqual(self.columns, columns)
49 self.assertEqual([tuple(self.values)], data) 49 self.assertEqual([tuple(self.values)], data)
50
51
52class TestConfigurationShow(TestConfigurations):
53
54 values = ('2015-05-16T10:24:28', 'mysql', '5.6', '', 'c-123',
55 'test_config', '2015-05-16T10:24:29', '{"max_connections": 5}')
56
57 def setUp(self):
58 super(TestConfigurationShow, self).setUp()
59 self.cmd = database_configurations.ShowDatabaseConfiguration(self.app,
60 None)
61 self.data = self.fake_configurations.get_configurations_c_123()
62 self.configuration_client.get.return_value = self.data
63 self.columns = (
64 'created',
65 'datastore_name',
66 'datastore_version_name',
67 'description',
68 'id',
69 'name',
70 'updated',
71 'values',
72 )
73
74 def test_show(self):
75 args = ['c-123']
76 parsed_args = self.check_parser(self.cmd, args, [])
77 columns, data = self.cmd.take_action(parsed_args)
78 self.assertEqual(self.columns, columns)
79 self.assertEqual(self.values, data)