Add restart to OSC

This change adds database support to the python-openstackclient
project for the restart command

The trove command restart is now:
    openstack database instance restart

Change-Id: I24eeb001d27eae39be5c33650e9bc04287053c8c
Partially-Implements: blueprint trove-support-in-python-openstackclient
This commit is contained in:
caishan 2018-01-18 19:12:01 -08:00
parent 34dbc53ec2
commit 38b870575f
4 changed files with 46 additions and 0 deletions

View File

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

View File

@ -63,6 +63,7 @@ openstack.database.v1 =
database_instance_reset_status = troveclient.osc.v1.database_instances:ResetDatabaseInstanceStatus
database_instance_resize_flavor = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceFlavor
database_instance_resize_volume = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceVolume
database_instance_restart = troveclient.osc.v1.database_instances:RestartDatabaseInstance
database_instance_show = troveclient.osc.v1.database_instances:ShowDatabaseInstance
database_instance_upgrade = troveclient.osc.v1.database_instances:UpgradeDatabaseInstance
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits

View File

@ -529,3 +529,26 @@ class ForceDeleteDatabaseInstance(command.Command):
msg = (_("Failed to delete instance %(instance)s: %(e)s")
% {'instance': parsed_args.instance, 'e': e})
raise exceptions.CommandError(msg)
class RestartDatabaseInstance(command.Command):
_description = _("Restarts an instance.")
def get_parser(self, prog_name):
parser = super(RestartDatabaseInstance, self).get_parser(
prog_name
)
parser.add_argument(
'instance',
metavar='<instance>',
type=str,
help=_('ID or name of the instance.')
)
return parser
def take_action(self, parsed_args):
db_instances = self.app.client_manager.database.instances
instance = osc_utils.find_resource(db_instances,
parsed_args.instance)
db_instances.restart(instance)

View File

@ -283,3 +283,20 @@ class TestDatabaseInstanceEnableLog(TestInstances):
self.instance_client.log_enable.assert_called_with('instance1',
'log_name')
self.assertIsNone(result)
class TestDatabaseInstanceRestart(TestInstances):
def setUp(self):
super(TestDatabaseInstanceRestart, self).setUp()
self.cmd = database_instances.RestartDatabaseInstance(self.app,
None)
@mock.patch.object(utils, 'find_resource')
def test_instance_restart(self, mock_find):
args = ['instance1']
mock_find.return_value = args[0]
parsed_args = self.check_parser(self.cmd, args, [])
result = self.cmd.take_action(parsed_args)
self.instance_client.restart.assert_called_with('instance1')
self.assertIsNone(result)