From 0ea43259d02aaf95e74f5e40e69df82a62726d2d Mon Sep 17 00:00:00 2001 From: wangyao Date: Sat, 9 Dec 2017 14:19:17 +0800 Subject: [PATCH] Add configuration-parameter-show to OSC This change adds database support to the python-openstackclient project for the configuration-parameter-show command. The trove command configuration-parameter-show is now: openstack database configuration parameter show Change-Id: I0a286390135a09b125fab0efa8c83aefec8ca334 Partially-Implements: trove-support-in-python-openstackclient --- ...arameter-show-to-osc-5bcf21662683ceee.yaml | 5 ++ setup.cfg | 1 + troveclient/osc/v1/database_configurations.py | 48 +++++++++++++++++++ .../osc/v1/test_database_configurations.py | 48 +++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 releasenotes/notes/add-configuration-parameter-show-to-osc-5bcf21662683ceee.yaml diff --git a/releasenotes/notes/add-configuration-parameter-show-to-osc-5bcf21662683ceee.yaml b/releasenotes/notes/add-configuration-parameter-show-to-osc-5bcf21662683ceee.yaml new file mode 100644 index 00000000..6beb9f22 --- /dev/null +++ b/releasenotes/notes/add-configuration-parameter-show-to-osc-5bcf21662683ceee.yaml @@ -0,0 +1,5 @@ +--- +features: + - The command ``trove configuration-parameter-show`` is now available to + use in the python-openstackclient CLI as ``openstack database + configuration parameter show`` diff --git a/setup.cfg b/setup.cfg index 00143a04..134064bb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,6 +36,7 @@ openstack.database.v1 = database_cluster_show = troveclient.osc.v1.database_clusters:ShowDatabaseCluster database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations database_configuration_parameter_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurationParameters + database_configuration_parameter_show = troveclient.osc.v1.database_configurations:ShowDatabaseConfigurationParameter database_configuration_show = troveclient.osc.v1.database_configurations:ShowDatabaseConfiguration database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors database_flavor_show = troveclient.osc.v1.database_flavors:ShowDatabaseFlavor diff --git a/troveclient/osc/v1/database_configurations.py b/troveclient/osc/v1/database_configurations.py index eb0d5d48..d51490ec 100644 --- a/troveclient/osc/v1/database_configurations.py +++ b/troveclient/osc/v1/database_configurations.py @@ -130,3 +130,51 @@ class ListDatabaseConfigurationParameters(command.Lister): params = [osc_utils.get_item_properties(p, self.columns) for p in params] return self.columns, params + + +class ShowDatabaseConfigurationParameter(command.ShowOne): + _description = _("Shows details of a database configuration parameter.") + + def get_parser(self, prog_name): + parser = super(ShowDatabaseConfigurationParameter, self).\ + get_parser(prog_name) + parser.add_argument( + 'datastore_version', + metavar='', + help=_('Datastore version name or ID assigned to the' + ' configuration group.'), + ) + parser.add_argument( + 'parameter', + metavar='', + help=_('Name of the configuration parameter.'), + ) + parser.add_argument( + '--datastore', + metavar='', + default=None, + help=_('ID or name of the datastore to list configuration' + ' parameters for. Optional if the ID of the' + ' datastore_version is provided.'), + ) + return parser + + def take_action(self, parsed_args): + db_configuration_parameters = self.app.client_manager.database.\ + configuration_parameters + if parsed_args.datastore: + param = db_configuration_parameters.get_parameter( + parsed_args.datastore, + parsed_args.datastore_version, + parsed_args.parameter) + elif utils.is_uuid_like(parsed_args.datastore_version): + param = db_configuration_parameters.get_parameter_by_version( + parsed_args.datastore_version, + parsed_args.parameter) + else: + raise exceptions.NoUniqueMatch(_('The datastore name or id is' + ' required to retrieve the' + ' parameter for the' + ' configuration group' + ' by name.')) + return zip(*sorted(six.iteritems(param._info))) diff --git a/troveclient/tests/osc/v1/test_database_configurations.py b/troveclient/tests/osc/v1/test_database_configurations.py index 2f76c1c3..9e26f394 100644 --- a/troveclient/tests/osc/v1/test_database_configurations.py +++ b/troveclient/tests/osc/v1/test_database_configurations.py @@ -121,3 +121,51 @@ class TestConfigurationParameterList(TestConfigurations): self.assertRaises(exceptions.NoUniqueMatch, self.cmd.take_action, parsed_args) + + +class TestConfigurationParameterShow(TestConfigurations): + + values = ('d-123', 31536000, 2, 'connect_timeout', 'false', 'integer') + + def setUp(self): + super(TestConfigurationParameterShow, self).setUp() + self.cmd = database_configurations. \ + ShowDatabaseConfigurationParameter(self.app, None) + data = self.fake_configuration_params.get_params_connect_timeout() + self.configuration_params_client.get_parameter.return_value = data + self.configuration_params_client.\ + get_parameter_by_version.return_value = data + self.columns = ( + 'datastore_version_id', + 'max', + 'min', + 'name', + 'restart_required', + 'type', + ) + + def test_configuration_parameter_show_defaults(self): + args = ['d-123', 'connect_timeout', '--datastore', 'mysql'] + verifylist = [ + ('datastore_version', 'd-123'), + ('parameter', 'connect_timeout'), + ('datastore', 'mysql'), + ] + parsed_args = self.check_parser(self.cmd, args, verifylist) + columns, data = self.cmd.take_action(parsed_args) + self.assertEqual(self.columns, columns) + self.assertEqual(self.values, data) + + def test_configuration_parameter_show_with_version_id_exception(self): + args = [ + 'd-123', + 'connect_timeout', + ] + verifylist = [ + ('datastore_version', 'd-123'), + ('parameter', 'connect_timeout'), + ] + parsed_args = self.check_parser(self.cmd, args, verifylist) + self.assertRaises(exceptions.NoUniqueMatch, + self.cmd.take_action, + parsed_args)