Add user-delete to OSC
This change adds database support to the python-openstackclient project for the user-delete command. The trove command user-delete is now: openstack database user delete Change-Id: Ie11a2a41dfca0e1f58e155eaf7c5949e11352c6a Partially-Implements: trove-support-in-python-openstackclient
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
The command ``trove user-delete`` is now available to use in
|
||||||
|
the python-openstackclient CLI as ``openstack database user delete``
|
@@ -42,6 +42,7 @@ openstack.database.v1 =
|
|||||||
database_instance_show = troveclient.osc.v1.database_instances:ShowDatabaseInstance
|
database_instance_show = troveclient.osc.v1.database_instances:ShowDatabaseInstance
|
||||||
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
|
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
|
||||||
database_list = troveclient.osc.v1.databases:ListDatabases
|
database_list = troveclient.osc.v1.databases:ListDatabases
|
||||||
|
database_user_delete = troveclient.osc.v1.database_users:DeleteDatabaseUser
|
||||||
database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers
|
database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers
|
||||||
database_user_show = troveclient.osc.v1.database_users:ShowDatabaseUser
|
database_user_show = troveclient.osc.v1.database_users:ShowDatabaseUser
|
||||||
datastore_list = troveclient.osc.v1.datastores:ListDatastores
|
datastore_list = troveclient.osc.v1.datastores:ListDatastores
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
"""Database v1 Users action implementations"""
|
"""Database v1 Users action implementations"""
|
||||||
|
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
|
from osc_lib import exceptions
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
import six
|
import six
|
||||||
|
|
||||||
@@ -75,3 +76,39 @@ class ShowDatabaseUser(command.ShowOne):
|
|||||||
user = db_users.get(parsed_args.instance, parsed_args.name,
|
user = db_users.get(parsed_args.instance, parsed_args.name,
|
||||||
hostname=parsed_args.host)
|
hostname=parsed_args.host)
|
||||||
return zip(*sorted(six.iteritems(user._info)))
|
return zip(*sorted(six.iteritems(user._info)))
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteDatabaseUser(command.Command):
|
||||||
|
|
||||||
|
_description = _("Deletes a user from an instance.")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(DeleteDatabaseUser, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'instance',
|
||||||
|
metavar='<instance>',
|
||||||
|
help=_('ID or name of the instance.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'name',
|
||||||
|
metavar='<name>',
|
||||||
|
help=_('Name of user.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--host',
|
||||||
|
metavar='<host>',
|
||||||
|
help=_('Optional host of user.')
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
manager = self.app.client_manager.database
|
||||||
|
users = manager.users
|
||||||
|
try:
|
||||||
|
instance = utils.find_resource(manager.instances,
|
||||||
|
parsed_args.instance)
|
||||||
|
users.delete(instance, parsed_args.name, parsed_args.host)
|
||||||
|
except Exception as e:
|
||||||
|
msg = (_("Failed to delete user %(user)s: %(e)s")
|
||||||
|
% {'user': parsed_args.name, 'e': e})
|
||||||
|
raise exceptions.CommandError(msg)
|
||||||
|
@@ -9,6 +9,10 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import mock
|
||||||
|
|
||||||
|
from osc_lib import exceptions
|
||||||
|
from osc_lib import utils
|
||||||
|
|
||||||
from troveclient import common
|
from troveclient import common
|
||||||
from troveclient.osc.v1 import database_users
|
from troveclient.osc.v1 import database_users
|
||||||
@@ -62,3 +66,42 @@ class TestUserShow(TestUsers):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.values, data)
|
self.assertEqual(self.values, data)
|
||||||
|
|
||||||
|
|
||||||
|
class TestDatabaseUserDelete(TestUsers):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestDatabaseUserDelete, self).setUp()
|
||||||
|
self.cmd = database_users.DeleteDatabaseUser(self.app, None)
|
||||||
|
|
||||||
|
@mock.patch.object(utils, 'find_resource')
|
||||||
|
def test_user_delete(self, mock_find):
|
||||||
|
args = ['userinstance', 'user1', '--host', '1.1.1.1']
|
||||||
|
mock_find.return_value = args[0]
|
||||||
|
parsed_args = self.check_parser(self.cmd, args, [])
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
self.user_client.delete.assert_called_with('userinstance',
|
||||||
|
'user1',
|
||||||
|
'1.1.1.1')
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
@mock.patch.object(utils, 'find_resource')
|
||||||
|
def test_user_delete_without_host(self, mock_find):
|
||||||
|
args = ['userinstance2', 'user1']
|
||||||
|
mock_find.return_value = args[0]
|
||||||
|
parsed_args = self.check_parser(self.cmd, args, [])
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
self.user_client.delete.assert_called_with('userinstance2',
|
||||||
|
'user1',
|
||||||
|
None)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
@mock.patch.object(utils, 'find_resource')
|
||||||
|
def test_user_delete_with_exception(self, mock_find):
|
||||||
|
args = ['userfakeinstance', 'db1', '--host', '1.1.1.1']
|
||||||
|
parsed_args = self.check_parser(self.cmd, args, [])
|
||||||
|
|
||||||
|
mock_find.side_effect = exceptions.CommandError
|
||||||
|
self.assertRaises(exceptions.CommandError,
|
||||||
|
self.cmd.take_action,
|
||||||
|
parsed_args)
|
||||||
|
Reference in New Issue
Block a user