Support to reboot instance

openstack database instance reboot <instance>

Change-Id: Id5ac985399797356165eaac68dd05bc46ee0124d
This commit is contained in:
Lingxian Kong
2020-01-04 17:42:13 +13:00
parent a0324f4109
commit 68e3ae83c1
4 changed files with 52 additions and 4 deletions

View File

@@ -0,0 +1,8 @@
---
features:
- |
Support to reboot instance.
.. code-block:: console
openstack database instance reboot <instance>

View File

@@ -75,6 +75,7 @@ openstack.database.v1 =
database_instance_show = troveclient.osc.v1.database_instances:ShowDatabaseInstance
database_instance_update = troveclient.osc.v1.database_instances:UpdateDatabaseInstance
database_instance_upgrade = troveclient.osc.v1.database_instances:UpgradeDatabaseInstance
database_instance_reboot = troveclient.osc.v1.database_instances:RebootDatabaseInstance
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
database_log_list = troveclient.osc.v1.database_logs:ListDatabaseLogs
database_log_set = troveclient.osc.v1.database_logs:SetDatabaseInstanceLog

View File

@@ -428,10 +428,9 @@ class CreateDatabaseInstance(command.ShowOne):
class ResetDatabaseInstanceStatus(command.Command):
_description = _("Set the task status of an instance to NONE if the "
"instance is in BUILD or ERROR state. Resetting task "
"status of an instance in BUILD state will allow "
"the instance to be deleted.")
_description = _("Set instance service status to ERROR and clear the "
"current task status. Mark any running backup operations "
"as FAILED.")
def get_parser(self, prog_name):
parser = super(ResetDatabaseInstanceStatus, self).get_parser(prog_name)
@@ -709,3 +708,27 @@ class DetachDatabaseInstanceReplica(command.Command):
instance = osc_utils.find_resource(db_instances,
parsed_args.instance)
db_instances.edit(instance, detach_replica_source=True)
class RebootDatabaseInstance(command.Command):
_description = _("Reboots an instance(the Nova server).")
def get_parser(self, prog_name):
parser = super(RebootDatabaseInstance, 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):
instance_id = parsed_args.instance
if not uuidutils.is_uuid_like(instance_id):
instance_mgr = self.app.client_manager.database.instances
instance_id = osc_utils.find_resource(instance_mgr, instance_id)
mgmt_instance_mgr = self.app.client_manager.database.mgmt_instances
mgmt_instance_mgr.reboot(instance_id)

View File

@@ -422,3 +422,19 @@ class TestInstanceReplicaDetach(TestInstances):
self.instance_client.edit.assert_called_with(
'instance', detach_replica_source=True)
self.assertIsNone(result)
class TestDatabaseInstanceReboot(TestInstances):
def setUp(self):
super(TestDatabaseInstanceReboot, self).setUp()
self.cmd = database_instances.RebootDatabaseInstance(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, [])
self.cmd.take_action(parsed_args)
self.mgmt_client.reboot.assert_called_with('instance1')