Fix detach configuration from instance

Change-Id: Id0853dfb207bbd219755d46a9c0d6b4e897bfbeb
This commit is contained in:
Lingxian Kong 2021-07-09 20:31:43 +12:00
parent 5ce2e998b9
commit 64f3f62368
4 changed files with 24 additions and 14 deletions

View File

@ -265,7 +265,6 @@ class CreateDatabaseConfiguration(command.ShowOne):
class AttachDatabaseConfiguration(command.Command):
_description = _("Attaches a configuration group to an instance.")
def get_parser(self, prog_name):
@ -289,11 +288,16 @@ class AttachDatabaseConfiguration(command.Command):
manager = self.app.client_manager.database
db_instances = manager.instances
db_configurations = manager.configurations
instance = osc_utils.find_resource(db_instances,
parsed_args.instance)
configuration = osc_utils.find_resource(
db_configurations, parsed_args.configuration)
db_instances.modify(instance, configuration)
instance_id = parsed_args.instance
config_id = parsed_args.configuration
if not uuidutils.is_uuid_like(instance_id):
instance_id = osc_utils.find_resource(db_instances, instance_id)
if not uuidutils.is_uuid_like(config_id):
config_id = osc_utils.find_resource(db_configurations, config_id)
db_instances.update(instance_id, configuration=config_id)
class DetachDatabaseConfiguration(command.Command):
@ -312,9 +316,12 @@ class DetachDatabaseConfiguration(command.Command):
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.modify(instance)
instance_id = parsed_args.instance
if not uuidutils.is_uuid_like(instance_id):
instance_id = osc_utils.find_resource(db_instances, instance_id)
db_instances.update(instance_id, remove_configuration=True)
class ListDatabaseConfigurationInstances(command.Lister):

View File

@ -719,8 +719,8 @@ class UpdateDatabaseInstance(command.Command):
help=_('ID of the configuration reference to attach.'),
)
parser.add_argument(
'--detach_replica_source',
'--detach-replica-source',
'--detach_replica_source',
dest='detach_replica_source',
action="store_true",
default=False,
@ -729,8 +729,8 @@ class UpdateDatabaseInstance(command.Command):
'in favor of just --detach_replica_source'),
)
parser.add_argument(
'--remove_configuration',
'--remove-configuration',
'--remove_configuration',
dest='remove_configuration',
action="store_true",
default=False,

View File

@ -278,7 +278,8 @@ class TestConfigurationAttach(TestConfigurations):
mock_find.side_effect = ['instance1', 'config1']
parsed_args = self.check_parser(self.cmd, args, [])
result = self.cmd.take_action(parsed_args)
self.instance_client.modify.assert_called_with('instance1', 'config1')
self.instance_client.update.assert_called_with(
'instance1', configuration='config1')
self.assertIsNone(result)
@ -295,7 +296,8 @@ class TestConfigurationDetach(TestConfigurations):
mock_find.return_value = args[0]
parsed_args = self.check_parser(self.cmd, args, [])
result = self.cmd.take_action(parsed_args)
self.instance_client.modify.assert_called_with('instance2')
self.instance_client.update.assert_called_with(
'instance2', remove_configuration=True)
self.assertIsNone(result)

View File

@ -141,6 +141,7 @@ class Instances(base.ManagerWithFind):
return self._create("/instances", body, "instance")
def modify(self, instance, configuration=None):
"""This method is deprecated, use update instead."""
body = {
"instance": {
}