Add configuration-delete to OSC

This change adds database support to the python-openstackclient
project for the configuration-delete command.

The trove command configuration-delete is now:
    openstack database configuration delete

Change-Id: I747566e5a1ddf415c3127a86debc2ba477256141
Partially-Implements: trove-support-in-python-openstackclient
This commit is contained in:
zhanggang 2017-12-21 00:23:55 -05:00
parent 26a9ff544f
commit a1e9f46a53
4 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
features:
- |
The command ``trove configuration-delete`` is now available
to use in the python-openstackclient CLI as ``openstack
database configuration delete``

View File

@ -36,6 +36,7 @@ openstack.database.v1 =
database_cluster_delete = troveclient.osc.v1.database_clusters:DeleteDatabaseCluster
database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
database_cluster_show = troveclient.osc.v1.database_clusters:ShowDatabaseCluster
database_configuration_delete = troveclient.osc.v1.database_configurations:DeleteDatabaseConfiguration
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

View File

@ -178,3 +178,28 @@ class ShowDatabaseConfigurationParameter(command.ShowOne):
' configuration group'
' by name.'))
return zip(*sorted(six.iteritems(param._info)))
class DeleteDatabaseConfiguration(command.Command):
_description = _("Deletes a configuration group.")
def get_parser(self, prog_name):
parser = super(DeleteDatabaseConfiguration, self).get_parser(prog_name)
parser.add_argument(
'configuration_group',
metavar='<configuration_group>',
help=_('ID or name of the configuration group'),
)
return parser
def take_action(self, parsed_args):
db_configurations = self.app.client_manager.database.configurations
try:
configuration = osc_utils.find_resource(
db_configurations, parsed_args.configuration_group)
db_configurations.delete(configuration)
except Exception as e:
msg = (_("Failed to delete configuration %(c_group)s: %(e)s")
% {'c_group': parsed_args.configuration_group, 'e': e})
raise exceptions.CommandError(msg)

View File

@ -10,6 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from osc_lib import utils
from troveclient import common
from troveclient import exceptions
from troveclient.osc.v1 import database_configurations
@ -169,3 +173,30 @@ class TestConfigurationParameterShow(TestConfigurations):
self.assertRaises(exceptions.NoUniqueMatch,
self.cmd.take_action,
parsed_args)
class TestDatabaseConfigurationDelete(TestConfigurations):
def setUp(self):
super(TestDatabaseConfigurationDelete, self).setUp()
self.cmd = database_configurations.\
DeleteDatabaseConfiguration(self.app, None)
@mock.patch.object(utils, 'find_resource')
def test_configuration_delete(self, mock_find):
args = ['config1']
mock_find.return_value = args[0]
parsed_args = self.check_parser(self.cmd, args, [])
result = self.cmd.take_action(parsed_args)
self.configuration_client.delete.assert_called_with('config1')
self.assertIsNone(result)
@mock.patch.object(utils, 'find_resource')
def test_configuration_delete_with_exception(self, mock_find):
args = ['fakeconfig']
parsed_args = self.check_parser(self.cmd, args, [])
mock_find.side_effect = exceptions.CommandError
self.assertRaises(exceptions.CommandError,
self.cmd.take_action,
parsed_args)