From 3f705bd0c828ef60dcae9d1621dcc7b95e9f21b9 Mon Sep 17 00:00:00 2001 From: wangyao Date: Fri, 13 Jul 2018 18:59:37 +0800 Subject: [PATCH] Add promote-to-replica-source to OSC This change adds database support to the python-openstackclient project for the promote-to-replica-source command. The trove command promote-to-replica-source is now: openstack database instance promote to replica source Change-Id: I0009b3e1074ddabaed6b02f5578f28cffc995b30 Partially-Implements: blueprint trove-support-in-python-openstackclient --- ...eplica-source-to-osc-6eca8c5507344205.yaml | 5 ++++ setup.cfg | 1 + troveclient/osc/v1/database_instances.py | 23 +++++++++++++++++++ .../tests/osc/v1/test_database_instances.py | 18 +++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 releasenotes/notes/add-promote-to-replica-source-to-osc-6eca8c5507344205.yaml diff --git a/releasenotes/notes/add-promote-to-replica-source-to-osc-6eca8c5507344205.yaml b/releasenotes/notes/add-promote-to-replica-source-to-osc-6eca8c5507344205.yaml new file mode 100644 index 00000000..2eb1b5a7 --- /dev/null +++ b/releasenotes/notes/add-promote-to-replica-source-to-osc-6eca8c5507344205.yaml @@ -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`` diff --git a/setup.cfg b/setup.cfg index ced55476..a0fcd903 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,6 +63,7 @@ openstack.database.v1 = database_instance_delete = troveclient.osc.v1.database_instances:DeleteDatabaseInstance database_instance_force_delete = troveclient.osc.v1.database_instances:ForceDeleteDatabaseInstance 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_resize_flavor = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceFlavor database_instance_resize_volume = troveclient.osc.v1.database_instances:ResizeDatabaseInstanceVolume diff --git a/troveclient/osc/v1/database_instances.py b/troveclient/osc/v1/database_instances.py index 49fee399..8fae3575 100644 --- a/troveclient/osc/v1/database_instances.py +++ b/troveclient/osc/v1/database_instances.py @@ -533,6 +533,29 @@ class ForceDeleteDatabaseInstance(command.Command): 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='', + 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): _description = _("Restarts an instance.") diff --git a/troveclient/tests/osc/v1/test_database_instances.py b/troveclient/tests/osc/v1/test_database_instances.py index aeac22aa..83e6d3e0 100644 --- a/troveclient/tests/osc/v1/test_database_instances.py +++ b/troveclient/tests/osc/v1/test_database_instances.py @@ -284,6 +284,24 @@ class TestDatabaseInstanceEnableLog(TestInstances): '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): def setUp(self):