Fix resize flavor for instance
Change-Id: I9192857a690585cb3f365b15707dfa98e521e788 Story: #2007188 Task: #38315
This commit is contained in:
@@ -190,8 +190,8 @@ class DeleteDatabaseInstance(base.TroveDeleter):
|
|||||||
db_instances = self.app.client_manager.database.instances
|
db_instances = self.app.client_manager.database.instances
|
||||||
|
|
||||||
# Used for batch deletion
|
# Used for batch deletion
|
||||||
self.delete_func = (db_instances.force_delete
|
self.delete_func = (db_instances.force_delete if parsed_args.force
|
||||||
if parsed_args.force else db_instances.delete)
|
else db_instances.delete)
|
||||||
self.resource = 'database instance'
|
self.resource = 'database instance'
|
||||||
|
|
||||||
ids = []
|
ids = []
|
||||||
@@ -212,7 +212,6 @@ class DeleteDatabaseInstance(base.TroveDeleter):
|
|||||||
|
|
||||||
|
|
||||||
class CreateDatabaseInstance(command.ShowOne):
|
class CreateDatabaseInstance(command.ShowOne):
|
||||||
|
|
||||||
_description = _("Creates a new database instance.")
|
_description = _("Creates a new database instance.")
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
@@ -427,7 +426,6 @@ class CreateDatabaseInstance(command.ShowOne):
|
|||||||
|
|
||||||
|
|
||||||
class ResetDatabaseInstanceStatus(command.Command):
|
class ResetDatabaseInstanceStatus(command.Command):
|
||||||
|
|
||||||
_description = _("Set instance service status to ERROR and clear the "
|
_description = _("Set instance service status to ERROR and clear the "
|
||||||
"current task status. Mark any running backup operations "
|
"current task status. Mark any running backup operations "
|
||||||
"as FAILED.")
|
"as FAILED.")
|
||||||
@@ -449,7 +447,6 @@ class ResetDatabaseInstanceStatus(command.Command):
|
|||||||
|
|
||||||
|
|
||||||
class ResizeDatabaseInstanceFlavor(command.Command):
|
class ResizeDatabaseInstanceFlavor(command.Command):
|
||||||
|
|
||||||
_description = _("Resize an instance with a new flavor")
|
_description = _("Resize an instance with a new flavor")
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
@@ -466,22 +463,21 @@ class ResizeDatabaseInstanceFlavor(command.Command):
|
|||||||
'flavor_id',
|
'flavor_id',
|
||||||
metavar='<flavor_id>',
|
metavar='<flavor_id>',
|
||||||
type=str,
|
type=str,
|
||||||
help=_('New flavor of the instance')
|
help=_('New flavor ID of the instance')
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
db_instances = self.app.client_manager.database.instances
|
instance_mgr = self.app.client_manager.database.instances
|
||||||
db_flavor = self.app.client_manager.database.flavors
|
instance_id = parsed_args.instance
|
||||||
instance = osc_utils.find_resource(db_instances,
|
|
||||||
parsed_args.instance)
|
if not uuidutils.is_uuid_like(instance_id):
|
||||||
flavor = osc_utils.find_resource(db_flavor,
|
instance_id = osc_utils.find_resource(instance_mgr, instance_id)
|
||||||
parsed_args.flavor_id)
|
|
||||||
db_instances.resize_instance(instance, flavor)
|
instance_mgr.resize_instance(instance_id, parsed_args.flavor_id)
|
||||||
|
|
||||||
|
|
||||||
class UpgradeDatabaseInstance(command.Command):
|
class UpgradeDatabaseInstance(command.Command):
|
||||||
|
|
||||||
_description = _("Upgrades an instance to a new datastore version.")
|
_description = _("Upgrades an instance to a new datastore version.")
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
@@ -507,7 +503,6 @@ class UpgradeDatabaseInstance(command.Command):
|
|||||||
|
|
||||||
|
|
||||||
class ResizeDatabaseInstanceVolume(command.Command):
|
class ResizeDatabaseInstanceVolume(command.Command):
|
||||||
|
|
||||||
_description = _("Resizes the volume size of an instance.")
|
_description = _("Resizes the volume size of an instance.")
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
@@ -537,12 +532,11 @@ class ResizeDatabaseInstanceVolume(command.Command):
|
|||||||
|
|
||||||
|
|
||||||
class ForceDeleteDatabaseInstance(command.Command):
|
class ForceDeleteDatabaseInstance(command.Command):
|
||||||
|
|
||||||
_description = _("Force delete an instance.")
|
_description = _("Force delete an instance.")
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = (super(ForceDeleteDatabaseInstance, self)
|
parser = (
|
||||||
.get_parser(prog_name))
|
super(ForceDeleteDatabaseInstance, self).get_parser(prog_name))
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'instance',
|
'instance',
|
||||||
metavar='<instance>',
|
metavar='<instance>',
|
||||||
@@ -564,7 +558,6 @@ class ForceDeleteDatabaseInstance(command.Command):
|
|||||||
|
|
||||||
|
|
||||||
class PromoteDatabaseInstanceToReplicaSource(command.Command):
|
class PromoteDatabaseInstanceToReplicaSource(command.Command):
|
||||||
|
|
||||||
_description = _(
|
_description = _(
|
||||||
"Promotes a replica to be the new replica source of its set.")
|
"Promotes a replica to be the new replica source of its set.")
|
||||||
|
|
||||||
@@ -587,7 +580,6 @@ class PromoteDatabaseInstanceToReplicaSource(command.Command):
|
|||||||
|
|
||||||
|
|
||||||
class RestartDatabaseInstance(command.Command):
|
class RestartDatabaseInstance(command.Command):
|
||||||
|
|
||||||
_description = _("Restarts an instance.")
|
_description = _("Restarts an instance.")
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
@@ -610,7 +602,6 @@ class RestartDatabaseInstance(command.Command):
|
|||||||
|
|
||||||
|
|
||||||
class EjectDatabaseInstanceReplicaSource(command.Command):
|
class EjectDatabaseInstanceReplicaSource(command.Command):
|
||||||
|
|
||||||
_description = _("Ejects a replica source from its set.")
|
_description = _("Ejects a replica source from its set.")
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
@@ -632,7 +623,6 @@ class EjectDatabaseInstanceReplicaSource(command.Command):
|
|||||||
|
|
||||||
|
|
||||||
class UpdateDatabaseInstance(command.Command):
|
class UpdateDatabaseInstance(command.Command):
|
||||||
|
|
||||||
_description = _("Updates an instance: Edits name, "
|
_description = _("Updates an instance: Edits name, "
|
||||||
"configuration, or replica source.")
|
"configuration, or replica source.")
|
||||||
|
|
||||||
@@ -688,7 +678,6 @@ class UpdateDatabaseInstance(command.Command):
|
|||||||
|
|
||||||
|
|
||||||
class DetachDatabaseInstanceReplica(command.Command):
|
class DetachDatabaseInstanceReplica(command.Command):
|
||||||
|
|
||||||
_description = _("Detaches a replica instance "
|
_description = _("Detaches a replica instance "
|
||||||
"from its replication source.")
|
"from its replication source.")
|
||||||
|
|
||||||
|
@@ -259,11 +259,13 @@ class TestDatabaseInstanceResizeFlavor(TestInstances):
|
|||||||
@mock.patch.object(utils, 'find_resource')
|
@mock.patch.object(utils, 'find_resource')
|
||||||
def test_instance_resize_flavor(self, mock_find):
|
def test_instance_resize_flavor(self, mock_find):
|
||||||
args = ['instance1', 'flavor_id']
|
args = ['instance1', 'flavor_id']
|
||||||
mock_find.side_effect = ['instance1', 'flavor_id']
|
mock_find.return_value = 'fake_instance_id'
|
||||||
|
|
||||||
parsed_args = self.check_parser(self.cmd, args, [])
|
parsed_args = self.check_parser(self.cmd, args, [])
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
self.instance_client.resize_instance.assert_called_with('instance1',
|
|
||||||
'flavor_id')
|
self.instance_client.resize_instance.assert_called_with(
|
||||||
|
'fake_instance_id', 'flavor_id')
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user