Merge "Add promote-to-replica-source to OSC"

This commit is contained in:
Zuul 2018-07-18 06:21:52 +00:00 committed by Gerrit Code Review
commit 3adf5fe392
4 changed files with 47 additions and 0 deletions

View File

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

View File

@ -68,6 +68,7 @@ openstack.database.v1 =
database_instance_eject_replica_source = troveclient.osc.v1.database_instances:EjectDatabaseInstanceReplicaSource database_instance_eject_replica_source = troveclient.osc.v1.database_instances:EjectDatabaseInstanceReplicaSource
database_instance_force_delete = troveclient.osc.v1.database_instances:ForceDeleteDatabaseInstance database_instance_force_delete = troveclient.osc.v1.database_instances:ForceDeleteDatabaseInstance
database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances
database_instance_promote_to_replica_source = troveclient.osc.v1.database_instances:PromoteDatabaseInstanceToReplicaSource
database_instance_reset_status = troveclient.osc.v1.database_instances:ResetDatabaseInstanceStatus database_instance_reset_status = troveclient.osc.v1.database_instances:ResetDatabaseInstanceStatus
database_instance_resize_flavor = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceFlavor database_instance_resize_flavor = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceFlavor
database_instance_resize_volume = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceVolume database_instance_resize_volume = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceVolume

View File

@ -533,6 +533,29 @@ class ForceDeleteDatabaseInstance(command.Command):
raise exceptions.CommandError(msg) raise exceptions.CommandError(msg)
class PromoteDatabaseInstanceToReplicaSource(command.Command):
_description = _(
"Promotes a replica to be the new replica source of its set.")
def get_parser(self, prog_name):
parser = super(PromoteDatabaseInstanceToReplicaSource,
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.promote_to_replica_source(instance)
class RestartDatabaseInstance(command.Command): class RestartDatabaseInstance(command.Command):
_description = _("Restarts an instance.") _description = _("Restarts an instance.")

View File

@ -284,6 +284,24 @@ class TestDatabaseInstanceEnableLog(TestInstances):
'log_name') 'log_name')
class TestDatabaseInstancePromoteToReplicaSource(TestInstances):
def setUp(self):
super(TestDatabaseInstancePromoteToReplicaSource, self).setUp()
self.cmd = database_instances.PromoteDatabaseInstanceToReplicaSource(
self.app, None)
@mock.patch.object(utils, 'find_resource')
def test_instance_promote_to_replica_source(self, mock_find):
args = ['instance']
mock_find.return_value = args[0]
parsed_args = self.check_parser(self.cmd, args, [])
result = self.cmd.take_action(parsed_args)
self.instance_client.promote_to_replica_source.assert_called_with(
'instance')
self.assertIsNone(result)
class TestDatabaseInstanceRestart(TestInstances): class TestDatabaseInstanceRestart(TestInstances):
def setUp(self): def setUp(self):